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.
** See Also **
[ANSI]: vVarious ANSI standards govern terminal behaviour.
[xterm]: aA terminal emulator.
[curses]: aA [C] library for controlling terminals.
[handling of ANSI terminals using Expect]:
[stty]: tThe [Units%|%*nix] command to configure and manage a terminal.
[terminal control sequence]:
** Reference **
[http://vt100.net/%|%VT100.net]: This sitDe is dedicated to the range of video terminals produced by Digital Equipment Corporation (DEC) from 1970 to 1995. The most famous of these is the VT100.
[http://www.linusakesson.net/programming/tty/index.php%|%The TTY demystified], Linus Åkesson, 2008-07-25:
** Description **
Terminal emulators for [Linux] have support for ANSI escape codes built in.
** Checking for a Terminal **
[AMG]: To check if stdin is connected to a terminal, run:
======
if {![catch {exec /usr/bin/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 {/usr/bin/tty -s < /dev/stdout} >@ stdout}]} {
# stdout is a terminal
}
if {![catch {exec /bin/sh -c {/usr/bin/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`.
<<categories>> Text Screen