Debian Codegraph @

vendor/github.com/kr/pty/util.go

raw
1 // +build !windows
2
3 package pty
4
5 import (
6 "os"
7 "syscall"
8 "unsafe"
9 )
10
11 // Getsize returns the number of rows (lines) and cols (positions
12 // in each line) in terminal t.
13 func Getsize(t *os.File) (rows, cols int, err error) {
14 var ws winsize
15 err = windowrect(&ws, t.Fd())
16 return int(ws.ws_row), int(ws.ws_col), err
17 }
18
19 type winsize struct {
20 ws_row uint16
21 ws_col uint16
22 ws_xpixel uint16
23 ws_ypixel uint16
24 }
25
26 func windowrect(ws *winsize, fd uintptr) error {
27 _, _, errno := syscall.Syscall(
28 syscall.SYS_IOCTL,
29 fd,
30 syscall.TIOCGWINSZ,
31 uintptr(unsafe.Pointer(ws)),
32 )
33 if errno != 0 {
34 return syscall.Errno(errno)
35 }
36 return nil
37 }