elvish/pkg/sys/winsize_windows.go
Qi Xiao 7a72b6346a Reorganize pkg/sys into portable and non-portable system utilities.
Non-portable ones are moved into new packages pkg/sys/e{unix windows}. The "e"
prefix is needed to avoid conflict with packages under golang.org/x/sys/ and can
mean "extra".
2021-10-02 13:14:00 +01:00

24 lines
514 B
Go

package sys
import (
"fmt"
"os"
"syscall"
"golang.org/x/sys/windows"
)
// Windows doesn't have SIGCH, so use an impossible value.
const sigWINCH = syscall.Signal(-1)
func winSize(file *os.File) (row, col int) {
var info windows.ConsoleScreenBufferInfo
err := windows.GetConsoleScreenBufferInfo(windows.Handle(file.Fd()), &info)
if err != nil {
fmt.Printf("error in winSize: %v", err)
return -1, -1
}
window := info.Window
return int(window.Bottom - window.Top), int(window.Right - window.Left)
}