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:
Pranav Srinivas Kumar
2020-05-08 15:14:52 -05:00
parent 66af25ab62
commit 296bde6088
10 changed files with 17 additions and 41 deletions

View File

@@ -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();
}
} }
{ {

View File

@@ -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) {

View File

@@ -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

View File

@@ -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)

View File

@@ -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>();

View File

@@ -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_)

View File

@@ -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>();

View File

@@ -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>();

View File

@@ -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);

View File

@@ -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>();