Add a progress bar.
authorCarl Hetherington <cth@carlh.net>
Tue, 11 Oct 2022 20:43:32 +0000 (22:43 +0200)
committerCarl Hetherington <cth@carlh.net>
Tue, 11 Oct 2022 20:43:32 +0000 (22:43 +0200)
tools/dcpverify.cc

index 4d670b8e3544d94c6dbc7284aaa75ff5ad246019..1eb0da2a7acda4ca6ff598a28ad809868ac6aec3 100644 (file)
@@ -128,7 +128,25 @@ main (int argc, char* argv[])
                }
        };
 
-       auto progress = [](float) {};
+       auto progress = [quiet](float amount) {
+               if (quiet) {
+                       return;
+               }
+               int const width = 60;
+               int const index = std::rint(amount * width);
+               cout << "[";
+               for (int i = 0; i < width; ++i) {
+                       if (i < index) {
+                               std::cout << "=";
+                       } else if (i == index) {
+                               std::cout << ">";
+                       } else {
+                               std::cout << " ";
+                       }
+               }
+               cout << "] " << std::rint(amount * 100) << "%\r";
+               cout.flush();
+       };
 
        vector<boost::filesystem::path> directories;
        directories.push_back (argv[optind]);