textProgressBar
Loading...
Searching...
No Matches
TextProgressBar Class Reference

Renders an ASCII progress bar to standard output. More...

#include <textProgressBar.h>

Public Member Functions

 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.
 

Detailed Description

TextProgressBar prints a single-line progress indicator (title + bar + percentage) to the console. Updates overwrite the same line via carriage return (\r). When the progress reaches the final step, the progress bar ends with a newline.

Note
Output is produced to std::cout by the implementation.
Typical usage
TextProgressBar bar(30, " processing: ", 0, 100);
for (int i = 0; i <= 100; i++) {
bar.setProgress(i);
}
Renders an ASCII progress bar to standard output.
Update throttling
The progress bar is intentionally throttled: it only prints when the input value advances by at least one internal step. The internal step size is derived from the configured [min, max] range and the module constant TEXTPROGRESSBARNSTEPS.

Definition at line 32 of file textProgressBar.h.

Constructor & Destructor Documentation

◆ TextProgressBar()

TextProgressBar::TextProgressBar ( int w,
string t,
int minimum = 0,
int maximum = 100,
char s = '[',
char e = ']',
char m = '=',
char a = '>' )
inline

The progress bar represents values in the inclusive range [minimum, maximum]. The output is throttled to at most TEXTPROGRESSBARNSTEPS printed updates across the full range.

Parameters
wThe visual width of the bar (number of character cells between the delimiters).
tThe title/prefix printed before the bar (e.g. " processing: ").
minimumThe minimum progress value (start of the range).
maximumThe maximum progress value (end of the range).
sThe character used to open the bar (default: ‘’['). \param e The character used to close the bar (default:']'). \param m The character used to fill completed portions of the bar (default:'='). \param a The character used to indicate the current advancing position (default:'>'`).
Note
If the range is too small to compute a meaningful step size, updates may be suppressed (see TextProgressBar::setProgress "setProgress()").

Definition at line 53 of file textProgressBar.h.

Member Function Documentation

◆ setProgress()

void TextProgressBar::setProgress ( int p)

The progress bar prints only when the provided value reaches or exceeds the next internal threshold (tracked by indexStep). This prevents excessive console output in tight loops.

Updates are ignored in the following cases:

  • The provided value is less than the next threshold (p < indexStep).
  • The bar's internal step size is zero (singleStep == 0), meaning the range is too small for throttled printing.
  • The provided value is outside the configured range (p < min or p > max).
Parameters
pCurrent progress value (typically a loop index or processed item count).

Definition at line 8 of file textProgressBar.cc.


The documentation for this class was generated from the following files: