Print the EPUB file name if more than 1 input file.
Change --no-filename to mean: Don't print the EPUB file name.
This commit is contained in:
parent
0c45e7ac98
commit
c376ce8466
|
@ -59,8 +59,9 @@ Print _NUMBER_ words of context around matches.
|
||||||
Do not color matches.
|
Do not color matches.
|
||||||
|
|
||||||
*--no-filename*::
|
*--no-filename*::
|
||||||
Suppress the mentioning of file names on output. Chapters and page numbers will
|
Suppress the mentioning of EPUB file names on output. File names inside the
|
||||||
still be output.
|
EPUB, chapters and page numbers will still be output.
|
||||||
|
|
||||||
*-r*, *--recursive*:
|
*-r*, *--recursive*:
|
||||||
Read all files under each directory, recursively, following symbolic links only
|
Read all files under each directory, recursively, following symbolic links only
|
||||||
if they are on the command line. Silently skips directories that are not
|
if they are on the command line. Silently skips directories that are not
|
||||||
|
|
27
src/main.cpp
27
src/main.cpp
|
@ -228,19 +228,32 @@ int main(int argc, char *argv[])
|
||||||
|
|
||||||
for (const auto &matches_file : matches_all)
|
for (const auto &matches_file : matches_all)
|
||||||
{
|
{
|
||||||
|
fs::path last_epub;
|
||||||
for (const auto &match : matches_file)
|
for (const auto &match : matches_file)
|
||||||
{
|
{
|
||||||
if (vm.count("no-filename") == 0)
|
if (input_files.size() <= 1 || vm.count("no-filename") == 0)
|
||||||
{
|
{
|
||||||
cout << match.filepath;
|
if (match.epub_filepath != last_epub)
|
||||||
|
{
|
||||||
|
if (vm.count("nocolor") == 0)
|
||||||
|
{
|
||||||
|
cout << termcolor::yellow;
|
||||||
|
}
|
||||||
|
|
||||||
|
cout << format(translate(" In {0:s}: \n").str().data(),
|
||||||
|
fs::relative(match.epub_filepath));
|
||||||
|
last_epub = match.epub_filepath;
|
||||||
|
|
||||||
|
if (vm.count("nocolor") == 0)
|
||||||
|
{
|
||||||
|
cout << termcolor::reset;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
cout << match.filepath;
|
||||||
if (!match.headline.empty())
|
if (!match.headline.empty())
|
||||||
{
|
{
|
||||||
if (vm.count("no-filename") == 0)
|
cout << ", " << match.headline;
|
||||||
{
|
|
||||||
cout << ", ";
|
|
||||||
}
|
|
||||||
cout << match.headline;
|
|
||||||
}
|
}
|
||||||
if (!match.page.empty())
|
if (!match.page.empty())
|
||||||
{
|
{
|
||||||
|
|
|
@ -74,7 +74,7 @@ po::variables_map parse_options(int argc, char *argv[])
|
||||||
.str().data())
|
.str().data())
|
||||||
("nocolor", translate("Do not color matches.") .str().data())
|
("nocolor", translate("Do not color matches.") .str().data())
|
||||||
("no-filename",
|
("no-filename",
|
||||||
translate("Suppress the mentioning of file names on output.")
|
translate("Suppress the mentioning of EPUB file names on output.")
|
||||||
.str().data())
|
.str().data())
|
||||||
("recursive,r",
|
("recursive,r",
|
||||||
translate("Read all files under each directory, recursively.")
|
translate("Read all files under each directory, recursively.")
|
||||||
|
|
|
@ -80,6 +80,7 @@ std::vector<match> search(const fs::path &filepath, std::string_view regex,
|
||||||
boost::match_default))
|
boost::match_default))
|
||||||
{
|
{
|
||||||
match match; // FIXME: Rename variable or struct.
|
match match; // FIXME: Rename variable or struct.
|
||||||
|
match.epub_filepath = filepath;
|
||||||
match.filepath = entry;
|
match.filepath = entry;
|
||||||
match.text = match_result[0];
|
match.text = match_result[0];
|
||||||
match.context = context(match_result, opts.context);
|
match.context = context(match_result, opts.context);
|
||||||
|
|
|
@ -34,11 +34,12 @@ using match_context = std::pair<std::string, std::string>;
|
||||||
|
|
||||||
struct match
|
struct match
|
||||||
{
|
{
|
||||||
std::string text; //!< Matched string.
|
fs::path epub_filepath; //!< File path of the EPUB.
|
||||||
match_context context; //!< The context around the match.
|
std::string text; //!< Matched string.
|
||||||
std::string filepath; //!< The file path of the matched line.
|
match_context context; //!< The context around the match.
|
||||||
std::string headline; //!< The last headline, if available.
|
std::string filepath; //!< The file path of the matched line.
|
||||||
std::string page; //!< The page number, if available.
|
std::string headline; //!< The last headline, if available.
|
||||||
|
std::string page; //!< The page number, if available.
|
||||||
};
|
};
|
||||||
|
|
||||||
enum class regex_kind
|
enum class regex_kind
|
||||||
|
|
Loading…
Reference in New Issue
Block a user