text_formatter: detect tty based on fd

This commit is contained in:
Simon Eskildsen
2017-02-05 09:21:03 -05:00
parent 61e43dc76f
commit 1726e1744a
5 changed files with 39 additions and 18 deletions
+9 -3
View File
@@ -9,7 +9,13 @@ import (
)
// IsTerminal returns true if the given file descriptor is a terminal.
func IsTerminal() bool {
_, err := unix.IoctlGetTermios(int(os.Stdout.Fd()), unix.TCGETA)
return err == nil
func IsTerminal(f io.Writer) bool {
var termios Termios
switch v := f.(type) {
case *os.File:
_, err := unix.IoctlGetTermios(int(f.Fd()), unix.TCGETA)
return err == nil
default:
return false
}
}