From c48d5c298a8d6359a2a17914432e8531e3cb883f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Ho=C5=A1ek?= Date: Tue, 7 May 2013 15:49:14 +0200 Subject: [PATCH] HLExtract: use colors only if outputting to a terminal --- HLExtract/Main.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/HLExtract/Main.c b/HLExtract/Main.c index ec2b2d0..b82bc0a 100644 --- a/HLExtract/Main.c +++ b/HLExtract/Main.c @@ -53,6 +53,7 @@ # define UNUSED # include #else +# include # include # define MAX_PATH PATH_MAX # define UNUSED __attribute__((__unused__)) @@ -575,7 +576,15 @@ hlVoid SetColor(hlUInt16 uiColor) SetConsoleTextAttribute(Handle, uiColor); #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) {