Created
February 7, 2017 11:33
-
-
Save Soulou/ad9b094d3b9a56c04995405751301e1b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"syscall" | |
"unsafe" | |
) | |
const cursorColumn = false | |
type State struct { | |
columns int | |
} | |
type winSize struct { | |
row, col uint16 | |
xpixel, ypixel uint16 | |
} | |
func (s *State) getColumns() bool { | |
var ws winSize | |
ok, _, _ := syscall.Syscall(syscall.SYS_IOCTL, uintptr(syscall.Stdout), | |
syscall.TIOCGWINSZ, uintptr(unsafe.Pointer(&ws))) | |
if int(ok) < 0 { | |
return false | |
} | |
s.columns = int(ws.col) | |
if cursorColumn && s.columns > 1 { | |
s.columns-- | |
} | |
return true | |
} | |
func main() { | |
s := State{} | |
fmt.Println(s.getColumns()) | |
fmt.Println(s.columns) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment