From c12da5d44adb61e83460fc46adcca5cd0fedf7fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patrick=20L=C3=BChne?= Date: Thu, 24 Nov 2016 15:01:37 +0100 Subject: [PATCH] Added command-line option to control color output. --- app/main.cpp | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/app/main.cpp b/app/main.cpp index ea2e3d6..61054b1 100644 --- a/app/main.cpp +++ b/app/main.cpp @@ -15,7 +15,8 @@ int main(int argc, char **argv) description.add_options() ("help,h", "Display this help message") ("version,v", "Display version information") - ("input,i", po::value>(), "Input files"); + ("input,i", po::value>(), "Input files") + ("color", po::value()->default_value("auto"), "Whether to colorize the output (always, never, or auto)."); po::positional_options_description positionalOptionsDescription; positionalOptionsDescription.add("input", -1); @@ -59,6 +60,22 @@ int main(int argc, char **argv) return EXIT_SUCCESS; } + const auto colorPolicy = variablesMap["color"].as(); + + if (colorPolicy == "auto") + context.logger.setColorPolicy(anthem::output::ColorStream::ColorPolicy::Auto); + else if (colorPolicy == "never") + context.logger.setColorPolicy(anthem::output::ColorStream::ColorPolicy::Never); + else if (colorPolicy == "always") + context.logger.setColorPolicy(anthem::output::ColorStream::ColorPolicy::Always); + else + { + context.logger.log(anthem::output::Priority::Error, ("unknown color policy “" + colorPolicy + "”").c_str()); + context.logger.errorStream() << std::endl; + printHelp(); + return EXIT_FAILURE; + } + try { if (variablesMap.count("input"))