Do not show prefix in output if there is no metadata.

Previously epubgrep would output “: match” instead of “match”.

Closes: #15
This commit is contained in:
tastytea 2021-06-24 12:53:09 +02:00
parent b2a6f9217b
commit 18c3d8f58d
Signed by: tastytea
GPG Key ID: CFC39497F1B26E07
1 changed files with 16 additions and 13 deletions

View File

@ -78,22 +78,25 @@ void print_matches(const std::vector<search::match> &matches,
{
metadata.emplace_back("page " + match.page);
}
if (!opts.nocolor)
if (!metadata.empty())
{
cout << termcolor::italic;
}
for (const auto &part : metadata)
{
cout << part;
if (part != *(metadata.rbegin()))
if (!opts.nocolor)
{
cout << ", ";
cout << termcolor::italic;
}
for (const auto &part : metadata)
{
cout << part;
if (part != *(metadata.rbegin()))
{
cout << ", ";
}
}
cout << ": ";
if (!opts.nocolor)
{
cout << termcolor::reset;
}
}
cout << ": ";
if (!opts.nocolor)
{
cout << termcolor::reset;
}
cout << match.context.first;
if (!opts.nocolor)