mirror of
https://github.com/p-ranav/indicators.git
synced 2025-12-16 04:18:51 +08:00
Closes #24
This commit is contained in:
@@ -77,19 +77,19 @@ public:
|
||||
template <typename T, details::ProgressBarOption id>
|
||||
void set_option(details::Setting<T, id>&& setting){
|
||||
static_assert(!std::is_same<T, typename std::decay<decltype(details::get_value<id>(std::declval<Settings>()))>::type>::value, "Setting has wrong type!");
|
||||
std::lock_guard<std::mutex> lock(_mutex);
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
get_value<id>() = std::move(setting).value;
|
||||
}
|
||||
|
||||
template <typename T, details::ProgressBarOption id>
|
||||
void set_option(const details::Setting<T, id>& setting){
|
||||
static_assert(!std::is_same<T, typename std::decay<decltype(details::get_value<id>(std::declval<Settings>()))>::type>::value, "Setting has wrong type!");
|
||||
std::lock_guard<std::mutex> lock(_mutex);
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
get_value<id>() = setting.value;
|
||||
}
|
||||
|
||||
void set_option(const details::Setting<std::string, details::ProgressBarOption::postfix_text>& setting){
|
||||
std::lock_guard<std::mutex> lock(_mutex);
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
get_value<details::ProgressBarOption::postfix_text>() = setting.value;
|
||||
if(setting.value.length() > get_value<details::ProgressBarOption::max_postfix_text_len>()){
|
||||
get_value<details::ProgressBarOption::max_postfix_text_len>() = setting.value.length();
|
||||
@@ -97,7 +97,7 @@ public:
|
||||
}
|
||||
|
||||
void set_option(details::Setting<std::string, details::ProgressBarOption::postfix_text>&& setting){
|
||||
std::lock_guard<std::mutex> lock(_mutex);
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
get_value<details::ProgressBarOption::postfix_text>() = std::move(setting).value;
|
||||
auto& new_value = get_value<details::ProgressBarOption::postfix_text>();
|
||||
if(new_value.length() > get_value<details::ProgressBarOption::max_postfix_text_len>()){
|
||||
@@ -107,32 +107,32 @@ public:
|
||||
|
||||
void set_progress(float value) {
|
||||
{
|
||||
std::lock_guard<std::mutex> lock{_mutex};
|
||||
_progress = value;
|
||||
std::lock_guard<std::mutex> lock{mutex_};
|
||||
progress_ = value;
|
||||
}
|
||||
_save_start_time();
|
||||
_print_progress();
|
||||
save_start_time();
|
||||
print_progress();
|
||||
}
|
||||
|
||||
void tick() {
|
||||
{
|
||||
std::lock_guard<std::mutex> lock{_mutex};
|
||||
_progress += 1;
|
||||
std::lock_guard<std::mutex> lock{mutex_};
|
||||
progress_ += 1;
|
||||
}
|
||||
_save_start_time();
|
||||
_print_progress();
|
||||
save_start_time();
|
||||
print_progress();
|
||||
}
|
||||
|
||||
size_t current() {
|
||||
std::lock_guard<std::mutex> lock{_mutex};
|
||||
return std::min(static_cast<size_t>(_progress), size_t(100));
|
||||
std::lock_guard<std::mutex> lock{mutex_};
|
||||
return std::min(static_cast<size_t>(progress_), size_t(100));
|
||||
}
|
||||
|
||||
bool is_completed() const { return get_value<details::ProgressBarOption::completed>(); }
|
||||
|
||||
void mark_as_completed() {
|
||||
get_value<details::ProgressBarOption::completed>() = true;
|
||||
_print_progress();
|
||||
print_progress();
|
||||
}
|
||||
|
||||
private:
|
||||
@@ -148,33 +148,33 @@ private:
|
||||
}
|
||||
|
||||
Settings settings_;
|
||||
float _progress{0.0};
|
||||
std::chrono::time_point<std::chrono::high_resolution_clock> _start_time_point;
|
||||
std::mutex _mutex;
|
||||
float progress_{0.0};
|
||||
std::chrono::time_point<std::chrono::high_resolution_clock> start_time_point_;
|
||||
std::mutex mutex_;
|
||||
|
||||
template <typename Indicator, size_t count> friend class MultiProgress;
|
||||
std::atomic<bool> _multi_progress_mode{false};
|
||||
std::atomic<bool> multi_progress_mode_{false};
|
||||
|
||||
void _save_start_time() {
|
||||
void save_start_time() {
|
||||
auto& show_elapsed_time = get_value<details::ProgressBarOption::show_elapsed_time>();
|
||||
auto& saved_start_time = get_value<details::ProgressBarOption::saved_start_time>();
|
||||
auto& show_remaining_time = get_value<details::ProgressBarOption::show_remaining_time>();
|
||||
if ((show_elapsed_time || show_remaining_time) && !saved_start_time) {
|
||||
_start_time_point = std::chrono::high_resolution_clock::now();
|
||||
start_time_point_ = std::chrono::high_resolution_clock::now();
|
||||
saved_start_time = true;
|
||||
}
|
||||
}
|
||||
|
||||
void _print_progress(bool from_multi_progress = false) {
|
||||
if (_multi_progress_mode && !from_multi_progress) {
|
||||
if (_progress > 100.0) {
|
||||
void print_progress(bool from_multi_progress = false) {
|
||||
if (multi_progress_mode_ && !from_multi_progress) {
|
||||
if (progress_ > 100.0) {
|
||||
get_value<details::ProgressBarOption::completed>() = true;
|
||||
}
|
||||
return;
|
||||
}
|
||||
std::lock_guard<std::mutex> lock{_mutex};
|
||||
std::lock_guard<std::mutex> lock{mutex_};
|
||||
auto now = std::chrono::high_resolution_clock::now();
|
||||
auto elapsed = std::chrono::duration_cast<std::chrono::nanoseconds>(now - _start_time_point);
|
||||
auto elapsed = std::chrono::duration_cast<std::chrono::nanoseconds>(now - start_time_point_);
|
||||
|
||||
std::cout << termcolor::bold;
|
||||
details::set_stream_color(std::cout, get_value<details::ProgressBarOption::foreground_color>());
|
||||
@@ -182,11 +182,11 @@ private:
|
||||
std::cout << get_value<details::ProgressBarOption::start>();
|
||||
|
||||
details::BlockProgressScaleWriter writer{std::cout, get_value<details::ProgressBarOption::bar_width>()};
|
||||
writer.write(_progress);
|
||||
writer.write(progress_);
|
||||
|
||||
std::cout << get_value<details::ProgressBarOption::end>();
|
||||
if (get_value<details::ProgressBarOption::show_percentage>()) {
|
||||
std::cout << " " << std::min(static_cast<size_t>(_progress), size_t(100)) << "%";
|
||||
std::cout << " " << std::min(static_cast<size_t>(progress_), size_t(100)) << "%";
|
||||
}
|
||||
|
||||
if (get_value<details::ProgressBarOption::show_elapsed_time>()) {
|
||||
@@ -200,7 +200,7 @@ private:
|
||||
else
|
||||
std::cout << " [";
|
||||
auto eta = std::chrono::nanoseconds(
|
||||
_progress > 0 ? static_cast<long long>(elapsed.count() * 100 / _progress) : 0);
|
||||
progress_ > 0 ? static_cast<long long>(elapsed.count() * 100 / progress_) : 0);
|
||||
auto remaining = eta > elapsed ? (eta - elapsed) : (elapsed - eta);
|
||||
details::write_duration(std::cout, remaining);
|
||||
std::cout << "]";
|
||||
@@ -213,7 +213,7 @@ private:
|
||||
get_value<details::ProgressBarOption::max_postfix_text_len>() = 10;
|
||||
std::cout << " " << get_value<details::ProgressBarOption::postfix_text>() << std::string(get_value<details::ProgressBarOption::max_postfix_text_len>(), ' ') << "\r";
|
||||
std::cout.flush();
|
||||
if (_progress > 100.0) {
|
||||
if (progress_ > 100.0) {
|
||||
get_value<details::ProgressBarOption::completed>() = true;
|
||||
}
|
||||
if (get_value<details::ProgressBarOption::completed>() && !from_multi_progress) // Don't std::endl if calling from MultiProgress
|
||||
|
||||
@@ -39,55 +39,55 @@ public:
|
||||
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;
|
||||
bars_ = {bars...};
|
||||
for (auto &bar : bars_) {
|
||||
bar.get().multi_progress_mode_ = true;
|
||||
}
|
||||
}
|
||||
|
||||
template <size_t index>
|
||||
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();
|
||||
if (!bars_[index].get().is_completed())
|
||||
bars_[index].get().set_progress(value);
|
||||
print_progress();
|
||||
}
|
||||
|
||||
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();
|
||||
if (!bars_[index].get().is_completed())
|
||||
bars_[index].get().tick();
|
||||
print_progress();
|
||||
}
|
||||
|
||||
template <size_t index>
|
||||
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();
|
||||
}
|
||||
|
||||
private:
|
||||
std::atomic<bool> _started{false};
|
||||
std::mutex _mutex;
|
||||
std::vector<std::reference_wrapper<Indicator>> _bars;
|
||||
std::atomic<bool> started_{false};
|
||||
std::mutex mutex_;
|
||||
std::vector<std::reference_wrapper<Indicator>> bars_;
|
||||
|
||||
bool _all_completed() {
|
||||
bool result{true};
|
||||
for (size_t i = 0; i < count; ++i)
|
||||
result &= _bars[i].get().is_completed();
|
||||
result &= bars_[i].get().is_completed();
|
||||
return result;
|
||||
}
|
||||
|
||||
void _print_progress() {
|
||||
std::lock_guard<std::mutex> lock{_mutex};
|
||||
if (_started)
|
||||
void print_progress() {
|
||||
std::lock_guard<std::mutex> lock{mutex_};
|
||||
if (started_)
|
||||
for (size_t i = 0; i < count; ++i)
|
||||
std::cout << "\x1b[A";
|
||||
for (auto &bar : _bars) {
|
||||
bar.get()._print_progress(true);
|
||||
for (auto &bar : bars_) {
|
||||
bar.get().print_progress(true);
|
||||
std::cout << "\n";
|
||||
}
|
||||
std::cout << termcolor::reset;
|
||||
if (!_started)
|
||||
_started = true;
|
||||
if (!started_)
|
||||
started_ = true;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -89,19 +89,19 @@ public:
|
||||
template <typename T, details::ProgressBarOption id>
|
||||
void set_option(details::Setting<T, id>&& setting){
|
||||
static_assert(!std::is_same<T, typename std::decay<decltype(details::get_value<id>(std::declval<Settings>()))>::type>::value, "Setting has wrong type!");
|
||||
std::lock_guard<std::mutex> lock(_mutex);
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
get_value<id>() = std::move(setting).value;
|
||||
}
|
||||
|
||||
template <typename T, details::ProgressBarOption id>
|
||||
void set_option(const details::Setting<T, id>& setting){
|
||||
static_assert(!std::is_same<T, typename std::decay<decltype(details::get_value<id>(std::declval<Settings>()))>::type>::value, "Setting has wrong type!");
|
||||
std::lock_guard<std::mutex> lock(_mutex);
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
get_value<id>() = setting.value;
|
||||
}
|
||||
|
||||
void set_option(const details::Setting<std::string, details::ProgressBarOption::postfix_text>& setting){
|
||||
std::lock_guard<std::mutex> lock(_mutex);
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
get_value<details::ProgressBarOption::postfix_text>() = setting.value;
|
||||
if(setting.value.length() > get_value<details::ProgressBarOption::max_postfix_text_len>()){
|
||||
get_value<details::ProgressBarOption::max_postfix_text_len>() = setting.value.length();
|
||||
@@ -109,7 +109,7 @@ public:
|
||||
}
|
||||
|
||||
void set_option(details::Setting<std::string, details::ProgressBarOption::postfix_text>&& setting){
|
||||
std::lock_guard<std::mutex> lock(_mutex);
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
get_value<details::ProgressBarOption::postfix_text>() = std::move(setting).value;
|
||||
auto& new_value = get_value<details::ProgressBarOption::postfix_text>();
|
||||
if(new_value.length() > get_value<details::ProgressBarOption::max_postfix_text_len>()){
|
||||
@@ -117,35 +117,35 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
void set_progress(float newProgress){
|
||||
void set_progress(float new_progress){
|
||||
{
|
||||
std::lock_guard<std::mutex> lck(_mutex);
|
||||
_progress = newProgress;
|
||||
std::lock_guard<std::mutex> lck(mutex_);
|
||||
progress_ = new_progress;
|
||||
}
|
||||
|
||||
_save_start_time();
|
||||
_print_progress();
|
||||
save_start_time();
|
||||
print_progress();
|
||||
}
|
||||
|
||||
void tick() {
|
||||
{
|
||||
std::lock_guard<std::mutex> lock{_mutex};
|
||||
_progress += 1;
|
||||
std::lock_guard<std::mutex> lock{mutex_};
|
||||
progress_ += 1;
|
||||
}
|
||||
_save_start_time();
|
||||
_print_progress();
|
||||
save_start_time();
|
||||
print_progress();
|
||||
}
|
||||
|
||||
size_t current() {
|
||||
std::lock_guard<std::mutex> lock{_mutex};
|
||||
return std::min(static_cast<size_t>(_progress), size_t(100));
|
||||
std::lock_guard<std::mutex> lock{mutex_};
|
||||
return std::min(static_cast<size_t>(progress_), size_t(100));
|
||||
}
|
||||
|
||||
bool is_completed() const { return get_value<details::ProgressBarOption::completed>(); }
|
||||
|
||||
void mark_as_completed() {
|
||||
get_value<details::ProgressBarOption::completed>() = true;
|
||||
_print_progress();
|
||||
print_progress();
|
||||
}
|
||||
|
||||
private:
|
||||
@@ -160,36 +160,36 @@ private:
|
||||
return details::get_value<id>(settings_).value;
|
||||
}
|
||||
|
||||
float _progress{0};
|
||||
float progress_{0};
|
||||
Settings settings_;
|
||||
std::chrono::nanoseconds _elapsed;
|
||||
std::chrono::time_point<std::chrono::high_resolution_clock> _start_time_point;
|
||||
std::mutex _mutex;
|
||||
std::chrono::nanoseconds elapsed_;
|
||||
std::chrono::time_point<std::chrono::high_resolution_clock> start_time_point_;
|
||||
std::mutex mutex_;
|
||||
|
||||
template <typename Indicator, size_t count> friend class MultiProgress;
|
||||
std::atomic<bool> _multi_progress_mode{false};
|
||||
std::atomic<bool> multi_progress_mode_{false};
|
||||
|
||||
void _save_start_time() {
|
||||
void save_start_time() {
|
||||
auto& show_elapsed_time = get_value<details::ProgressBarOption::show_elapsed_time>();
|
||||
auto& saved_start_time = get_value<details::ProgressBarOption::saved_start_time>();
|
||||
auto& show_remaining_time = get_value<details::ProgressBarOption::show_remaining_time>();
|
||||
if ((show_elapsed_time || show_remaining_time) && !saved_start_time) {
|
||||
_start_time_point = std::chrono::high_resolution_clock::now();
|
||||
start_time_point_ = std::chrono::high_resolution_clock::now();
|
||||
saved_start_time = true;
|
||||
}
|
||||
}
|
||||
|
||||
void _print_progress(bool from_multi_progress = false) {
|
||||
if (_multi_progress_mode && !from_multi_progress) {
|
||||
if (_progress > 100.0) {
|
||||
void print_progress(bool from_multi_progress = false) {
|
||||
if (multi_progress_mode_ && !from_multi_progress) {
|
||||
if (progress_ > 100.0) {
|
||||
get_value<details::ProgressBarOption::completed>() = true;
|
||||
}
|
||||
return;
|
||||
}
|
||||
std::lock_guard<std::mutex> lock{_mutex};
|
||||
std::lock_guard<std::mutex> lock{mutex_};
|
||||
auto now = std::chrono::high_resolution_clock::now();
|
||||
if (!get_value<details::ProgressBarOption::completed>())
|
||||
_elapsed = std::chrono::duration_cast<std::chrono::nanoseconds>(now - _start_time_point);
|
||||
elapsed_ = std::chrono::duration_cast<std::chrono::nanoseconds>(now - start_time_point_);
|
||||
|
||||
std::cout << termcolor::bold;
|
||||
details::set_stream_color(std::cout, get_value<details::ProgressBarOption::foreground_color>());
|
||||
@@ -201,17 +201,17 @@ private:
|
||||
get_value<details::ProgressBarOption::fill>(),
|
||||
get_value<details::ProgressBarOption::lead>(),
|
||||
get_value<details::ProgressBarOption::remainder>()};
|
||||
writer.write(_progress);
|
||||
writer.write(progress_);
|
||||
|
||||
std::cout << get_value<details::ProgressBarOption::end>();
|
||||
|
||||
if (get_value<details::ProgressBarOption::show_percentage>()) {
|
||||
std::cout << " " << std::min(static_cast<size_t>(_progress), size_t(100)) << "%";
|
||||
std::cout << " " << std::min(static_cast<size_t>(progress_), size_t(100)) << "%";
|
||||
}
|
||||
|
||||
if (get_value<details::ProgressBarOption::show_elapsed_time>()) {
|
||||
std::cout << " [";
|
||||
details::write_duration(std::cout, _elapsed);
|
||||
details::write_duration(std::cout, elapsed_);
|
||||
}
|
||||
|
||||
if (get_value<details::ProgressBarOption::show_remaining_time>()) {
|
||||
@@ -220,8 +220,8 @@ private:
|
||||
else
|
||||
std::cout << " [";
|
||||
auto eta = std::chrono::nanoseconds(
|
||||
_progress > 0 ? static_cast<long long>(_elapsed.count() * 100 / _progress) : 0);
|
||||
auto remaining = eta > _elapsed ? (eta - _elapsed) : (_elapsed - eta);
|
||||
progress_ > 0 ? static_cast<long long>(elapsed_.count() * 100 / progress_) : 0);
|
||||
auto remaining = eta > elapsed_ ? (eta - elapsed_) : (elapsed_ - eta);
|
||||
details::write_duration(std::cout, remaining);
|
||||
std::cout << "]";
|
||||
} else {
|
||||
@@ -233,7 +233,7 @@ private:
|
||||
get_value<details::ProgressBarOption::max_postfix_text_len>() = 10;
|
||||
std::cout << " " << get_value<details::ProgressBarOption::postfix_text>() << std::string(get_value<details::ProgressBarOption::max_postfix_text_len>(), ' ') << "\r";
|
||||
std::cout.flush();
|
||||
if (_progress > 100.0) {
|
||||
if (progress_ > 100.0) {
|
||||
get_value<details::ProgressBarOption::completed>() = true;
|
||||
}
|
||||
if (get_value<details::ProgressBarOption::completed>() && !from_multi_progress) // Don't std::endl if calling from MultiProgress
|
||||
|
||||
@@ -78,19 +78,19 @@ public:
|
||||
template <typename T, details::ProgressBarOption id>
|
||||
void set_option(details::Setting<T, id>&& setting){
|
||||
static_assert(!std::is_same<T, typename std::decay<decltype(details::get_value<id>(std::declval<Settings>()))>::type>::value, "Setting has wrong type!");
|
||||
std::lock_guard<std::mutex> lock(_mutex);
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
get_value<id>() = std::move(setting).value;
|
||||
}
|
||||
|
||||
template <typename T, details::ProgressBarOption id>
|
||||
void set_option(const details::Setting<T, id>& setting){
|
||||
static_assert(!std::is_same<T, typename std::decay<decltype(details::get_value<id>(std::declval<Settings>()))>::type>::value, "Setting has wrong type!");
|
||||
std::lock_guard<std::mutex> lock(_mutex);
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
get_value<id>() = setting.value;
|
||||
}
|
||||
|
||||
void set_option(const details::Setting<std::string, details::ProgressBarOption::postfix_text>& setting){
|
||||
std::lock_guard<std::mutex> lock(_mutex);
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
get_value<details::ProgressBarOption::postfix_text>() = setting.value;
|
||||
if(setting.value.length() > get_value<details::ProgressBarOption::max_postfix_text_len>()){
|
||||
get_value<details::ProgressBarOption::max_postfix_text_len>() = setting.value.length();
|
||||
@@ -98,7 +98,7 @@ public:
|
||||
}
|
||||
|
||||
void set_option(details::Setting<std::string, details::ProgressBarOption::postfix_text>&& setting){
|
||||
std::lock_guard<std::mutex> lock(_mutex);
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
get_value<details::ProgressBarOption::postfix_text>() = std::move(setting).value;
|
||||
auto& new_value = get_value<details::ProgressBarOption::postfix_text>();
|
||||
if(new_value.length() > get_value<details::ProgressBarOption::max_postfix_text_len>()){
|
||||
@@ -108,40 +108,40 @@ public:
|
||||
|
||||
void set_progress(float value) {
|
||||
{
|
||||
std::lock_guard<std::mutex> lock{_mutex};
|
||||
_progress = value;
|
||||
std::lock_guard<std::mutex> lock{mutex_};
|
||||
progress_ = value;
|
||||
}
|
||||
_save_start_time();
|
||||
_print_progress();
|
||||
save_start_time();
|
||||
print_progress();
|
||||
}
|
||||
|
||||
void tick() {
|
||||
{
|
||||
std::lock_guard<std::mutex> lock{_mutex};
|
||||
_progress += 1;
|
||||
std::lock_guard<std::mutex> lock{mutex_};
|
||||
progress_ += 1;
|
||||
}
|
||||
_save_start_time();
|
||||
_print_progress();
|
||||
save_start_time();
|
||||
print_progress();
|
||||
}
|
||||
|
||||
size_t current() {
|
||||
std::lock_guard<std::mutex> lock{_mutex};
|
||||
return std::min(static_cast<size_t>(_progress), size_t(100));
|
||||
std::lock_guard<std::mutex> lock{mutex_};
|
||||
return std::min(static_cast<size_t>(progress_), size_t(100));
|
||||
}
|
||||
|
||||
bool is_completed() const { return get_value<details::ProgressBarOption::completed>(); }
|
||||
|
||||
void mark_as_completed() {
|
||||
get_value<details::ProgressBarOption::completed>() = true;
|
||||
_print_progress();
|
||||
print_progress();
|
||||
}
|
||||
|
||||
private:
|
||||
Settings settings_;
|
||||
float _progress{0.0};
|
||||
size_t _index{0};
|
||||
std::chrono::time_point<std::chrono::high_resolution_clock> _start_time_point;
|
||||
std::mutex _mutex;
|
||||
float progress_{0.0};
|
||||
size_t index_{0};
|
||||
std::chrono::time_point<std::chrono::high_resolution_clock> start_time_point_;
|
||||
std::mutex mutex_;
|
||||
|
||||
template <details::ProgressBarOption id>
|
||||
auto get_value() -> decltype((details::get_value<id>(std::declval<Settings&>()).value)) {
|
||||
@@ -153,28 +153,28 @@ private:
|
||||
return details::get_value<id>(settings_).value;
|
||||
}
|
||||
|
||||
void _save_start_time() {
|
||||
void save_start_time() {
|
||||
auto& show_elapsed_time = get_value<details::ProgressBarOption::show_elapsed_time>();
|
||||
auto& show_remaining_time = get_value<details::ProgressBarOption::show_remaining_time>();
|
||||
auto& saved_start_time = get_value<details::ProgressBarOption::saved_start_time>();
|
||||
if ((show_elapsed_time || show_remaining_time) && !saved_start_time) {
|
||||
_start_time_point = std::chrono::high_resolution_clock::now();
|
||||
start_time_point_ = std::chrono::high_resolution_clock::now();
|
||||
saved_start_time = true;
|
||||
}
|
||||
}
|
||||
|
||||
void _print_progress() {
|
||||
std::lock_guard<std::mutex> lock{_mutex};
|
||||
void print_progress() {
|
||||
std::lock_guard<std::mutex> lock{mutex_};
|
||||
auto now = std::chrono::high_resolution_clock::now();
|
||||
auto elapsed = std::chrono::duration_cast<std::chrono::nanoseconds>(now - _start_time_point);
|
||||
auto elapsed = std::chrono::duration_cast<std::chrono::nanoseconds>(now - start_time_point_);
|
||||
|
||||
std::cout << termcolor::bold;
|
||||
details::set_stream_color(std::cout, get_value<details::ProgressBarOption::foreground_color>());
|
||||
std::cout << get_value<details::ProgressBarOption::prefix_text>();
|
||||
if (get_value<details::ProgressBarOption::spinner_show>())
|
||||
std::cout << get_value<details::ProgressBarOption::spinner_states>()[_index % get_value<details::ProgressBarOption::spinner_states>().size()];
|
||||
std::cout << get_value<details::ProgressBarOption::spinner_states>()[index_ % get_value<details::ProgressBarOption::spinner_states>().size()];
|
||||
if (get_value<details::ProgressBarOption::show_percentage>()) {
|
||||
std::cout << " " << std::min(static_cast<size_t>(_progress), size_t(100)) << "%";
|
||||
std::cout << " " << std::min(static_cast<size_t>(progress_), size_t(100)) << "%";
|
||||
}
|
||||
|
||||
if (get_value<details::ProgressBarOption::show_elapsed_time>()) {
|
||||
@@ -188,7 +188,7 @@ private:
|
||||
else
|
||||
std::cout << " [";
|
||||
auto eta = std::chrono::nanoseconds(
|
||||
_progress > 0 ? static_cast<long long>(elapsed.count() * 100 / _progress) : 0);
|
||||
progress_ > 0 ? static_cast<long long>(elapsed.count() * 100 / progress_) : 0);
|
||||
auto remaining = eta > elapsed ? (eta - elapsed) : (elapsed - eta);
|
||||
details::write_duration(std::cout, remaining);
|
||||
std::cout << "]";
|
||||
@@ -201,8 +201,8 @@ private:
|
||||
get_value<details::ProgressBarOption::max_postfix_text_len>() = 10;
|
||||
std::cout << " " << get_value<details::ProgressBarOption::postfix_text>() << std::string(get_value<details::ProgressBarOption::max_postfix_text_len>(), ' ') << "\r";
|
||||
std::cout.flush();
|
||||
_index += 1;
|
||||
if (_progress > 100.0) {
|
||||
index_ += 1;
|
||||
if (progress_ > 100.0) {
|
||||
get_value<details::ProgressBarOption::completed>() = true;
|
||||
}
|
||||
if (get_value<details::ProgressBarOption::completed>())
|
||||
|
||||
Reference in New Issue
Block a user