winsize.go 681 B

123456789101112131415161718192021222324252627
  1. package pty
  2. import "os"
  3. // InheritSize applies the terminal size of pty to tty. This should be run
  4. // in a signal handler for syscall.SIGWINCH to automatically resize the tty when
  5. // the pty receives a window size change notification.
  6. func InheritSize(pty, tty *os.File) error {
  7. size, err := GetsizeFull(pty)
  8. if err != nil {
  9. return err
  10. }
  11. if err := Setsize(tty, size); err != nil {
  12. return err
  13. }
  14. return nil
  15. }
  16. // Getsize returns the number of rows (lines) and cols (positions
  17. // in each line) in terminal t.
  18. func Getsize(t *os.File) (rows, cols int, err error) {
  19. ws, err := GetsizeFull(t)
  20. if err != nil {
  21. return 0, 0, err
  22. }
  23. return int(ws.Rows), int(ws.Cols), nil
  24. }