erlang/otp — pull request #480 by andrewjstone (2014-09-22 18:16:34+00:00)
Title: Add os:isatty/1 as a bif

The posix libc function, isatty(), is a useful function that will tell
you if a file descriptor is attached to a terminal. If, for instance, you
want to write a program that uses ansi color codes, it is not enough to
just check $TERM because the output could be redirected to a file. In
that case you would end up with the escape codes in the file making it
harder to read and parse. By calling os:isatty/1 with stdout as its
parameter the program can ensure that it never writes escape codes to
log files.

This PR adds os:isatty/1 as well as docs and a test of its argument
handling. os:isatty/1 accepts the atoms stdin, stdout and stderr as well
as any 32 bit non_negative_integer() representing a file descriptor. It
simply returns false in case the integer is not an FD, and throws in the
case of a bad argument. The test does not check the return value in the
valid case, because that would depend upon how tests are run.

This code should work on all platforms including Windows, as isatty is a
posix function. Note however that it is deprecated on Windows according
to MSDN in favor of the C++ standard _isatty().