Breite im Terminal begrenzen
This commit is contained in:
29
internal/formatter/terminal_linux.go
Normal file
29
internal/formatter/terminal_linux.go
Normal 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
|
||||
}
|
||||
Reference in New Issue
Block a user