[terminal] fix when only stderr is tty (1>/dev/null)

This commit is contained in:
chzyer 2016-06-21 17:47:31 +08:00
parent b411b0f4b2
commit 3717d7c383
1 changed files with 6 additions and 2 deletions

View File

@ -44,7 +44,11 @@ func getWidth(stdoutFd int) int {
} }
func GetScreenWidth() 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 // ClearScreen clears the console screen
@ -53,7 +57,7 @@ func ClearScreen(w io.Writer) (int, error) {
} }
func DefaultIsTerminal() bool { func DefaultIsTerminal() bool {
return IsTerminal(syscall.Stdin) && IsTerminal(syscall.Stdout) return IsTerminal(syscall.Stdin) && (IsTerminal(syscall.Stdout) || IsTerminal(syscall.Stderr))
} }
func GetStdin() int { func GetStdin() int {