HLExtract: use colors only if outputting to a terminal

This commit is contained in:
Ondřej Hošek 2013-05-07 15:49:14 +02:00
parent 0dce4a6660
commit c48d5c298a
1 changed files with 10 additions and 1 deletions

View File

@ -53,6 +53,7 @@
# define UNUSED # define UNUSED
# include <windows.h> # include <windows.h>
#else #else
# include <unistd.h>
# include <linux/limits.h> # include <linux/limits.h>
# define MAX_PATH PATH_MAX # define MAX_PATH PATH_MAX
# define UNUSED __attribute__((__unused__)) # define UNUSED __attribute__((__unused__))
@ -575,7 +576,15 @@ hlVoid SetColor(hlUInt16 uiColor)
SetConsoleTextAttribute(Handle, uiColor); SetConsoleTextAttribute(Handle, uiColor);
#else #else
hlUInt16 uiColorPart = (uiColor & (FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE)); hlUInt16 uiColorPart;
if (!isatty(fileno(stdout)))
{
// cowardly refuse to write colors into things that aren't terminals
return;
}
uiColorPart = (uiColor & (FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE));
if (uiColorPart == 0) if (uiColorPart == 0)
{ {