* simv2: wip * simulation: exec adapter start/stop * simulation: add node status to exec adapter * simulation: initial simulation code * simulation: exec adapter, configure path to executable * simulation: initial docker adapter * simulation: wip kubernetes adapter * simulation: kubernetes adapter proxy * simulation: implement GetAll/StartAll/StopAll * simulation: kuberentes adapter - set env vars and resource limits * simulation: discovery test * simulation: remove port definitions within docker adapter * simulation: simplify wait for healthy loop * simulation: get nat ip addr from interface * simulation: pull docker images automatically * simulation: NodeStatus -> NodeInfo * simulation: move discovery test to example dir * simulation: example snapshot usage * simulation: add goclient specific simulation * simulation: add peer connections to snapshot * simulation: close rpc client * simulation: don't export kubernetes proxy server * simulation: merge simulation code * simulation: don't export nodemap * simulation: rename SimulationSnapshot -> Snapshot * simulation: linting fixes * simulation: add k8s available helper func * simulation: vendor * simulation: fix 'no non-test Go files' when building * simulation: remove errors from interface methods where non were returned * simulation: run getHealthInfo check in parallel
102 lines
2.2 KiB
Go
102 lines
2.2 KiB
Go
// +build windows
|
|
|
|
package winterm
|
|
|
|
const (
|
|
horizontal = iota
|
|
vertical
|
|
)
|
|
|
|
func (h *windowsAnsiEventHandler) getCursorWindow(info *CONSOLE_SCREEN_BUFFER_INFO) SMALL_RECT {
|
|
if h.originMode {
|
|
sr := h.effectiveSr(info.Window)
|
|
return SMALL_RECT{
|
|
Top: sr.top,
|
|
Bottom: sr.bottom,
|
|
Left: 0,
|
|
Right: info.Size.X - 1,
|
|
}
|
|
} else {
|
|
return SMALL_RECT{
|
|
Top: info.Window.Top,
|
|
Bottom: info.Window.Bottom,
|
|
Left: 0,
|
|
Right: info.Size.X - 1,
|
|
}
|
|
}
|
|
}
|
|
|
|
// setCursorPosition sets the cursor to the specified position, bounded to the screen size
|
|
func (h *windowsAnsiEventHandler) setCursorPosition(position COORD, window SMALL_RECT) error {
|
|
position.X = ensureInRange(position.X, window.Left, window.Right)
|
|
position.Y = ensureInRange(position.Y, window.Top, window.Bottom)
|
|
err := SetConsoleCursorPosition(h.fd, position)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
h.logf("Cursor position set: (%d, %d)", position.X, position.Y)
|
|
return err
|
|
}
|
|
|
|
func (h *windowsAnsiEventHandler) moveCursorVertical(param int) error {
|
|
return h.moveCursor(vertical, param)
|
|
}
|
|
|
|
func (h *windowsAnsiEventHandler) moveCursorHorizontal(param int) error {
|
|
return h.moveCursor(horizontal, param)
|
|
}
|
|
|
|
func (h *windowsAnsiEventHandler) moveCursor(moveMode int, param int) error {
|
|
info, err := GetConsoleScreenBufferInfo(h.fd)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
position := info.CursorPosition
|
|
switch moveMode {
|
|
case horizontal:
|
|
position.X += int16(param)
|
|
case vertical:
|
|
position.Y += int16(param)
|
|
}
|
|
|
|
if err = h.setCursorPosition(position, h.getCursorWindow(info)); err != nil {
|
|
return err
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
func (h *windowsAnsiEventHandler) moveCursorLine(param int) error {
|
|
info, err := GetConsoleScreenBufferInfo(h.fd)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
position := info.CursorPosition
|
|
position.X = 0
|
|
position.Y += int16(param)
|
|
|
|
if err = h.setCursorPosition(position, h.getCursorWindow(info)); err != nil {
|
|
return err
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
func (h *windowsAnsiEventHandler) moveCursorColumn(param int) error {
|
|
info, err := GetConsoleScreenBufferInfo(h.fd)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
position := info.CursorPosition
|
|
position.X = int16(param) - 1
|
|
|
|
if err = h.setCursorPosition(position, h.getCursorWindow(info)); err != nil {
|
|
return err
|
|
}
|
|
|
|
return nil
|
|
}
|