Output metadata italic, chapters underlined.

This commit is contained in:
tastytea 2021-05-30 19:03:59 +02:00
parent fe23fcf04b
commit 22cae4c3cd
Signed by: tastytea
GPG Key ID: CFC39497F1B26E07
3 changed files with 27 additions and 5 deletions

View File

@ -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_::

View File

@ -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<std::string>()->value_name(translate("WHICH")),
translate("Suppress the mentioning of file names on output. "
"WHICH is filesystem, in-epub or all.").str().data())

View File

@ -22,6 +22,7 @@
#include <termcolor/termcolor.hpp>
#include <iostream>
#include <sstream>
namespace epubgrep::output
{
@ -61,12 +62,27 @@ void print_matches(const std::vector<search::match> &matches,
}
if (!match.headline.empty())
{
metadata.emplace_back(match.headline);
// <https://github.com/ikalnytskyi/termcolor/issues/45>
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<search::match> &matches,
cout << ", ";
}
}
cout << ": " << match.context.first;
cout << ": ";
if (!opts.nocolor)
{
cout << termcolor::reset;
}
cout << match.context.first;
if (!opts.nocolor)
{
cout << termcolor::bright_magenta;