mirror of
https://gogs.blitter.com/RLabs/xs
synced 2024-08-14 10:26:42 +00:00
f5be3578a8
2/3 Added vendor/ dir to lock down dependent pkg versions. The author of git.schwanenlied.me/yawning/{chacha20,newhope,kyber}.git has copied their repos to gitlab.com/yawning/ but some imports of chacha20 from newhope still inconsistently refer to git.schwanenlied.me/, breaking build. Licenses for chacha20 also changed from CC0 to AGPL, which may or may not be an issue. Until the two aforementioned issues are resolved, locking to last-good versions is probably the best way forward for now. To build with vendored deps, use make VENDOR=1 clean all 3/3 Moved body of CI push script into bacillus/
64 lines
1.5 KiB
Go
64 lines
1.5 KiB
Go
// +build !windows
|
|
|
|
package pty
|
|
|
|
import (
|
|
"os"
|
|
"syscall"
|
|
"unsafe"
|
|
)
|
|
|
|
// InheritSize applies the terminal size of pty to tty. This should be run
|
|
// in a signal handler for syscall.SIGWINCH to automatically resize the tty when
|
|
// the pty receives a window size change notification.
|
|
func InheritSize(pty, tty *os.File) error {
|
|
size, err := GetsizeFull(pty)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
err = Setsize(tty, size)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// Setsize resizes t to s.
|
|
func Setsize(t *os.File, ws *Winsize) error {
|
|
return windowRectCall(ws, t.Fd(), syscall.TIOCSWINSZ)
|
|
}
|
|
|
|
// GetsizeFull returns the full terminal size description.
|
|
func GetsizeFull(t *os.File) (size *Winsize, err error) {
|
|
var ws Winsize
|
|
err = windowRectCall(&ws, t.Fd(), syscall.TIOCGWINSZ)
|
|
return &ws, err
|
|
}
|
|
|
|
// Getsize returns the number of rows (lines) and cols (positions
|
|
// in each line) in terminal t.
|
|
func Getsize(t *os.File) (rows, cols int, err error) {
|
|
ws, err := GetsizeFull(t)
|
|
return int(ws.Rows), int(ws.Cols), err
|
|
}
|
|
|
|
// Winsize describes the terminal size.
|
|
type Winsize struct {
|
|
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
|
|
}
|
|
|
|
func windowRectCall(ws *Winsize, fd, a2 uintptr) error {
|
|
_, _, errno := syscall.Syscall(
|
|
syscall.SYS_IOCTL,
|
|
fd,
|
|
a2,
|
|
uintptr(unsafe.Pointer(ws)),
|
|
)
|
|
if errno != 0 {
|
|
return syscall.Errno(errno)
|
|
}
|
|
return nil
|
|
}
|