2014-08-05 16:17:57 +05:30
|
|
|
#include "base/progress_monitor.h"
|
|
|
|
|
|
|
|
#include <iostream>
|
|
|
|
|
|
|
|
//----------------------------------------------------------------
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
using namespace std;
|
|
|
|
|
|
|
|
class progress_bar : public base::progress_monitor {
|
|
|
|
public:
|
|
|
|
progress_bar(string const &title)
|
|
|
|
: title_(title),
|
|
|
|
progress_width_(50),
|
|
|
|
spinner_(0) {
|
|
|
|
|
|
|
|
update_percent(0);
|
|
|
|
}
|
2014-09-01 19:14:37 +05:30
|
|
|
~progress_bar() {
|
|
|
|
cout << "\n";
|
|
|
|
}
|
2014-08-05 16:17:57 +05:30
|
|
|
|
|
|
|
void update_percent(unsigned p) {
|
|
|
|
unsigned nr_equals = max<unsigned>(progress_width_ * p / 100, 1);
|
|
|
|
unsigned nr_spaces = progress_width_ - nr_equals;
|
|
|
|
|
|
|
|
cout << title_ << ": [";
|
|
|
|
|
|
|
|
for (unsigned i = 0; i < nr_equals - 1; i++)
|
|
|
|
cout << '=';
|
|
|
|
|
|
|
|
if (nr_equals < progress_width_)
|
|
|
|
cout << '>';
|
2015-08-20 15:42:53 +05:30
|
|
|
else
|
|
|
|
cout << "=";
|
2014-08-05 16:17:57 +05:30
|
|
|
|
|
|
|
for (unsigned i = 0; i < nr_spaces; i++)
|
|
|
|
cout << ' ';
|
|
|
|
|
2015-08-20 15:42:53 +05:30
|
|
|
cout << "] " << spinner_char(p) << " " << p << "%\r" << flush;
|
2014-08-05 16:17:57 +05:30
|
|
|
|
|
|
|
spinner_++;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2015-08-20 15:42:53 +05:30
|
|
|
char spinner_char(unsigned p) const {
|
|
|
|
if (p == 100)
|
|
|
|
return ' ';
|
|
|
|
|
2014-08-05 16:17:57 +05:30
|
|
|
char cs[] = {'|', '/', '-', '\\'};
|
|
|
|
|
|
|
|
unsigned index = spinner_ % sizeof(cs);
|
|
|
|
return cs[index];
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string title_;
|
|
|
|
unsigned progress_width_;
|
|
|
|
unsigned spinner_;
|
|
|
|
};
|
|
|
|
|
|
|
|
class quiet_progress : public base::progress_monitor {
|
|
|
|
public:
|
|
|
|
void update_percent(unsigned p) {
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------
|
|
|
|
|
2016-02-04 14:32:42 +05:30
|
|
|
std::unique_ptr<base::progress_monitor>
|
2014-08-05 16:17:57 +05:30
|
|
|
base::create_progress_bar(std::string const &title)
|
|
|
|
{
|
2016-02-04 14:32:42 +05:30
|
|
|
return unique_ptr<progress_monitor>(new progress_bar(title));
|
2014-08-05 16:17:57 +05:30
|
|
|
}
|
|
|
|
|
2016-02-04 14:32:42 +05:30
|
|
|
std::unique_ptr<base::progress_monitor>
|
2014-08-05 16:17:57 +05:30
|
|
|
base::create_quiet_progress_monitor()
|
|
|
|
{
|
2016-02-04 14:32:42 +05:30
|
|
|
return unique_ptr<progress_monitor>(new quiet_progress());
|
2014-08-05 16:17:57 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------
|