summaryrefslogtreecommitdiff
path: root/cmd/prognosis/term_unix.go
diff options
context:
space:
mode:
Diffstat (limited to 'cmd/prognosis/term_unix.go')
-rw-r--r--cmd/prognosis/term_unix.go28
1 files changed, 28 insertions, 0 deletions
diff --git a/cmd/prognosis/term_unix.go b/cmd/prognosis/term_unix.go
new file mode 100644
index 0000000..7cccf25
--- /dev/null
+++ b/cmd/prognosis/term_unix.go
@@ -0,0 +1,28 @@
+//go:build linux || darwin || freebsd || netbsd || openbsd
+
+package main
+
+import (
+ "os"
+ "syscall"
+ "unsafe"
+)
+
+// termCols asks the terminal for its width.
+//
+// This is an ioctl rather than golang.org/x/term because the spec keeps this
+// binary free of third-party modules; it is a dozen lines and only needs to
+// work on the platforms prognosis is built for.
+func termCols() (int, bool) {
+ var ws struct{ Row, Col, Xpixel, Ypixel uint16 }
+ _, _, errno := syscall.Syscall(
+ syscall.SYS_IOCTL,
+ os.Stdout.Fd(),
+ uintptr(syscall.TIOCGWINSZ),
+ uintptr(unsafe.Pointer(&ws)),
+ )
+ if errno != 0 || ws.Col == 0 {
+ return 0, false
+ }
+ return int(ws.Col), true
+}