git-lfs/vendor/github.com/cheggaaa/pb/pb_x.go

47 lines
679 B
Go
Raw Normal View History

2015-04-24 17:48:49 +00:00
// +build linux darwin freebsd netbsd openbsd solaris
2014-07-24 20:57:57 +00:00
package pb
import (
2015-04-24 17:48:49 +00:00
"os"
2014-07-24 20:57:57 +00:00
"runtime"
"syscall"
"unsafe"
)
const (
TIOCGWINSZ = 0x5413
TIOCGWINSZ_OSX = 1074295912
)
2015-04-24 17:48:49 +00:00
var tty *os.File
func init() {
var err error
tty, err = os.Open("/dev/tty")
if err != nil {
tty = os.Stdin
}
}
2014-07-24 20:57:57 +00:00
func bold(str string) string {
return "\033[1m" + str + "\033[0m"
}
func terminalWidth() (int, error) {
w := new(window)
tio := syscall.TIOCGWINSZ
if runtime.GOOS == "darwin" {
tio = TIOCGWINSZ_OSX
}
res, _, err := syscall.Syscall(sys_ioctl,
2015-04-24 17:48:49 +00:00
tty.Fd(),
2014-07-24 20:57:57 +00:00
uintptr(tio),
uintptr(unsafe.Pointer(w)),
)
if int(res) == -1 {
return 0, err
}
return int(w.Col), nil
}