mirror of
https://github.com/restic/restic.git
synced 2024-12-23 00:07:25 +00:00
#1795 use unix.IoctlGetWinsize to get terminal size
This commit is contained in:
parent
0183fea926
commit
589c23dc23
1 changed files with 5 additions and 6 deletions
|
@ -4,8 +4,8 @@ package termstatus
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"io"
|
"io"
|
||||||
"syscall"
|
|
||||||
"unsafe"
|
"golang.org/x/sys/unix"
|
||||||
|
|
||||||
isatty "github.com/mattn/go-isatty"
|
isatty "github.com/mattn/go-isatty"
|
||||||
)
|
)
|
||||||
|
@ -30,10 +30,9 @@ func canUpdateStatus(fd uintptr) bool {
|
||||||
// getTermSize returns the dimensions of the given terminal.
|
// getTermSize returns the dimensions of the given terminal.
|
||||||
// the code is taken from "golang.org/x/crypto/ssh/terminal"
|
// the code is taken from "golang.org/x/crypto/ssh/terminal"
|
||||||
func getTermSize(fd uintptr) (width, height int, err error) {
|
func getTermSize(fd uintptr) (width, height int, err error) {
|
||||||
var dimensions [4]uint16
|
ws, err := unix.IoctlGetWinsize(int(fd), unix.TIOCGWINSZ)
|
||||||
|
if err != nil {
|
||||||
if _, _, err := syscall.Syscall6(syscall.SYS_IOCTL, fd, uintptr(syscall.TIOCGWINSZ), uintptr(unsafe.Pointer(&dimensions)), 0, 0, 0); err != 0 {
|
|
||||||
return -1, -1, err
|
return -1, -1, err
|
||||||
}
|
}
|
||||||
return int(dimensions[1]), int(dimensions[0]), nil
|
return int(ws.Col), int(ws.Row), nil
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue