Implementation of progress bar.

This commit is contained in:
Patrick Shriwise 2018-10-29 18:02:00 -05:00
parent e09a78dabd
commit 6014310f01
5 changed files with 80 additions and 1 deletions

52
src/progress_bar.cpp Normal file
View file

@ -0,0 +1,52 @@
#include "openmc/progress_bar.h"
#include <sstream>
#include <iostream>
#include <iomanip>
#define BAR_WIDTH 72
ProgressBar::ProgressBar() {
// bar = "???% | |";
set_value(0.0);
}
void
ProgressBar::set_value(double val) {
// set the bar percentage
if (val >= 100.0) {
bar.append("100");
} else if (val <= 0.0) {
bar.append(" 0");
} else {
std::stringstream ss;
ss << std::setfill(' ') << std::setw(3) << (int)val;
bar.append(ss.str());
}
bar.append("% |");
// remaining width of the bar
int remain = BAR_WIDTH - bar.size() - 1;
// set the bar width
if (val >= 100.0) {
bar.append(remain, '=');
} else {
int width = (int)(65*val/100);
std::cout << "Setting width: " << width;
bar.append(width, '=');
bar.append(1, '>');
bar.append(remain-width-1, ' ');
}
bar.append("|");
// write the bar
std::cout << '\r' << bar << std::flush;
// reset the bar value
bar = ""; //???% | |";
}