optimin nits

This commit is contained in:
vanhauser-thc
2021-07-21 09:55:22 +02:00
parent fa2b164429
commit 60cbe5b4be
8 changed files with 133 additions and 22 deletions

View File

@ -11,6 +11,7 @@
/// Display a progress bar in the terminal
class ProgressBar {
private:
const size_t BarWidth;
const std::string Fill;
@ -18,14 +19,17 @@ class ProgressBar {
public:
ProgressBar() : ProgressBar(60, "#", " ") {
}
ProgressBar(size_t Width, const llvm::StringRef F, const llvm::StringRef R)
: BarWidth(Width), Fill(F), Remainder(R) {
}
void update(float Progress, const llvm::StringRef Status = "",
llvm::raw_ostream &OS = llvm::outs()) {
// No need to write once progress is 100%
if (Progress > 100.0f) return;
@ -39,11 +43,17 @@ class ProgressBar {
const auto Completed =
static_cast<size_t>(Progress * static_cast<float>(BarWidth) / 100.0);
for (size_t I = 0; I < BarWidth; ++I) {
if (I <= Completed) {
OS << Fill;
} else {
OS << Remainder;
}
}
// End bar
@ -54,5 +64,8 @@ class ProgressBar {
// Write status text
OS << " " << Status;
}
};