@@ -12,6 +12,7 @@ static_assert(__cplusplus >= 201703L,
1212// std
1313#include < iostream>
1414#include < limits>
15+ #include < sstream>
1516#include < string>
1617#include < vector>
1718
@@ -78,6 +79,7 @@ usage()
7879 << " -makeresultsfile (true)| false makes a results file\n "
7980 << " -outputname name sets the results file name to \" name\" "
8081 " (default results.txt)\n "
82+ << " -progress true |(false) output progress information"
8183 << " -deleteduplicates true |(false) delete duplicate files\n "
8284 << " -sleep Xms sleep for X milliseconds between "
8385 " file reads.\n "
@@ -115,6 +117,7 @@ struct Options
115117 bool usesha512 = false ; // use sha512 checksum to check for similarity
116118 bool usexxh128 = false ; // use xxh128 checksum to check for similarity
117119 bool deterministic = true ; // be independent of filesystem order
120+ bool showprogress = false ; // show progress while reading file contents
118121 std::size_t buffersize = 1 << 20 ; // chunksize to use when reading files
119122 long nsecsleep = 0 ; // number of nanoseconds to sleep between each file read.
120123 std::string resultsfile = " results.txt" ; // results file name.
@@ -237,6 +240,8 @@ parseOptions(Parser& parser)
237240 << nextarg << " \" is not among them.\n " ;
238241 std::exit (EXIT_FAILURE);
239242 }
243+ } else if (parser.try_parse_bool (" -progress" )) {
244+ o.showprogress = parser.get_parsed_bool ();
240245 } else if (parser.current_arg_is (" -help" ) || parser.current_arg_is (" -h" ) ||
241246 parser.current_arg_is (" --help" )) {
242247 usage ();
@@ -409,12 +414,28 @@ main(int narg, const char* argv[])
409414 " xxh128 checksum" );
410415 }
411416
417+ std::function<void (std::size_t )> progress_callback;
418+ if (o.showprogress ) {
419+ progress_callback = []() {
420+ // format the total count only once, not each iteration.
421+ std::ostringstream oss;
422+ oss << " /" << filelist.size () << " )"
423+ << " \033 [u" ; // Restore the cursor to the saved position;
424+ return [suffix = oss.str ()](std::size_t completed) {
425+ std::cout
426+ << " \033 [s\033 [K" // Save the cursor position & clear following text
427+ << " (" << completed << suffix << std::flush;
428+ };
429+ }();
430+ }
431+
412432 for (auto it = modes.begin () + 1 ; it != modes.end (); ++it) {
413433 std::cout << dryruntext << " Now eliminating candidates based on "
414434 << it->second << " : " << std::flush;
415435
416436 // read bytes (destroys the sorting, for disk reading efficiency)
417- gswd.fillwithbytes (it[0 ].first , it[-1 ].first , o.nsecsleep , o.buffersize );
437+ gswd.fillwithbytes (
438+ it[0 ].first , it[-1 ].first , o.nsecsleep , o.buffersize , progress_callback);
418439
419440 // remove non-duplicates
420441 std::cout << " removed " << gswd.removeUniqSizeAndBuffer ()
0 commit comments