Skip to content

Instantly share code, notes, and snippets.

@Soulou
Created February 7, 2017 11:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Soulou/ad9b094d3b9a56c04995405751301e1b to your computer and use it in GitHub Desktop.
Save Soulou/ad9b094d3b9a56c04995405751301e1b to your computer and use it in GitHub Desktop.
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