mirror of
https://github.com/openmc-dev/openmc.git
synced 2026-07-26 05:05:30 -04:00
Implementation of progress bar.
This commit is contained in:
parent
e09a78dabd
commit
6014310f01
5 changed files with 80 additions and 1 deletions
52
src/progress_bar.cpp
Normal file
52
src/progress_bar.cpp
Normal 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 = ""; //???% | |";
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue