From 18c3d8f58d36a4a7e6c56c2f4d598d685562acea Mon Sep 17 00:00:00 2001 From: tastytea Date: Thu, 24 Jun 2021 12:53:09 +0200 Subject: [PATCH] Do not show prefix in output if there is no metadata. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Previously epubgrep would output “: match” instead of “match”. Closes: https://schlomp.space/tastytea/epubgrep/issues/15 --- src/output.cpp | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/src/output.cpp b/src/output.cpp index 19bd72f..df3724d 100644 --- a/src/output.cpp +++ b/src/output.cpp @@ -78,22 +78,25 @@ void print_matches(const std::vector &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)