elvish/pkg/sys/winsize_unix.go
Qi Xiao f7cb556d9b Require Go 1.18.
- Run "go fix" to remove legacy build tags

- Use staticcheck@master until it has a release that supports Go 1.18

- Turn off autocrlf for Windows tasks
2022-03-20 15:28:23 +00:00

38 lines
688 B
Go

//go:build !windows && !plan9
// Copyright 2015 go-termios Author. All Rights Reserved.
// https://github.com/go-termios/termios
// Author: John Lenton <chipaca@github.com>
package sys
import (
"fmt"
"os"
"golang.org/x/sys/unix"
)
const sigWINCH = unix.SIGWINCH
func winSize(file *os.File) (row, col int) {
fd := int(file.Fd())
ws, err := unix.IoctlGetWinsize(fd, unix.TIOCGWINSZ)
if err != nil {
fmt.Printf("error in winSize: %v", err)
return -1, -1
}
// Pick up a reasonable value for row and col
// if they equal zero in special case,
// e.g. serial console
if ws.Col == 0 {
ws.Col = 80
}
if ws.Row == 0 {
ws.Row = 24
}
return int(ws.Row), int(ws.Col)
}