From 3717d7c383e7038a963f0fcf0e047943e4c0c153 Mon Sep 17 00:00:00 2001 From: chzyer <0@0xdf.com> Date: Tue, 21 Jun 2016 17:47:31 +0800 Subject: [PATCH] [terminal] fix when only stderr is tty (1>/dev/null) --- utils_unix.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/utils_unix.go b/utils_unix.go index addc5ba..39c32a1 100644 --- a/utils_unix.go +++ b/utils_unix.go @@ -44,7 +44,11 @@ func getWidth(stdoutFd int) int { } func GetScreenWidth() int { - return getWidth(syscall.Stdout) + w := getWidth(syscall.Stdout) + if w < 0 { + w = getWidth(syscall.Stderr) + } + return w } // ClearScreen clears the console screen @@ -53,7 +57,7 @@ func ClearScreen(w io.Writer) (int, error) { } func DefaultIsTerminal() bool { - return IsTerminal(syscall.Stdin) && IsTerminal(syscall.Stdout) + return IsTerminal(syscall.Stdin) && (IsTerminal(syscall.Stdout) || IsTerminal(syscall.Stderr)) } func GetStdin() int {