From 6280033ac4d3d3646c4c512a1c852c9c8f088f80 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Wed, 18 Nov 2015 15:35:45 +0200 Subject: Add support for ANSI colorization of usage output --- cli/context.cxx | 40 ++++++++++++++++++++++++++++++++++++---- 1 file changed, 36 insertions(+), 4 deletions(-) (limited to 'cli/context.cxx') diff --git a/cli/context.cxx b/cli/context.cxx index d41bb3c..7459406 100644 --- a/cli/context.cxx +++ b/cli/context.cxx @@ -614,8 +614,23 @@ format_line (output_type ot, string& r, const char* s, size_t n) { case ot_plain: { - if (b & code) - r += "'"; + if ((b & link) == 0) + { + if (options.ansi_color ()) + { + if (b & bold) + r += "\033[1m"; + + if (b & itlc) + r += "\033[4m"; + } + else + { + if (b & code) + r += "'"; + } + } + break; } case ot_html: @@ -713,8 +728,25 @@ format_line (output_type ot, string& r, const char* s, size_t n) } else { - if (b & code) - r += "'"; + if (options.ansi_color ()) + { + // While there are codes to turn off bold (22) and + // underline (24), it is not clear how widely they + // are supported. + // + r += "\033[0m"; // Clear all. + + if (eb & bold) + r += "\033[1m"; + + if (eb & itlc) + r += "\033[4m"; + } + else + { + if (b & code) + r += "'"; + } } break; -- cgit v1.1