atoum/atoum — pull request #193 by Hywan (2013-04-04 13:58:04+00:00)
Title: New isTerminal() implementation

The goal of this function is twofold. First: detect if STDOUT is a character device (e.g. screen, so a device that supports characters and attached to a terminal) or not (a pipe, a redirection, something else…).
Second: detect if the terminal supports colours. We assume that POSIX-compliant systems always support colours, and for Windows, we look for an additional program that creates a variable in the environment (says ANSICON).

This patch then works in two steps. First: detect if STDOUT is a character device. We have removed the dependency to the posix_isatty() function by using fstat(). The previous isTerminal() implementation did not consider that Windows supports redirections (because of the unavailibility of posix_*() functions). This new approach works on all systems, POSIX or not.
Second: we detect if the terminal supports colours (only for Windows).
The result is a conjunction of these two steps.

This is inspired from Hoa\Console, and please, see sys/stat.h to understand the numbers.

Tests have been consequently updated.