progress bar
This commit is contained in:
parent
d1d81f051f
commit
95b4a62995
@ -12,6 +12,7 @@
|
||||
#include <thread> // For std::this_thread (C++ standard library)
|
||||
#include <chrono> // For timing operations (C++ standard library)
|
||||
#include <cstdio> // For freopen
|
||||
#include <regex>
|
||||
|
||||
std::string directory_path = ".";
|
||||
int selected_index = -1; // Global variable to hold the selected index
|
||||
@ -370,6 +371,34 @@ int main(int argc, char* argv[]) {
|
||||
// Get the latest progress string from the observer
|
||||
std::string current_progress = engineObserver.getProgress();
|
||||
|
||||
float progress = 0.0f;
|
||||
|
||||
// Find number in string
|
||||
std::regex number_regex(R"((\d+(\.\d+)?))");
|
||||
std::smatch match;
|
||||
|
||||
if (std::regex_search(current_progress, match, number_regex)) {
|
||||
try {
|
||||
float value = std::stof(match.str()); // "9.26" -> 9.26
|
||||
progress = std::clamp(value / 100.0f, 0.0f, 1.0f); // normalize
|
||||
}
|
||||
catch (...) {
|
||||
progress = 0.0f;
|
||||
}
|
||||
}
|
||||
|
||||
/* float progress = 0.0f;
|
||||
|
||||
if (!current_progress.empty()) {
|
||||
try {
|
||||
int value = std::stoi(current_progress); // "45" -> 45
|
||||
progress = std::clamp(value / 100.0f, 0.0f, 1.0f);
|
||||
}
|
||||
catch (...) {
|
||||
progress = 0.0f; // fallback if not numeric
|
||||
}
|
||||
}*/
|
||||
|
||||
return ftxui::vbox({
|
||||
|
||||
// Header showing the current directory
|
||||
@ -390,7 +419,7 @@ int main(int argc, char* argv[]) {
|
||||
ftxui::text(current_progress.empty() ? "Idle" : current_progress)
|
||||
| ftxui::color(ftxui::Color::Green),
|
||||
}),
|
||||
|
||||
ftxui::gauge(progress),
|
||||
ftxui::separator(),
|
||||
ftxui::hbox({
|
||||
ftxui::text("Enter folder #: "),
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user