From 46b7119fab32b05923dbf9cda7cd6ce62f572846 Mon Sep 17 00:00:00 2001 From: Kelly Rauchenberger Date: Mon, 9 Jan 2017 14:01:51 -0500 Subject: Initial commit --- generator/progress.h | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 generator/progress.h (limited to 'generator/progress.h') diff --git a/generator/progress.h b/generator/progress.h new file mode 100644 index 0000000..f42f701 --- /dev/null +++ b/generator/progress.h @@ -0,0 +1,56 @@ +#ifndef PROGRESS_H_A34EF856 +#define PROGRESS_H_A34EF856 + +#include + +namespace cadence { + namespace generator { + + class progress { + private: + std::string message; + int total; + int cur = 0; + int lprint = 0; + + public: + progress(std::string message, int total) : message(message), total(total) + { + std::cout << message << " 0%" << std::flush; + } + + void update(int val) + { + if (val <= total) + { + cur = val; + } else { + cur = total; + } + + int pp = cur * 100 / total; + if (pp != lprint) + { + lprint = pp; + + std::cout << "\b\b\b\b" << std::right; + std::cout.width(3); + std::cout << pp << "%" << std::flush; + } + } + + void update() + { + update(cur+1); + } + + ~progress() + { + std::cout << "\b\b\b\b100%" << std::endl; + } + }; + + }; +}; + +#endif /* end of include guard: PROGRESS_H_A34EF856 */ -- cgit 1.4.1