diff options
-rwxr-xr-x | misc/output_test.py | 21 | ||||
-rw-r--r-- | src/build.cc | 1 | ||||
-rw-r--r-- | src/line_printer.cc | 4 |
3 files changed, 20 insertions, 6 deletions
diff --git a/misc/output_test.py b/misc/output_test.py index 6a5b635..878de19 100755 --- a/misc/output_test.py +++ b/misc/output_test.py @@ -11,11 +11,14 @@ import sys import tempfile import unittest -def run(build_ninja, flags='', pipe=False): - env = dict(os.environ) - if 'NINJA_STATUS' in env: - del env['NINJA_STATUS'] - env['TERM'] = '' +default_env = dict(os.environ) +if 'NINJA_STATUS' in default_env: + del default_env['NINJA_STATUS'] +if 'CLICOLOR_FORCE' in default_env: + del default_env['CLICOLOR_FORCE'] +default_env['TERM'] = '' + +def run(build_ninja, flags='', pipe=False, env=default_env): with tempfile.NamedTemporaryFile('w') as f: f.write(build_ninja) f.flush() @@ -84,5 +87,13 @@ red red ''') + # CLICOLOR_FORCE=1 can be used to disable escape code stripping. + env = default_env.copy() + env['CLICOLOR_FORCE'] = '1' + self.assertEqual(run(print_red, pipe=True, env=env), +'''[1/1] echo a +\x1b[31mred\x1b[0m +''') + if __name__ == '__main__': unittest.main() diff --git a/src/build.cc b/src/build.cc index 6b33024..ed219fd 100644 --- a/src/build.cc +++ b/src/build.cc @@ -154,7 +154,6 @@ void BuildStatus::BuildEdgeFinished(Edge* edge, // (Launching subprocesses in pseudo ttys doesn't work because there are // only a few hundred available on some systems, and ninja can launch // thousands of parallel compile commands.) - // TODO: There should be a flag to disable escape code stripping. string final_output; if (!printer_.supports_color()) final_output = StripAnsiEscapeCodes(output); diff --git a/src/line_printer.cc b/src/line_printer.cc index a3a551e..6effca6 100644 --- a/src/line_printer.cc +++ b/src/line_printer.cc @@ -42,6 +42,10 @@ LinePrinter::LinePrinter() : have_blank_line_(true), console_locked_(false) { smart_terminal_ = GetConsoleScreenBufferInfo(console_, &csbi); #endif supports_color_ = smart_terminal_; + if (!supports_color_) { + const char* clicolor_force = getenv("CLICOLOR_FORCE"); + supports_color_ = clicolor_force && string(clicolor_force) != "0"; + } } void LinePrinter::Print(string to_print, LineType type) { |