Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Align Saving, Loading and Verifying progress bars #170

Merged
merged 5 commits into from
Nov 19, 2024
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 13 additions & 8 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3922,21 +3922,22 @@ static picoboot::connection get_single_rp2350_bootsel_device_connection(device_m

struct progress_bar {
explicit progress_bar(string prefix, int width = 30) : prefix(std::move(prefix)), width(width) {
// Align all bars with the longest possible prefix string
auto longest_mem = std::max_element(
std::begin(memory_names), std::end(memory_names),
[] (const auto & p1, const auto & p2) {
return p1.second.length() < p2.second.length();
}
);
longest_mem_str = longest_mem->second;
progress(0);
}

void progress(int _percent) {
if (_percent != percent) {
percent = _percent;
unsigned int len = (width * percent) / 100;
// Align all bars with the longest possible prefix string
auto longest_mem = std::max_element(
std::begin(memory_names), std::end(memory_names),
[] (const auto & p1, const auto & p2) {
return p1.second.length() < p2.second.length();
}
);
string extra_space(string("Loading into " + longest_mem->second + ": ").length() - prefix.length(), ' ');
string extra_space(string("Loading into " + longest_mem_str + ": ").length() - prefix.length(), ' ');
lurch marked this conversation as resolved.
Show resolved Hide resolved
std::cout << prefix << extra_space << "[" << string(len, '=') << string(width-len, ' ') << "] " << std::to_string(percent) << "%\r" << std::flush;
}
}
Expand All @@ -3952,6 +3953,7 @@ struct progress_bar {
std::string prefix;
int percent = -1;
int width;
std::string longest_mem_str;
};

#if HAS_LIBUSB
Expand Down Expand Up @@ -3998,6 +4000,9 @@ bool save_command::execute(device_map &devices) {
} else {
start = settings.from;
end = settings.to;
// Set offset for verifying
settings.offset = start;
settings.offset_set = true;
}
if (end <= start) {
fail(ERROR_ARGS, "Save range is invalid/empty");
Expand Down
Loading