mirror of
https://github.com/p-ranav/indicators.git
synced 2025-12-16 04:18:51 +08:00
Merge branch 'p-ranav:master' into master
This commit is contained in:
11
README.md
11
README.md
@@ -80,6 +80,7 @@ int main() {
|
|||||||
option::End{"]"},
|
option::End{"]"},
|
||||||
option::PostfixText{"Extracting Archive"},
|
option::PostfixText{"Extracting Archive"},
|
||||||
option::ForegroundColor{Color::green},
|
option::ForegroundColor{Color::green},
|
||||||
|
option::ShowPercentage{true},
|
||||||
option::FontStyles{std::vector<FontStyle>{FontStyle::bold}}
|
option::FontStyles{std::vector<FontStyle>{FontStyle::bold}}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -127,8 +128,8 @@ int main() {
|
|||||||
option::End{" ]"},
|
option::End{" ]"},
|
||||||
option::PostfixText{"Loading dependency 1/4"},
|
option::PostfixText{"Loading dependency 1/4"},
|
||||||
option::ForegroundColor{Color::cyan},
|
option::ForegroundColor{Color::cyan},
|
||||||
option::FontStyles{std::vector<FontStyle>{FontStyle::bold}}
|
option::ShowPercentage{true},
|
||||||
};
|
option::FontStyles{std::vector<FontStyle>{FontStyle::bold}} };
|
||||||
|
|
||||||
// Update bar state
|
// Update bar state
|
||||||
bar.set_progress(10); // 10% done
|
bar.set_progress(10); // 10% done
|
||||||
@@ -190,6 +191,7 @@ int main() {
|
|||||||
option::End{"]"},
|
option::End{"]"},
|
||||||
option::PrefixText{"Training Gaze Network 👀"},
|
option::PrefixText{"Training Gaze Network 👀"},
|
||||||
option::ForegroundColor{Color::yellow},
|
option::ForegroundColor{Color::yellow},
|
||||||
|
option::ShowPercentage{true},
|
||||||
option::ShowElapsedTime{true},
|
option::ShowElapsedTime{true},
|
||||||
option::ShowRemainingTime{true},
|
option::ShowRemainingTime{true},
|
||||||
option::FontStyles{std::vector<FontStyle>{FontStyle::bold}}
|
option::FontStyles{std::vector<FontStyle>{FontStyle::bold}}
|
||||||
@@ -291,6 +293,7 @@ int main() {
|
|||||||
option::Start{"["},
|
option::Start{"["},
|
||||||
option::End{"]"},
|
option::End{"]"},
|
||||||
option::ForegroundColor{Color::white} ,
|
option::ForegroundColor{Color::white} ,
|
||||||
|
option::ShowPercentage{true},
|
||||||
option::FontStyles{std::vector<FontStyle>{FontStyle::bold}}
|
option::FontStyles{std::vector<FontStyle>{FontStyle::bold}}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -340,6 +343,7 @@ int main() {
|
|||||||
option::Remainder{" "},
|
option::Remainder{" "},
|
||||||
option::End{" ]"},
|
option::End{" ]"},
|
||||||
option::ForegroundColor{Color::yellow},
|
option::ForegroundColor{Color::yellow},
|
||||||
|
option::ShowPercentage{true},
|
||||||
option::ShowElapsedTime{true},
|
option::ShowElapsedTime{true},
|
||||||
option::ShowRemainingTime{true},
|
option::ShowRemainingTime{true},
|
||||||
option::PrefixText{"Progress Bar #1 "},
|
option::PrefixText{"Progress Bar #1 "},
|
||||||
@@ -356,6 +360,7 @@ int main() {
|
|||||||
option::Remainder{" "},
|
option::Remainder{" "},
|
||||||
option::End{" ]"},
|
option::End{" ]"},
|
||||||
option::ForegroundColor{Color::cyan},
|
option::ForegroundColor{Color::cyan},
|
||||||
|
option::ShowPercentage{true},
|
||||||
option::ShowElapsedTime{true},
|
option::ShowElapsedTime{true},
|
||||||
option::ShowRemainingTime{true},
|
option::ShowRemainingTime{true},
|
||||||
option::PrefixText{"Progress Bar #2 "},
|
option::PrefixText{"Progress Bar #2 "},
|
||||||
@@ -371,6 +376,7 @@ int main() {
|
|||||||
option::Remainder{" "},
|
option::Remainder{" "},
|
||||||
option::End{" ]"},
|
option::End{" ]"},
|
||||||
option::ForegroundColor{Color::red},
|
option::ForegroundColor{Color::red},
|
||||||
|
option::ShowPercentage{true},
|
||||||
option::ShowElapsedTime{true},
|
option::ShowElapsedTime{true},
|
||||||
option::ShowRemainingTime{true},
|
option::ShowRemainingTime{true},
|
||||||
option::PrefixText{"Progress Bar #3 "},
|
option::PrefixText{"Progress Bar #3 "},
|
||||||
@@ -723,6 +729,7 @@ int main() {
|
|||||||
BlockProgressBar bar{
|
BlockProgressBar bar{
|
||||||
option::BarWidth{80},
|
option::BarWidth{80},
|
||||||
option::ForegroundColor{Color::white},
|
option::ForegroundColor{Color::white},
|
||||||
|
option::ShowPercentage{true},
|
||||||
option::FontStyles{
|
option::FontStyles{
|
||||||
std::vector<FontStyle>{FontStyle::bold}},
|
std::vector<FontStyle>{FontStyle::bold}},
|
||||||
option::MaxProgress{numbers.size()}
|
option::MaxProgress{numbers.size()}
|
||||||
|
|||||||
@@ -102,10 +102,10 @@ public:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void set_progress(float value) {
|
void set_progress(size_t value) {
|
||||||
{
|
{
|
||||||
std::lock_guard<std::mutex> lock{mutex_};
|
std::lock_guard<std::mutex> lock{mutex_};
|
||||||
progress_ = value;
|
tick_ = value;
|
||||||
}
|
}
|
||||||
save_start_time();
|
save_start_time();
|
||||||
print_progress();
|
print_progress();
|
||||||
@@ -114,7 +114,7 @@ public:
|
|||||||
void tick() {
|
void tick() {
|
||||||
{
|
{
|
||||||
std::lock_guard<std::mutex> lock{mutex_};
|
std::lock_guard<std::mutex> lock{mutex_};
|
||||||
progress_ += 1;
|
tick_++;
|
||||||
}
|
}
|
||||||
save_start_time();
|
save_start_time();
|
||||||
print_progress();
|
print_progress();
|
||||||
@@ -122,8 +122,7 @@ public:
|
|||||||
|
|
||||||
size_t current() {
|
size_t current() {
|
||||||
std::lock_guard<std::mutex> lock{mutex_};
|
std::lock_guard<std::mutex> lock{mutex_};
|
||||||
return (std::min)(static_cast<size_t>(progress_),
|
return (std::min)(tick_, size_t(get_value<details::ProgressBarOption::max_progress>()));
|
||||||
size_t(get_value<details::ProgressBarOption::max_progress>()));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool is_completed() const { return get_value<details::ProgressBarOption::completed>(); }
|
bool is_completed() const { return get_value<details::ProgressBarOption::completed>(); }
|
||||||
@@ -147,6 +146,7 @@ private:
|
|||||||
|
|
||||||
Settings settings_;
|
Settings settings_;
|
||||||
float progress_{0.0};
|
float progress_{0.0};
|
||||||
|
size_t tick_{0};
|
||||||
std::chrono::time_point<std::chrono::high_resolution_clock> start_time_point_;
|
std::chrono::time_point<std::chrono::high_resolution_clock> start_time_point_;
|
||||||
std::mutex mutex_;
|
std::mutex mutex_;
|
||||||
|
|
||||||
@@ -175,11 +175,12 @@ private:
|
|||||||
std::pair<std::string, int> get_postfix_text() {
|
std::pair<std::string, int> get_postfix_text() {
|
||||||
std::stringstream os;
|
std::stringstream os;
|
||||||
const auto max_progress = get_value<details::ProgressBarOption::max_progress>();
|
const auto max_progress = get_value<details::ProgressBarOption::max_progress>();
|
||||||
|
progress_ = static_cast<float>(tick_)/max_progress;
|
||||||
auto now = std::chrono::high_resolution_clock::now();
|
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_);
|
||||||
|
|
||||||
if (get_value<details::ProgressBarOption::show_percentage>()) {
|
if (get_value<details::ProgressBarOption::show_percentage>()) {
|
||||||
os << " " << (std::min)(static_cast<size_t>(progress_ / max_progress * 100.0), size_t(100))
|
os << " " << (std::min)(static_cast<size_t>(progress_ * 100.0), size_t(100))
|
||||||
<< "%";
|
<< "%";
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -201,9 +202,8 @@ private:
|
|||||||
|
|
||||||
if (saved_start_time) {
|
if (saved_start_time) {
|
||||||
auto eta = std::chrono::nanoseconds(
|
auto eta = std::chrono::nanoseconds(
|
||||||
progress_ > 0
|
tick_ > 0
|
||||||
? static_cast<long long>(std::ceil(float(elapsed.count()) *
|
? static_cast<long long>(std::ceil(float(elapsed.count()) * progress_))
|
||||||
max_progress / progress_))
|
|
||||||
: 0);
|
: 0);
|
||||||
auto remaining = eta > elapsed ? (eta - elapsed) : (elapsed - eta);
|
auto remaining = eta > elapsed ? (eta - elapsed) : (elapsed - eta);
|
||||||
details::write_duration(os, remaining);
|
details::write_duration(os, remaining);
|
||||||
@@ -232,7 +232,7 @@ public:
|
|||||||
|
|
||||||
const auto max_progress = get_value<details::ProgressBarOption::max_progress>();
|
const auto max_progress = get_value<details::ProgressBarOption::max_progress>();
|
||||||
if (multi_progress_mode_ && !from_multi_progress) {
|
if (multi_progress_mode_ && !from_multi_progress) {
|
||||||
if (progress_ > max_progress) {
|
if (tick_ > max_progress) {
|
||||||
get_value<details::ProgressBarOption::completed>() = true;
|
get_value<details::ProgressBarOption::completed>() = true;
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
@@ -253,7 +253,7 @@ public:
|
|||||||
|
|
||||||
details::BlockProgressScaleWriter writer{os,
|
details::BlockProgressScaleWriter writer{os,
|
||||||
get_value<details::ProgressBarOption::bar_width>()};
|
get_value<details::ProgressBarOption::bar_width>()};
|
||||||
writer.write(progress_ / max_progress * 100);
|
writer.write(progress_ * 100);
|
||||||
|
|
||||||
os << get_value<details::ProgressBarOption::end>();
|
os << get_value<details::ProgressBarOption::end>();
|
||||||
|
|
||||||
@@ -278,7 +278,7 @@ public:
|
|||||||
}
|
}
|
||||||
os.flush();
|
os.flush();
|
||||||
|
|
||||||
if (progress_ > max_progress) {
|
if (tick_ > max_progress) {
|
||||||
get_value<details::ProgressBarOption::completed>() = true;
|
get_value<details::ProgressBarOption::completed>() = true;
|
||||||
}
|
}
|
||||||
if (get_value<details::ProgressBarOption::completed>() &&
|
if (get_value<details::ProgressBarOption::completed>() &&
|
||||||
@@ -289,4 +289,4 @@ public:
|
|||||||
|
|
||||||
} // namespace indicators
|
} // namespace indicators
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -311,7 +311,7 @@ static inline int mk_wcswidth_cjk(const wchar_t *pwcs, size_t n) {
|
|||||||
// convert UTF-8 string to wstring
|
// convert UTF-8 string to wstring
|
||||||
#ifdef _MSC_VER
|
#ifdef _MSC_VER
|
||||||
static inline std::wstring utf8_decode(const std::string& s) {
|
static inline std::wstring utf8_decode(const std::string& s) {
|
||||||
auto r = setlocale(LC_ALL, "");
|
auto r = setlocale(LC_ALL, NULL);
|
||||||
std::string curLocale;
|
std::string curLocale;
|
||||||
if (r)
|
if (r)
|
||||||
curLocale = r;
|
curLocale = r;
|
||||||
@@ -327,7 +327,7 @@ static inline std::wstring utf8_decode(const std::string& s) {
|
|||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
static inline std::wstring utf8_decode(const std::string& s) {
|
static inline std::wstring utf8_decode(const std::string& s) {
|
||||||
auto r = setlocale(LC_ALL, "");
|
auto r = setlocale(LC_ALL, NULL);
|
||||||
std::string curLocale;
|
std::string curLocale;
|
||||||
if (r)
|
if (r)
|
||||||
curLocale = r;
|
curLocale = r;
|
||||||
|
|||||||
@@ -14,10 +14,10 @@ int main() {
|
|||||||
std::vector<indicators::FontStyle>{indicators::FontStyle::bold}}};
|
std::vector<indicators::FontStyle>{indicators::FontStyle::bold}}};
|
||||||
|
|
||||||
// Update bar state
|
// Update bar state
|
||||||
auto progress = 0.0f;
|
size_t progress = 0;
|
||||||
while (true) {
|
while (true) {
|
||||||
bar.set_progress(progress);
|
bar.set_progress(progress);
|
||||||
progress += 0.25f;
|
progress++;
|
||||||
if (bar.is_completed())
|
if (bar.is_completed())
|
||||||
break;
|
break;
|
||||||
std::this_thread::sleep_for(std::chrono::milliseconds(50));
|
std::this_thread::sleep_for(std::chrono::milliseconds(50));
|
||||||
|
|||||||
Reference in New Issue
Block a user