Determine whether the stream is a tty.
-
Supports most platforms
-
Supports force override using environment variable
FORCE_TTY
go get gopkg.ilharper.com/x/isatty
import "gopkg.ilharper.com/x/isatty"
if isatty.Isatty(os.Stdout.Fd()) {
// TTY
} else {
// Not TTY
}
User can override the result using the environment variable FORCE_TTY
.
# Force TTY
FORCE_TTY=
FORCE_TTY=1
FORCE_TTY=true
# Force not TTY
FORCE_TTY=0
FORCE_TTY=false
To determine whether the current stdout
is a tty:
go test
See #3.