winsize_unix.go 879 B

1234567891011121314151617181920212223242526272829303132333435
  1. //go:build !windows
  2. // +build !windows
  3. package pty
  4. import (
  5. "os"
  6. "syscall"
  7. "unsafe"
  8. )
  9. // Winsize describes the terminal size.
  10. type Winsize struct {
  11. Rows uint16 // ws_row: Number of rows (in cells)
  12. Cols uint16 // ws_col: Number of columns (in cells)
  13. X uint16 // ws_xpixel: Width in pixels
  14. Y uint16 // ws_ypixel: Height in pixels
  15. }
  16. // Setsize resizes t to s.
  17. func Setsize(t *os.File, ws *Winsize) error {
  18. //nolint:gosec // Expected unsafe pointer for Syscall call.
  19. return ioctl(t.Fd(), syscall.TIOCSWINSZ, uintptr(unsafe.Pointer(ws)))
  20. }
  21. // GetsizeFull returns the full terminal size description.
  22. func GetsizeFull(t *os.File) (size *Winsize, err error) {
  23. var ws Winsize
  24. //nolint:gosec // Expected unsafe pointer for Syscall call.
  25. if err := ioctl(t.Fd(), syscall.TIOCGWINSZ, uintptr(unsafe.Pointer(&ws))); err != nil {
  26. return nil, err
  27. }
  28. return &ws, nil
  29. }