2015-09-27 06:41:05 +03:00
|
|
|
// +build windows
|
|
|
|
|
|
|
|
package readline
|
|
|
|
|
2016-05-16 12:59:35 +03:00
|
|
|
import (
|
2022-05-16 04:56:06 +03:00
|
|
|
"fmt"
|
2016-05-16 12:59:35 +03:00
|
|
|
"io"
|
|
|
|
"syscall"
|
|
|
|
)
|
2016-03-13 13:32:48 +03:00
|
|
|
|
2016-04-17 16:05:00 +03:00
|
|
|
func SuspendMe() {
|
|
|
|
}
|
|
|
|
|
2016-03-13 13:32:48 +03:00
|
|
|
func GetStdin() int {
|
|
|
|
return int(syscall.Stdin)
|
|
|
|
}
|
|
|
|
|
2015-09-29 16:01:17 +03:00
|
|
|
func init() {
|
|
|
|
isWindows = true
|
|
|
|
}
|
|
|
|
|
2015-09-27 06:41:05 +03:00
|
|
|
// get width of the terminal
|
2016-03-13 13:32:48 +03:00
|
|
|
func GetScreenWidth() int {
|
2015-09-29 12:49:58 +03:00
|
|
|
info, _ := GetConsoleScreenBufferInfo()
|
|
|
|
if info == nil {
|
2016-02-18 06:25:41 +03:00
|
|
|
return -1
|
2015-09-29 12:49:58 +03:00
|
|
|
}
|
|
|
|
return int(info.dwSize.x)
|
2015-09-27 06:41:05 +03:00
|
|
|
}
|
2016-03-13 13:32:48 +03:00
|
|
|
|
2022-05-16 04:56:06 +03:00
|
|
|
// Send the Current cursor position to t.sizeChan.
|
|
|
|
func SendCursorPosition(t *Terminal) {
|
|
|
|
info, err := GetConsoleScreenBufferInfo()
|
|
|
|
if err != nil || info == nil {
|
|
|
|
t.sizeChan <- "-1;-1"
|
|
|
|
} else {
|
|
|
|
t.sizeChan <- fmt.Sprintf("%d;%d", info.dwCursorPosition.y, info.dwCursorPosition.x)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-05-16 12:59:35 +03:00
|
|
|
// ClearScreen clears the console screen
|
|
|
|
func ClearScreen(_ io.Writer) error {
|
|
|
|
return SetConsoleCursorPosition(&_COORD{0, 0})
|
|
|
|
}
|
|
|
|
|
2016-03-13 13:32:48 +03:00
|
|
|
func DefaultIsTerminal() bool {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
func DefaultOnWidthChanged(func()) {
|
|
|
|
|
|
|
|
}
|