From fd8db544bd534fdba0ef176733aad5758262541a Mon Sep 17 00:00:00 2001 From: tastytea Date: Tue, 25 May 2021 11:45:25 +0200 Subject: [PATCH] Add --nocolor switch. Closes: https://schlomp.space/tastytea/epubgrep/issues/2 --- src/main.cpp | 15 +++++++++++---- src/options.cpp | 4 +++- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index c4fafe0..30341db 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -125,10 +125,17 @@ int main(int argc, char *argv[]) { cout << ", page " << match.page; } - cout << ": " << match.context.first - << termcolor::bright_magenta << match.text - << termcolor::reset << match.context.second - << '\n'; + cout << ": " << match.context.first; + if (vm.count("nocolor") == 0) + { + cout << termcolor::bright_magenta << match.text + << termcolor::reset; + } + else + { + cout << match.text; + } + cout << match.context.second << '\n'; } } catch (const std::exception &e) diff --git a/src/options.cpp b/src/options.cpp index fad0942..849acd0 100644 --- a/src/options.cpp +++ b/src/options.cpp @@ -70,7 +70,9 @@ po::variables_map parse_options(int argc, char *argv[]) translate("Do not clean up text before searching.").str().data()) ("context,C", po::value() ->value_name(translate("NUMBER"))->default_value(0), - translate("Print NUMBER words of context around matches.").str().data()) + translate("Print NUMBER words of context around matches.") + .str().data()) + ("nocolor", translate("Do not color matches.") .str().data()) ; po::options_description options_hidden("Hidden options");