A terminal is a display unit that is part of the user interface to a computer system. The word carries the connotation of being text-only.
Terminal emulators for Linux have support for ANSI escape codes built in.
AMG: To check if stdin is connected to a terminal, run:
if {![catch {exec tty -s}]} { # stdin is a terminal }
Checking for stdout/stderr is harder because exec does not allow stdout/stderr to be redirected to stdin because stdout/stderr are not considered readable. Instead, let the shell do the redirection. Furthermore, instruct [exec] to not intercept stdout/stderr.
if {![catch {exec /bin/sh -c {tty -s < /dev/stdout}} >@ stdout]} { # stdout is a terminal } if {![catch {exec /bin/sh -c {tty -s < /dev/stderr}} 2>@ stderr]} { # stderr is a terminal }
Without the -s switch, the tty program not only checks if its stdin is a terminal, but it also prints the device name to its stdout, e.g. /dev/pts/0.