github.com/oweisse/u-root@v0.0.0-20181109060735-d005ad25fef1/cmds/elvish/sys/winsize_windows.go (about)

     1  package sys
     2  
     3  import (
     4  	"fmt"
     5  	"os"
     6  	"syscall"
     7  
     8  	"golang.org/x/sys/windows"
     9  )
    10  
    11  // SIGWINCH is the Window size change signal. On Windows this signal does not
    12  // exist, so we use -1, an impossible value for signals.
    13  // NOTE: This has to use the syscall package before the x/sys/* packages also
    14  // use syscall.Signal to define signals.
    15  const SIGWINCH = syscall.Signal(-1)
    16  
    17  // GetWinsize queries the size of the terminal referenced by the given file.
    18  func GetWinsize(file *os.File) (row, col int) {
    19  	var info windows.ConsoleScreenBufferInfo
    20  	err := windows.GetConsoleScreenBufferInfo(windows.Handle(file.Fd()), &info)
    21  	if err != nil {
    22  		fmt.Printf("error in winSize: %v", err)
    23  		return -1, -1
    24  	}
    25  	window := info.Window
    26  	return int(window.Bottom - window.Top), int(window.Right - window.Left)
    27  }