package main import ( "syscall" "unsafe" ) func init() { ws := &struct { row uint16 col uint16 xpixel uint16 ypixel uint16 }{} retCode, _, errno := syscall.Syscall(syscall.SYS_IOCTL, uintptr(syscall.Stdin), uintptr(syscall.TIOCGWINSZ), uintptr(unsafe.Pointer(ws))) if int(retCode) == -1 { panic(errno) } Width = int(ws.col) - 2 }