Breite im Terminal begrenzen

This commit is contained in:
2026-07-12 12:25:51 +02:00
parent 8b23f8b116
commit a1504dd5e6
4 changed files with 133 additions and 5 deletions

View File

@@ -0,0 +1,29 @@
//go:build linux
package formatter
import (
"syscall"
"unsafe"
)
type winsize struct {
Row, Col uint16
Xpixel, Ypixel uint16
}
// getTerminalWidth returns the width of the stdout terminal in columns.
// If the output is not a terminal or the width cannot be determined, it returns (0, error).
func getTerminalWidth() (int, error) {
var ws winsize
_, _, errno := syscall.Syscall(
syscall.SYS_IOCTL,
uintptr(syscall.Stdout),
uintptr(syscall.TIOCGWINSZ),
uintptr(unsafe.Pointer(&ws)),
)
if errno != 0 {
return 0, errno
}
return int(ws.Col), nil
}