Add files via upload
This commit is contained in:
parent
07f2ed525b
commit
6e7f0c1505
37 changed files with 4084 additions and 20 deletions
31
extras/cpp/progress_bar.hpp
Normal file
31
extras/cpp/progress_bar.hpp
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
// extras/cpp — decorative. a tiny console progress bar, echoing the shape
|
||||
// of the /api/job/<id> polling response from backend/jobs.py.
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <algorithm>
|
||||
|
||||
namespace nexdex {
|
||||
|
||||
class ProgressBar {
|
||||
public:
|
||||
ProgressBar(std::string label, int width) : label_(std::move(label)), width_(width) {}
|
||||
|
||||
std::string render(int percent) const {
|
||||
percent = std::clamp(percent, 0, 100);
|
||||
int filled = width_ * percent / 100;
|
||||
int empty = width_ - filled;
|
||||
|
||||
std::string bar;
|
||||
bar.append(filled, '#');
|
||||
bar.append(empty, '-');
|
||||
|
||||
return label_ + " [" + bar + "] " + std::to_string(percent) + "%";
|
||||
}
|
||||
|
||||
private:
|
||||
std::string label_;
|
||||
int width_;
|
||||
};
|
||||
|
||||
} // namespace nexdex
|
||||
Loading…
Add table
Add a link
Reference in a new issue