mirror of
https://github.com/p-ranav/indicators.git
synced 2025-12-16 04:18:51 +08:00
Compare commits
9 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e697a43fec | ||
|
|
358e3763c3 | ||
|
|
419737af61 | ||
|
|
9786633eba | ||
|
|
502ce33af4 | ||
|
|
8190a1e513 | ||
|
|
72644e5134 | ||
|
|
222a8ae4f9 | ||
|
|
2694badc93 |
@@ -9,7 +9,7 @@
|
|||||||
<a href="https://github.com/p-ranav/indicators/blob/master/LICENSE">
|
<a href="https://github.com/p-ranav/indicators/blob/master/LICENSE">
|
||||||
<img src="https://img.shields.io/badge/License-MIT-yellow.svg" alt="license"/>
|
<img src="https://img.shields.io/badge/License-MIT-yellow.svg" alt="license"/>
|
||||||
</a>
|
</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>
|
||||||
|
|
||||||
<p align="center">
|
<p align="center">
|
||||||
@@ -239,7 +239,7 @@ int main() {
|
|||||||
|
|
||||||
# MultiProgress
|
# 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.
|
`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 ");
|
bar3.set_prefix_text("Progress Bar #3 ");
|
||||||
|
|
||||||
// Construct MultiProgress object
|
// Construct MultiProgress object
|
||||||
indicators::MultiProgress<indicators::ProgressBar, 3> bars;
|
indicators::MultiProgress<indicators::ProgressBar, 3> bars(bar1, bar2, bar3);
|
||||||
bars.insert<0>(bar1);
|
|
||||||
bars.insert<1>(bar2);
|
|
||||||
bars.insert<2>(bar3);
|
|
||||||
|
|
||||||
std::cout << "Multiple Progress Bars:\n";
|
std::cout << "Multiple Progress Bars:\n";
|
||||||
|
|
||||||
|
|||||||
@@ -104,7 +104,10 @@ public:
|
|||||||
_print_progress();
|
_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; }
|
bool is_completed() const { return _completed; }
|
||||||
|
|
||||||
|
|||||||
@@ -36,29 +36,31 @@ namespace indicators {
|
|||||||
|
|
||||||
template <typename Indicator, size_t count> class MultiProgress {
|
template <typename Indicator, size_t count> class MultiProgress {
|
||||||
public:
|
public:
|
||||||
MultiProgress() { _bars.reserve(count); }
|
template <typename... Indicators,
|
||||||
|
typename = typename std::enable_if<(sizeof...(Indicators) == count)>::type>
|
||||||
template <size_t index>
|
explicit MultiProgress(Indicators &... bars) {
|
||||||
typename std::enable_if<(index < count), void>::type insert(Indicator &bar) {
|
_bars = {bars...};
|
||||||
_bars.insert(_bars.begin() + index, 1, bar);
|
for (auto &bar : _bars) {
|
||||||
bar._multi_progress_mode = true;
|
bar.get()._multi_progress_mode = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
template <size_t index>
|
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())
|
if (!_bars[index].get().is_completed())
|
||||||
_bars[index].get().set_progress(value);
|
_bars[index].get().set_progress(value);
|
||||||
_print_progress();
|
_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())
|
if (!_bars[index].get().is_completed())
|
||||||
_bars[index].get().tick();
|
_bars[index].get().tick();
|
||||||
_print_progress();
|
_print_progress();
|
||||||
}
|
}
|
||||||
|
|
||||||
template <size_t index>
|
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();
|
return _bars[index].get().is_completed();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -118,7 +118,10 @@ public:
|
|||||||
_print_progress();
|
_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; }
|
bool is_completed() const { return _completed; }
|
||||||
|
|
||||||
|
|||||||
@@ -93,7 +93,10 @@ public:
|
|||||||
_print_progress();
|
_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; }
|
bool is_completed() const { return _completed; }
|
||||||
|
|
||||||
|
|||||||
@@ -24,10 +24,7 @@ int main() {
|
|||||||
bar3.show_remaining_time();
|
bar3.show_remaining_time();
|
||||||
bar3.set_prefix_text("Progress Bar #3 ");
|
bar3.set_prefix_text("Progress Bar #3 ");
|
||||||
|
|
||||||
indicators::MultiProgress<indicators::BlockProgressBar, 3> bars;
|
indicators::MultiProgress<indicators::BlockProgressBar, 3> bars(bar1, bar2, bar3);
|
||||||
bars.insert<0>(bar1);
|
|
||||||
bars.insert<1>(bar2);
|
|
||||||
bars.insert<2>(bar3);
|
|
||||||
|
|
||||||
std::cout << "Multiple Progress Bars:\n";
|
std::cout << "Multiple Progress Bars:\n";
|
||||||
|
|
||||||
|
|||||||
@@ -39,10 +39,7 @@ int main() {
|
|||||||
bar3.show_remaining_time();
|
bar3.show_remaining_time();
|
||||||
bar3.set_prefix_text("Progress Bar #3 ");
|
bar3.set_prefix_text("Progress Bar #3 ");
|
||||||
|
|
||||||
indicators::MultiProgress<indicators::ProgressBar, 3> bars;
|
indicators::MultiProgress<indicators::ProgressBar, 3> bars(bar1, bar2, bar3);
|
||||||
bars.insert<0>(bar1);
|
|
||||||
bars.insert<1>(bar2);
|
|
||||||
bars.insert<2>(bar3);
|
|
||||||
|
|
||||||
std::cout << "Multiple Progress Bars:\n";
|
std::cout << "Multiple Progress Bars:\n";
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user