terminal: use exact window size for pager (#3249)

Instead of using a fixed 100x30 window size query the operating system
for the exact size, also fixes a bug where the last line before calling
the pager is repeated twice.
This commit is contained in:
Alessandro Arzilli
2023-01-16 18:20:43 +01:00
committed by GitHub
parent 58fc3931e8
commit 2be9cf1fab
3 changed files with 79 additions and 11 deletions

25
pkg/terminal/out_unix.go Normal file
View File

@ -0,0 +1,25 @@
//go:build linux || darwin || freebsd
// +build linux darwin freebsd
package terminal
import (
"syscall"
"unsafe"
)
type winSize struct {
row, col uint16
xpixel, ypixel uint16
}
func (w *pagingWriter) getWindowSize() {
var ws winSize
ok, _, _ := syscall.Syscall(syscall.SYS_IOCTL, uintptr(syscall.Stdout), syscall.TIOCGWINSZ, uintptr(unsafe.Pointer(&ws)))
if int(ok) < 0 {
w.mode = pagingWriterNormal
return
}
w.lines = int(ws.row)
w.columns = int(ws.col)
}