Determine whether the stream is a tty.
-
Supports most platforms
-
Supports force override using environment variable
FORCE_TTY
go get gopkg.ilharper.com/x/isattyimport "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=falseTo determine whether the current stdout is a tty:
go testSee #3.