diff --git a/man/epubgrep.1.adoc b/man/epubgrep.1.adoc index c07fb31..2ca3fd3 100644 --- a/man/epubgrep.1.adoc +++ b/man/epubgrep.1.adoc @@ -2,7 +2,7 @@ :doctype: manpage :Author: tastytea :Email: tastytea@tastytea.de -:Date: 2021-05-29 +:Date: 2021-05-30 :Revision: 0.0.0 :man source: epubgrep :man manual: General Commands Manual @@ -57,7 +57,7 @@ all files will be read (not just the text documents listed in the spine). Print _NUMBER_ words of context around matches. *--nocolor*:: -Do not color matches. +Turn off colors and other decorations. *--no-filename* _WHICH_:: diff --git a/src/options.cpp b/src/options.cpp index 1670631..4527c8b 100644 --- a/src/options.cpp +++ b/src/options.cpp @@ -74,7 +74,8 @@ options parse_options(int argc, char *argv[]) ->value_name(translate("NUMBER"))->default_value(0), translate("Print NUMBER words of context around matches.") .str().data()) - ("nocolor", translate("Do not color matches.") .str().data()) + ("nocolor", translate("Turn off colors and other decorations.") + .str().data()) ("no-filename",po::value()->value_name(translate("WHICH")), translate("Suppress the mentioning of file names on output. " "WHICH is ‘filesystem’, ‘in-epub’ or ‘all’.").str().data()) diff --git a/src/output.cpp b/src/output.cpp index eec740f..e2c14f6 100644 --- a/src/output.cpp +++ b/src/output.cpp @@ -22,6 +22,7 @@ #include #include +#include namespace epubgrep::output { @@ -61,12 +62,27 @@ void print_matches(const std::vector &matches, } if (!match.headline.empty()) { - metadata.emplace_back(match.headline); + // + if (!opts.nocolor && termcolor::_internal::is_colorized(cout)) + { + std::stringstream ss; + ss << termcolor::colorize << termcolor::underline + << match.headline << termcolor::reset << termcolor::italic; + metadata.emplace_back(ss.str()); + } + else + { + metadata.emplace_back(match.headline); + } } if (!match.page.empty()) { metadata.emplace_back("page " + match.page); } + if (!opts.nocolor) + { + cout << termcolor::italic; + } for (const auto &part : metadata) { cout << part; @@ -75,7 +91,12 @@ void print_matches(const std::vector &matches, cout << ", "; } } - cout << ": " << match.context.first; + cout << ": "; + if (!opts.nocolor) + { + cout << termcolor::reset; + } + cout << match.context.first; if (!opts.nocolor) { cout << termcolor::bright_magenta;