File: term_posix.go

package info (click to toggle)
golang-github-tdewolff-argp 0.0~git20240625.87b04d5-1
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 152 kB
  • sloc: makefile: 2
file content (21 lines) | stat: -rw-r--r-- 400 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
// +build !windows

package argp

import (
	"syscall"
	"unsafe"
)

func TerminalSize() (int, int, error) {
	data := struct {
		Row    uint16
		Col    uint16
		Xpixel uint16
		Ypixel uint16
	}{}
	if _, _, err := syscall.Syscall(syscall.SYS_IOCTL, uintptr(syscall.Stdin), syscall.TIOCGWINSZ, uintptr(unsafe.Pointer(&data))); err != 0 {
		return 0, 0, err
	}
	return int(data.Row), int(data.Col), nil
}