2023-04-26 20:20:43 -04:00
|
|
|
//go:build !windows
|
|
|
|
// +build !windows
|
|
|
|
|
|
|
|
package pty
|
|
|
|
|
|
|
|
import (
|
|
|
|
"os"
|
|
|
|
"syscall"
|
|
|
|
"unsafe"
|
|
|
|
)
|
|
|
|
|
|
|
|
// Winsize describes the terminal size.
|
|
|
|
type Winsize struct {
|
2024-01-08 04:22:09 -05:00
|
|
|
Rows uint16 // ws_row: Number of rows (in cells).
|
|
|
|
Cols uint16 // ws_col: Number of columns (in cells).
|
|
|
|
X uint16 // ws_xpixel: Width in pixels.
|
|
|
|
Y uint16 // ws_ypixel: Height in pixels.
|
2023-04-26 20:20:43 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Setsize resizes t to s.
|
|
|
|
func Setsize(t *os.File, ws *Winsize) error {
|
|
|
|
//nolint:gosec // Expected unsafe pointer for Syscall call.
|
2024-01-08 04:22:09 -05:00
|
|
|
return ioctl(t, syscall.TIOCSWINSZ, uintptr(unsafe.Pointer(ws)))
|
2023-04-26 20:20:43 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// GetsizeFull returns the full terminal size description.
|
|
|
|
func GetsizeFull(t *os.File) (size *Winsize, err error) {
|
|
|
|
var ws Winsize
|
|
|
|
|
|
|
|
//nolint:gosec // Expected unsafe pointer for Syscall call.
|
2024-01-08 04:22:09 -05:00
|
|
|
if err := ioctl(t, syscall.TIOCGWINSZ, uintptr(unsafe.Pointer(&ws))); err != nil {
|
2023-04-26 20:20:43 -04:00
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return &ws, nil
|
|
|
|
}
|