//go:build windows package main import ( "os" "syscall" "unsafe" ) var getConsoleScreenBufferInfo = syscall.NewLazyDLL("kernel32.dll").NewProc("GetConsoleScreenBufferInfo") // termWidth returns the width of the window of the console f, and false when // f is not a console: GetConsoleScreenBufferInfo fails on anything else. func termWidth(f *os.File) (int, bool) { var info struct { size, cursor struct{ x, y int16 } attributes uint16 left, top, right, bottom int16 maxX, maxY int16 } if ok, _, _ := getConsoleScreenBufferInfo.Call(f.Fd(), uintptr(unsafe.Pointer(&info))); ok == 0 { return 0, false } return int(info.right-info.left) + 1, true }