textProgressBar
Loading...
Searching...
No Matches
textProgressBar.h
Go to the documentation of this file.
1#pragma once
2
4
5// c++
6#include <string>
7using std::string;
8
33{
34public:
53 TextProgressBar(int w, string t, int minimum = 0, int maximum = 100, char s = '[', char e = ']', char m = '=',
54 char a = '>') :
55 barWidth(w), title(t), min(minimum), max(maximum), startBarChar(s), endBarChar(e), middleBarChar(m),
56 advanceBarChar(a) {
57 // Determine the internal update granularity so we print at most textProgressBar::TEXTPROGRESSBARNSTEPS
58 // updates. If the range is too small, "singleStep" becomes 0 and updates will be suppressed.
59 if (maximum - minimum > textProgressBar::TEXTPROGRESSBARNSTEPS) {
60 singleStep = (maximum - minimum) / textProgressBar::TEXTPROGRESSBARNSTEPS;
61 }
62 else {
63 singleStep = 0;
64 }
65
66 // The next progress threshold at which we will print an update.
67 indexStep = minimum;
68 }
69
84 void setProgress(int p);
85
86private:
88 int barWidth;
89
91 string title;
92
94 int min, max;
95
97 char startBarChar, endBarChar;
98
100 char middleBarChar, advanceBarChar;
101
103 int singleStep;
104
106 int indexStep;
107};
TextProgressBar(int w, string t, int minimum=0, int maximum=100, char s='[', char e=']', char m='=', char a='>')
Constructs a progress bar with a value range and visual configuration.
void setProgress(int p)
Updates the progress bar based on the provided progress value.
constexpr int TEXTPROGRESSBARNSTEPS
Number of discrete progress bar steps used for throttled printing.