From f7600f07eecbdac0a4400ca2bc39e3e9f5a53b1b Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Thu, 8 Dec 2022 10:49:57 +0200 Subject: Add --[no]diag-color options (infrastructure only) --- libbuild2/diagnostics.cxx | 40 ++++++++++++++++++++++++++++++++++++---- 1 file changed, 36 insertions(+), 4 deletions(-) (limited to 'libbuild2/diagnostics.cxx') diff --git a/libbuild2/diagnostics.cxx b/libbuild2/diagnostics.cxx index d91150b..b31ff82 100644 --- a/libbuild2/diagnostics.cxx +++ b/libbuild2/diagnostics.cxx @@ -3,7 +3,8 @@ #include -#include // strchr(), memcpy() +#include // strcmp(), strchr(), memcpy() +#include // getenv() #include @@ -24,23 +25,54 @@ namespace build2 bool silent = true; optional diag_progress_option; + optional diag_color_option; bool diag_no_line = false; bool diag_no_column = false; - bool stderr_term = false; + optional stderr_term = nullopt; + bool stderr_term_color = false; void - init_diag (uint16_t v, bool s, optional p, bool nl, bool nc, bool st) + init_diag (uint16_t v, + bool s, + optional p, + optional c, + bool nl, + bool nc, + bool st) { assert (!s || v == 0); verb = v; silent = s; diag_progress_option = p; + diag_color_option = c; diag_no_line = nl; diag_no_column = nc; - stderr_term = st; + + if (st) + { + stderr_term = std::getenv ("TERM"); + + stderr_term_color = +#ifdef _WIN32 + // For now we disable color on Windows since it's unclear if/where/how + // it is supported. Maybe one day someone will figure this out. + // + false +#else + // This test was lifted from GCC (Emacs shell sets TERM=dumb). + // + *stderr_term != nullptr && strcmp (*stderr_term, "dumb") != 0 +#endif + ; + } + else + { + stderr_term = nullopt; + stderr_term_color = false; + } } // Stream verbosity. -- cgit v1.1