8#ifndef RUSH_PROGRESS_BAR_HPP
9#define RUSH_PROGRESS_BAR_HPP
20namespace rush::progress {
41 double update(
double p) {
42 p = std::clamp(p, 0.0, 1.0);
44 std::string s = std::string(
"\033[0m") + config_.
name;
45 if(!config_.
name.empty()) {
54 s +=
" " + std::to_string(p * 100).substr(0, std::to_string(p * 100).find(
'.') + (config_.
decimals > 0) + config_.
decimals) +
"%";
57 std::cout <<
"\u001b[1000D\033[31m\033[41m" << s << std::flush;
69 ioctl(STDOUT_FILENO, TIOCGWINSZ, &w);
85 return update((current_ = x) / max_);
93 return update(++current_ / max_);
101 return update(++current_ / max_);
110 return update((current_ += n) / max_);
118 return update(--current_ / max_);
126 return update(--current_ / max_);
135 return update((current_ -= n) / max_);
Definition progress-bar.hpp:34
double operator++(int)
Increment the progress bar by 1 (postfix).
Definition progress-bar.hpp:100
Bar(const double max, Configuration cfg=Configuration())
Construct a new Bar object.
Definition progress-bar.hpp:67
double operator-=(const int n)
Decrement the progress bar by a specified value.
Definition progress-bar.hpp:134
double operator+=(const int n)
Increment the progress bar by a specified value.
Definition progress-bar.hpp:109
double operator++()
Increment the progress bar by 1.
Definition progress-bar.hpp:92
double operator()(const double x)
Update the progress bar with a specific value.
Definition progress-bar.hpp:84
double operator--(int)
Decrement the progress bar by 1 (postfix).
Definition progress-bar.hpp:125
double operator--()
Decrement the progress bar by 1.
Definition progress-bar.hpp:117
This class extends std::string.
Definition string.hpp:22
This library provides string-related utilities.
Configuration structure for the progress bar.
Definition progress-bar.hpp:25
std::string uncomplete
Character used to represent uncompleted progress.
Definition progress-bar.hpp:28
std::string name
Name displayed alongside the progress bar.
Definition progress-bar.hpp:26
std::string complete
Character used to represent completed progress.
Definition progress-bar.hpp:27
bool percentage
Flag indicating whether to display percentage completion.
Definition progress-bar.hpp:30
std::array< std::string, 2 > decorator
Decorator strings surrounding the progress bar.
Definition progress-bar.hpp:29
double decimals
Number of decimal places for the percentage display.
Definition progress-bar.hpp:31