mirror of
https://github.com/p-ranav/indicators.git
synced 2025-12-12 17:58:55 +08:00
Minor bug fixes and updates:
* Removed progress bar sample that progresses in reverse direction - This needs a class of its own * Fixed a casting error in progress_bar class when dealing with max_progress variable * Minor update to the cursor movement functions in linux * Updated single include to include these changes
This commit is contained in:
@@ -158,38 +158,6 @@ int main() {
|
|||||||
thread4.join();
|
thread4.join();
|
||||||
|
|
||||||
std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
||||||
|
|
||||||
{
|
|
||||||
//
|
|
||||||
// GOING BACKWARDS
|
|
||||||
//
|
|
||||||
indicators::ProgressBar p{option::BarWidth{50},
|
|
||||||
option::Start{"["},
|
|
||||||
option::Fill{"■"},
|
|
||||||
option::Lead{"■"},
|
|
||||||
option::Remainder{"-"},
|
|
||||||
option::End{"]"},
|
|
||||||
option::ForegroundColor{indicators::Color::white},
|
|
||||||
option::PostfixText{"Reverting system restore"},
|
|
||||||
option::FontStyles{
|
|
||||||
std::vector<indicators::FontStyle>{indicators::FontStyle::bold}}};
|
|
||||||
p.set_progress(100); // TODO backwards as an option?
|
|
||||||
std::atomic<size_t> progress{100};
|
|
||||||
auto job = [&p, &progress]() {
|
|
||||||
while (true) {
|
|
||||||
progress -= 1;
|
|
||||||
p.set_progress(progress);
|
|
||||||
if (progress == 0) {
|
|
||||||
p.set_option(option::PostfixText{"Revert complete!"});
|
|
||||||
p.mark_as_completed();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
std::this_thread::sleep_for(std::chrono::milliseconds(60));
|
|
||||||
}
|
|
||||||
};
|
|
||||||
std::thread thread(job);
|
|
||||||
thread.join();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -183,6 +183,7 @@ private:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public:
|
||||||
void print_progress(bool from_multi_progress = false) {
|
void print_progress(bool from_multi_progress = false) {
|
||||||
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) {
|
||||||
|
|||||||
@@ -36,10 +36,10 @@ void move_left(int cols) { move(-cols, 0); }
|
|||||||
|
|
||||||
#else
|
#else
|
||||||
|
|
||||||
void move_up(int lines) { std::cout << "x1b[" << lines << "A"; }
|
void move_up(int lines) { std::cout << "\033[" << lines << "A"; }
|
||||||
void move_down(int lines) { std::cout << "x1b[" << lines << "B"; }
|
void move_down(int lines) { std::cout << "\033[" << lines << "B"; }
|
||||||
void move_right(int cols) { std::cout << "x1b[" << cols << "C"; }
|
void move_right(int cols) { std::cout << "\033[" << cols << "C"; }
|
||||||
void move_left(int cols) { std::cout << "x1b[" << cols << "D"; }
|
void move_left(int cols) { std::cout << "\033[" << cols << "D"; }
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|||||||
@@ -134,7 +134,7 @@ public:
|
|||||||
const std::string &lead, const std::string &remainder)
|
const std::string &lead, const std::string &remainder)
|
||||||
: os(os), bar_width(bar_width), fill(fill), lead(lead), remainder(remainder) {}
|
: os(os), bar_width(bar_width), fill(fill), lead(lead), remainder(remainder) {}
|
||||||
|
|
||||||
std::ostream &write(size_t progress) {
|
std::ostream &write(float progress) {
|
||||||
auto pos = static_cast<size_t>(progress * bar_width / 100.0);
|
auto pos = static_cast<size_t>(progress * bar_width / 100.0);
|
||||||
for (size_t i = 0; i < bar_width; ++i) {
|
for (size_t i = 0; i < bar_width; ++i) {
|
||||||
if (i < pos)
|
if (i < pos)
|
||||||
|
|||||||
@@ -98,6 +98,7 @@ private:
|
|||||||
return details::get_value<id>(settings_).value;
|
return details::get_value<id>(settings_).value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public:
|
||||||
void print_progress() {
|
void print_progress() {
|
||||||
std::lock_guard<std::mutex> lock{mutex_};
|
std::lock_guard<std::mutex> lock{mutex_};
|
||||||
auto &hide_bar_when_complete = get_value<details::ProgressBarOption::hide_bar_when_complete>();
|
auto &hide_bar_when_complete = get_value<details::ProgressBarOption::hide_bar_when_complete>();
|
||||||
|
|||||||
@@ -85,6 +85,7 @@ private:
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public:
|
||||||
void print_progress() {
|
void print_progress() {
|
||||||
std::lock_guard<std::mutex> lock{mutex_};
|
std::lock_guard<std::mutex> lock{mutex_};
|
||||||
if (started_)
|
if (started_)
|
||||||
|
|||||||
@@ -193,6 +193,7 @@ private:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public:
|
||||||
void print_progress(bool from_multi_progress = false) {
|
void print_progress(bool from_multi_progress = false) {
|
||||||
std::lock_guard<std::mutex> lock{mutex_};
|
std::lock_guard<std::mutex> lock{mutex_};
|
||||||
const auto max_progress = get_value<details::ProgressBarOption::max_progress>();
|
const auto max_progress = get_value<details::ProgressBarOption::max_progress>();
|
||||||
@@ -221,7 +222,7 @@ private:
|
|||||||
get_value<details::ProgressBarOption::fill>(),
|
get_value<details::ProgressBarOption::fill>(),
|
||||||
get_value<details::ProgressBarOption::lead>(),
|
get_value<details::ProgressBarOption::lead>(),
|
||||||
get_value<details::ProgressBarOption::remainder>()};
|
get_value<details::ProgressBarOption::remainder>()};
|
||||||
writer.write(progress_ / max_progress * 100);
|
writer.write(double(progress_) / double(max_progress) * 100.0f);
|
||||||
|
|
||||||
std::cout << get_value<details::ProgressBarOption::end>();
|
std::cout << get_value<details::ProgressBarOption::end>();
|
||||||
|
|
||||||
|
|||||||
@@ -182,6 +182,7 @@ private:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public:
|
||||||
void print_progress() {
|
void print_progress() {
|
||||||
std::lock_guard<std::mutex> lock{mutex_};
|
std::lock_guard<std::mutex> lock{mutex_};
|
||||||
const auto max_progress = get_value<details::ProgressBarOption::max_progress>();
|
const auto max_progress = get_value<details::ProgressBarOption::max_progress>();
|
||||||
|
|||||||
@@ -45,8 +45,6 @@ int main() {
|
|||||||
|
|
||||||
bar.set_progress(100); // all done
|
bar.set_progress(100); // all done
|
||||||
|
|
||||||
bar.mark_as_completed();
|
|
||||||
|
|
||||||
// Show cursor
|
// Show cursor
|
||||||
indicators::show_console_cursor(true);
|
indicators::show_console_cursor(true);
|
||||||
|
|
||||||
|
|||||||
@@ -626,7 +626,7 @@ public:
|
|||||||
const std::string &lead, const std::string &remainder)
|
const std::string &lead, const std::string &remainder)
|
||||||
: os(os), bar_width(bar_width), fill(fill), lead(lead), remainder(remainder) {}
|
: os(os), bar_width(bar_width), fill(fill), lead(lead), remainder(remainder) {}
|
||||||
|
|
||||||
std::ostream &write(size_t progress) {
|
std::ostream &write(float progress) {
|
||||||
auto pos = static_cast<size_t>(progress * bar_width / 100.0);
|
auto pos = static_cast<size_t>(progress * bar_width / 100.0);
|
||||||
for (size_t i = 0; i < bar_width; ++i) {
|
for (size_t i = 0; i < bar_width; ++i) {
|
||||||
if (i < pos)
|
if (i < pos)
|
||||||
@@ -980,6 +980,7 @@ private:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public:
|
||||||
void print_progress(bool from_multi_progress = false) {
|
void print_progress(bool from_multi_progress = false) {
|
||||||
std::lock_guard<std::mutex> lock{mutex_};
|
std::lock_guard<std::mutex> lock{mutex_};
|
||||||
if (multi_progress_mode_ && !from_multi_progress) {
|
if (multi_progress_mode_ && !from_multi_progress) {
|
||||||
@@ -1195,6 +1196,7 @@ private:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public:
|
||||||
void print_progress(bool from_multi_progress = false) {
|
void print_progress(bool from_multi_progress = false) {
|
||||||
if (multi_progress_mode_ && !from_multi_progress) {
|
if (multi_progress_mode_ && !from_multi_progress) {
|
||||||
if (progress_ > 100.0) {
|
if (progress_ > 100.0) {
|
||||||
@@ -1402,6 +1404,7 @@ private:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public:
|
||||||
void print_progress() {
|
void print_progress() {
|
||||||
std::lock_guard<std::mutex> lock{mutex_};
|
std::lock_guard<std::mutex> lock{mutex_};
|
||||||
auto now = std::chrono::high_resolution_clock::now();
|
auto now = std::chrono::high_resolution_clock::now();
|
||||||
@@ -1513,6 +1516,7 @@ private:
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public:
|
||||||
void print_progress() {
|
void print_progress() {
|
||||||
std::lock_guard<std::mutex> lock{mutex_};
|
std::lock_guard<std::mutex> lock{mutex_};
|
||||||
if (started_)
|
if (started_)
|
||||||
@@ -1599,6 +1603,7 @@ private:
|
|||||||
return details::get_value<id>(settings_).value;
|
return details::get_value<id>(settings_).value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public:
|
||||||
void print_progress() {
|
void print_progress() {
|
||||||
std::lock_guard<std::mutex> lock{mutex_};
|
std::lock_guard<std::mutex> lock{mutex_};
|
||||||
auto &hide_bar_when_complete = get_value<details::ProgressBarOption::hide_bar_when_complete>();
|
auto &hide_bar_when_complete = get_value<details::ProgressBarOption::hide_bar_when_complete>();
|
||||||
|
|||||||
Reference in New Issue
Block a user