2017-03-13 02:57:45 +03:00
|
|
|
// Copyright 2011 The Go Authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
2023-10-24 23:00:38 +03:00
|
|
|
//go:build darwin || dragonfly || freebsd || (linux && !appengine) || netbsd || openbsd
|
2017-03-13 02:57:45 +03:00
|
|
|
// +build darwin dragonfly freebsd linux,!appengine netbsd openbsd
|
|
|
|
|
|
|
|
package readline
|
|
|
|
|
|
|
|
import (
|
|
|
|
"syscall"
|
2023-10-24 23:00:38 +03:00
|
|
|
|
|
|
|
"golang.org/x/sys/unix"
|
2017-03-13 02:57:45 +03:00
|
|
|
)
|
|
|
|
|
|
|
|
type Termios syscall.Termios
|
|
|
|
|
|
|
|
// GetSize returns the dimensions of the given terminal.
|
|
|
|
func GetSize(fd int) (int, int, error) {
|
2023-10-24 23:00:38 +03:00
|
|
|
winsize, err := unix.IoctlGetWinsize(fd, unix.TIOCGWINSZ)
|
|
|
|
if err != nil {
|
2017-03-13 02:57:45 +03:00
|
|
|
return 0, 0, err
|
|
|
|
}
|
2023-10-24 23:00:38 +03:00
|
|
|
return int(winsize.Col), int(winsize.Row), nil
|
2017-03-13 02:57:45 +03:00
|
|
|
}
|