mirror of
https://github.com/kemko/xc.git
synced 2026-01-01 15:55:43 +03:00
35 lines
599 B
Go
35 lines
599 B
Go
package term
|
|
|
|
import (
|
|
"bytes"
|
|
"syscall"
|
|
"unsafe"
|
|
)
|
|
|
|
type winsize struct {
|
|
Row uint16
|
|
Col uint16
|
|
Xpixel uint16
|
|
Ypixel uint16
|
|
}
|
|
|
|
// HR returns a horizontal ruler of a given size
|
|
func HR(len int) string {
|
|
h := bytes.Repeat([]byte("="), len)
|
|
return string(h)
|
|
}
|
|
|
|
// GetTerminalWidth returns the current terminal width in symbols
|
|
func GetTerminalWidth() int {
|
|
ws := &winsize{}
|
|
retCode, _, errno := syscall.Syscall(syscall.SYS_IOCTL,
|
|
uintptr(syscall.Stdin),
|
|
uintptr(syscall.TIOCGWINSZ),
|
|
uintptr(unsafe.Pointer(ws)))
|
|
|
|
if int(retCode) == -1 {
|
|
panic(errno)
|
|
}
|
|
return int(ws.Col)
|
|
}
|