-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.go
More file actions
49 lines (43 loc) · 1.01 KB
/
Copy pathutils.go
File metadata and controls
49 lines (43 loc) · 1.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package TableWriter
import (
"syscall"
"unsafe"
)
type dividers struct {
HLine string
VLine string
TL string
TR string
BL string
BR string
Cross string
TUp string
TDown string
TRight string
TLeft string
VLeft string
VRight string
}
// Winsize is the structure used for ioctl calls, to obtain the terminal size.
type winsize struct {
Row uint16 // Rows number
Col uint16 // Columns number (width)
Xpixel uint16 // Pixel's width
Ypixel uint16 // Pixel's Height
}
// getTerminalSize retrieves the terminal's size associated to the given file descriptor
func getTerminalSize(fd uintptr) (cols, rows int, err error) {
ws := &winsize{}
// TIOCGWINSZ is the constant that tells the kernel to retrieve the TTY size.
// Using the TIOCGWINSZ syscall is tailored to Linux/macOS.
ret, _, errno := syscall.Syscall(
syscall.SYS_IOCTL,
fd,
uintptr(syscall.TIOCGWINSZ),
uintptr(unsafe.Pointer(ws)),
)
if int(ret) == -1 {
return 0, 0, errno
}
return int(ws.Col), int(ws.Row), nil
}