Skip to content

Commit

Permalink
utils/io/logger: don't print colors to not supported terminals
Browse files Browse the repository at this point in the history
  • Loading branch information
Peter Kubov committed Jul 22, 2020
1 parent 7c7174c commit 5cd42f2
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
1 change: 1 addition & 0 deletions include/retdec/utils/io/logger.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ class Logger {
Color _currentBrush = Color::Default;

bool _modifiedTerminalProperty = false;
bool _terminalNotSupported = false;
};

class FileLogger : public Logger {
Expand Down
5 changes: 4 additions & 1 deletion src/utils/io/logger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ Logger::Logger(std::ostream& stream, bool verbose):
// On windows we need to try to set ENABLE_VIRTUAL_TERMINAL_PROCESSING.
// This will enable ANSI support in terminal. This is best effort
// implementation approach.
_terminalNotSupported = true;
HANDLE hOut = GetStdHandle(STD_OUTPUT_HANDLE);
if (hOut == INVALID_HANDLE_VALUE)
return;
Expand All @@ -48,6 +49,8 @@ Logger::Logger(std::ostream& stream, bool verbose):
dwMode |= ENABLE_VIRTUAL_TERMINAL_PROCESSING;
if (!SetConsoleMode(hOut, dwMode))
return;

_terminalNotSupported = false;
#endif
}

Expand Down Expand Up @@ -103,7 +106,7 @@ Logger& Logger::operator << (const Color& lc)
/*Color::Default*/ "\u001b[0m"
};

if (isRedirected(_out))
if (_terminalNotSupported || isRedirected(_out))
return *this;

_currentBrush = lc;
Expand Down

0 comments on commit 5cd42f2

Please sign in to comment.