summaryrefslogtreecommitdiff
path: root/winsize_linux.go
blob: bf6f3d31edd2643c73752625da73444e2debf225 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
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
}