From e7f36a71afe3e188b0be771819f9526d63a73c19 Mon Sep 17 00:00:00 2001 From: Freddie Akeroyd Date: Tue, 23 Feb 2021 15:24:24 +0000 Subject: [PATCH] Use streamDebugColored IOC variable instead --- src/StreamEpics.cc | 1 + src/StreamError.cc | 28 +++++++--------------------- src/StreamError.h | 1 + src/makedbd.pl | 1 + 4 files changed, 10 insertions(+), 21 deletions(-) diff --git a/src/StreamEpics.cc b/src/StreamEpics.cc index 878a024..b065b0f 100644 --- a/src/StreamEpics.cc +++ b/src/StreamEpics.cc @@ -198,6 +198,7 @@ public: extern "C" { // needed for Windows epicsExportAddress(int, streamDebug); epicsExportAddress(int, streamError); +epicsExportAddress(int, streamDebugColored); } // for subroutine record diff --git a/src/StreamError.cc b/src/StreamError.cc index 088a81d..3f03c83 100644 --- a/src/StreamError.cc +++ b/src/StreamError.cc @@ -29,7 +29,6 @@ #include #include #include -#include int streamDebug = 0; int streamError = 1; @@ -71,8 +70,12 @@ static bool win_console_init() { return true; } -/* true if console supports ANSI color codes */ -static bool win_console_colored = win_console_init(); +/* do isatty() call second as always want to run win_console_init() */ +int streamDebugColored = win_console_init() && _isatty(_fileno(stdout)); + +#else + +int streamDebugColored = isatty(fileno(stdout)); #endif /* _WIN32 */ @@ -158,22 +161,5 @@ const char* ansiEscape(AnsiMode mode) { static const char* AnsiEscapes[] = { "\033[7m", "\033[27m", "\033[47m", "\033[0m", "\033[31;1m" }; - static const char* stream_debug_color = getenv("STREAM_DEBUG_COLOR"); - bool color_output = false; - if (stream_debug_color == NULL || stream_debug_color[0] == 'A'|| - stream_debug_color[0] == 'a') // auto - { -#ifdef _WIN32 - color_output = win_console_colored && - _isatty(_fileno(epicsGetStdout())); -#else - color_output = isatty(fileno(epicsGetStdout())); -#endif /* _WIN32 */ - } - else if (stream_debug_color[0] == 'Y' || stream_debug_color[0] == 'y' || - stream_debug_color[0] == '1') // yes - { - color_output = true; - } - return color_output ? AnsiEscapes[mode] : ""; + return streamDebugColored ? AnsiEscapes[mode] : ""; } diff --git a/src/StreamError.h b/src/StreamError.h index ca881ff..2ec8183 100644 --- a/src/StreamError.h +++ b/src/StreamError.h @@ -32,6 +32,7 @@ extern int streamDebug; extern int streamError; +extern int streamDebugColored; extern void (*StreamPrintTimestampFunction)(char* buffer, size_t size); void StreamError(int line, const char* file, const char* fmt, ...) diff --git a/src/makedbd.pl b/src/makedbd.pl index 56b1069..2ec4f4c 100644 --- a/src/makedbd.pl +++ b/src/makedbd.pl @@ -32,6 +32,7 @@ if (@ARGV[0] eq "-3.13") { } else { print "variable(streamDebug, int)\n"; print "variable(streamError, int)\n"; + print "variable(streamDebugColored, int)\n"; print "registrar(streamRegistrar)\n"; if ($asyn) { print "registrar(AsynDriverInterfaceRegistrar)\n"; } }