9 Commits
v1.4 ... v1.5

Author SHA1 Message Date
Pranav Srinivas Kumar
e697a43fec Clang format 2019-12-18 12:47:10 -06:00
Pranav Srinivas Kumar
358e3763c3 Minor update 2019-12-18 12:46:08 -06:00
Pranav Srinivas Kumar
419737af61 Merge branch 'feature/multiprogress_api' 2019-12-18 11:59:33 -06:00
Pranav Srinivas Kumar
9786633eba Bumped version 2019-12-18 11:59:20 -06:00
Pranav Srinivas Kumar
502ce33af4 Updated README w/ new MultiProgress API 2019-12-18 11:57:50 -06:00
Pranav Srinivas Kumar
8190a1e513 Minor update 2019-12-18 11:57:07 -06:00
Pranav Srinivas Kumar
72644e5134 Setting multiprogress mode in MultiProgress constructor 2019-12-18 11:55:56 -06:00
Pranav Srinivas Kumar
222a8ae4f9 Added explicit constructor for MultiProgress to remove insert API 2019-12-18 11:51:58 -06:00
Pranav Srinivas Kumar
2694badc93 Added locking to .current() 2019-12-18 07:55:22 -06:00
8 changed files with 33 additions and 31 deletions

View File

@@ -9,7 +9,7 @@
<a href="https://github.com/p-ranav/indicators/blob/master/LICENSE">
<img src="https://img.shields.io/badge/License-MIT-yellow.svg" alt="license"/>
</a>
<img src="https://img.shields.io/badge/version-1.4-blue.svg?cacheSeconds=2592000" alt="version"/>
<img src="https://img.shields.io/badge/version-1.5-blue.svg?cacheSeconds=2592000" alt="version"/>
</p>
<p align="center">
@@ -239,7 +239,7 @@ int main() {
# MultiProgress
`indicators` supports management of multiple progress bars with the `MultiProgress` class.
`indicators` supports management of multiple progress bars with the `MultiProgress` class template.
`template <typename Indicator, size_t count> class MultiProgress` is a class template that holds references to multiple progress bars and provides a safe interface to update the state of each bar. `MultiProgress` works with both `ProgressBar` and `BlockProgressBar` classes.
@@ -295,10 +295,7 @@ int main() {
bar3.set_prefix_text("Progress Bar #3 ");
// Construct MultiProgress object
indicators::MultiProgress<indicators::ProgressBar, 3> bars;
bars.insert<0>(bar1);
bars.insert<1>(bar2);
bars.insert<2>(bar3);
indicators::MultiProgress<indicators::ProgressBar, 3> bars(bar1, bar2, bar3);
std::cout << "Multiple Progress Bars:\n";

View File

@@ -104,7 +104,10 @@ public:
_print_progress();
}
size_t current() { return std::min(static_cast<size_t>(_progress), size_t(100)); }
size_t current() {
std::unique_lock<std::mutex> lock{_mutex};
return std::min(static_cast<size_t>(_progress), size_t(100));
}
bool is_completed() const { return _completed; }

View File

@@ -36,29 +36,31 @@ namespace indicators {
template <typename Indicator, size_t count> class MultiProgress {
public:
MultiProgress() { _bars.reserve(count); }
template <size_t index>
typename std::enable_if<(index < count), void>::type insert(Indicator &bar) {
_bars.insert(_bars.begin() + index, 1, bar);
bar._multi_progress_mode = true;
template <typename... Indicators,
typename = typename std::enable_if<(sizeof...(Indicators) == count)>::type>
explicit MultiProgress(Indicators &... bars) {
_bars = {bars...};
for (auto &bar : _bars) {
bar.get()._multi_progress_mode = true;
}
}
template <size_t index>
typename std::enable_if<(index < count), void>::type set_progress(float value) {
typename std::enable_if<(index >= 0 && index < count), void>::type set_progress(float value) {
if (!_bars[index].get().is_completed())
_bars[index].get().set_progress(value);
_print_progress();
}
template <size_t index> typename std::enable_if<(index < count), void>::type tick() {
template <size_t index>
typename std::enable_if<(index >= 0 && index < count), void>::type tick() {
if (!_bars[index].get().is_completed())
_bars[index].get().tick();
_print_progress();
}
template <size_t index>
typename std::enable_if<(index < count), bool>::type is_completed() const {
typename std::enable_if<(index >= 0 && index < count), bool>::type is_completed() const {
return _bars[index].get().is_completed();
}

View File

@@ -118,7 +118,10 @@ public:
_print_progress();
}
size_t current() { return std::min(static_cast<size_t>(_progress), size_t(100)); }
size_t current() {
std::unique_lock<std::mutex> lock{_mutex};
return std::min(static_cast<size_t>(_progress), size_t(100));
}
bool is_completed() const { return _completed; }

View File

@@ -93,7 +93,10 @@ public:
_print_progress();
}
size_t current() { return std::min(static_cast<size_t>(_progress), size_t(100)); }
size_t current() {
std::unique_lock<std::mutex> lock{_mutex};
return std::min(static_cast<size_t>(_progress), size_t(100));
}
bool is_completed() const { return _completed; }

View File

@@ -24,10 +24,7 @@ int main() {
bar3.show_remaining_time();
bar3.set_prefix_text("Progress Bar #3 ");
indicators::MultiProgress<indicators::BlockProgressBar, 3> bars;
bars.insert<0>(bar1);
bars.insert<1>(bar2);
bars.insert<2>(bar3);
indicators::MultiProgress<indicators::BlockProgressBar, 3> bars(bar1, bar2, bar3);
std::cout << "Multiple Progress Bars:\n";

View File

@@ -39,10 +39,7 @@ int main() {
bar3.show_remaining_time();
bar3.set_prefix_text("Progress Bar #3 ");
indicators::MultiProgress<indicators::ProgressBar, 3> bars;
bars.insert<0>(bar1);
bars.insert<1>(bar2);
bars.insert<2>(bar3);
indicators::MultiProgress<indicators::ProgressBar, 3> bars(bar1, bar2, bar3);
std::cout << "Multiple Progress Bars:\n";

View File

@@ -13,10 +13,10 @@ int main() {
bar.set_bar_width(50);
bar.start_bar_with("[");
bar.fill_bar_progress_with("");
bar.lead_bar_progress_with("");
bar.lead_bar_progress_with("");
bar.fill_bar_remainder_with("-");
bar.end_bar_with(" ]");
bar.set_postfix_text("Loading dependency 1/4");
bar.set_postfix_text("Loading dependency 1/4");
bar.set_foreground_color(indicators::Color::CYAN);
// Update bar state
@@ -25,14 +25,14 @@ int main() {
// do some work
std::this_thread::sleep_for(std::chrono::milliseconds(800));
bar.set_postfix_text("Loading dependency 2/4");
bar.set_postfix_text("Loading dependency 2/4");
bar.set_progress(30); // 30% done
// do some more work
std::this_thread::sleep_for(std::chrono::milliseconds(700));
bar.set_postfix_text("Loading dependency 3/4");
bar.set_postfix_text("Loading dependency 3/4");
bar.set_progress(65); // 65% done
@@ -46,7 +46,7 @@ int main() {
bar.mark_as_completed();
// Show cursor
std::cout << "\e[?25h";
std::cout << "\e[?25h";
return 0;
}