aboutsummaryrefslogtreecommitdiff
path: root/internal/cli/termwidth_unix.go
diff options
context:
space:
mode:
authorLukasz Kasprzak <lukas@labunix.xyz>2026-07-23 13:47:25 +0200
committerLukasz Kasprzak <lukas@labunix.xyz>2026-07-23 13:47:25 +0200
commitb3e5db93f7b59c7b80706ae30b505cb6b7945ec3 (patch)
treef42c52132b49b58540ef78be68cf0bef7479cab5 /internal/cli/termwidth_unix.go
parentcb1f49117d15b9690b46f344c0d6777e558b9021 (diff)
downloadlectio-b3e5db93f7b59c7b80706ae30b505cb6b7945ec3.tar.gz
lectio-b3e5db93f7b59c7b80706ae30b505cb6b7945ec3.zip
cli: subcommand dispatch
Diffstat (limited to 'internal/cli/termwidth_unix.go')
-rw-r--r--internal/cli/termwidth_unix.go23
1 files changed, 23 insertions, 0 deletions
diff --git a/internal/cli/termwidth_unix.go b/internal/cli/termwidth_unix.go
new file mode 100644
index 0000000..9d1b47d
--- /dev/null
+++ b/internal/cli/termwidth_unix.go
@@ -0,0 +1,23 @@
+//go:build unix
+
+package cli
+
+import (
+ "os"
+ "syscall"
+ "unsafe"
+)
+
+// ttyWidth returns f's terminal column width via the TIOCGWINSZ ioctl, or 0
+// if f isn't a terminal (redirected to a file/pipe, as in tests) or the
+// ioctl fails.
+func ttyWidth(f *os.File) int {
+ var ws struct {
+ Row, Col, Xpixel, Ypixel uint16
+ }
+ _, _, errno := syscall.Syscall(syscall.SYS_IOCTL, f.Fd(), syscall.TIOCGWINSZ, uintptr(unsafe.Pointer(&ws)))
+ if errno != 0 || ws.Col == 0 {
+ return 0
+ }
+ return int(ws.Col)
+}