github.com/dolfly/pty@v1.2.1/winsize.go (about) 1 package pty 2 3 // Winsize describes the terminal size. 4 type Winsize struct { 5 Rows uint16 // ws_row: Number of rows (in cells) 6 Cols uint16 // ws_col: Number of columns (in cells) 7 X uint16 // ws_xpixel: Width in pixels 8 Y uint16 // ws_ypixel: Height in pixels 9 } 10 11 // InheritSize applies the terminal size of pty to tty. This should be run 12 // in a signal handler for syscall.SIGWINCH to automatically resize the tty when 13 // the pty receives a window size change notification. 14 func InheritSize(pty Pty, tty Tty) error { 15 size, err := GetsizeFull(pty) 16 if err != nil { 17 return err 18 } 19 20 if err := Setsize(tty, size); err != nil { 21 return err 22 } 23 return nil 24 } 25 26 // Getsize returns the number of rows (lines) and cols (positions 27 // in each line) in terminal t. 28 func Getsize(t FdHolder) (rows, cols int, err error) { 29 ws, err := GetsizeFull(t) 30 return int(ws.Rows), int(ws.Cols), err 31 }