Skip to content

Commit

Permalink
improved ProgressBar
Browse files Browse the repository at this point in the history
  • Loading branch information
qddyy committed Dec 11, 2023
1 parent 65df4a8 commit bf5fc9e
Showing 1 changed file with 15 additions and 10 deletions.
25 changes: 15 additions & 10 deletions src/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

#include <Rcpp.h>
#include <algorithm>
#include <sstream>
#include <string>
#include <tuple>

Expand Down Expand Up @@ -39,37 +40,41 @@ class ProgressBar {
void done()
{
if (_appear) {
Rcout << "\015" << "\033[K" << "\033[0m";
Rcout << "\015\033[K\033[0m";
}
}

void update(unsigned current)
{
if (_appear && (current % _update_every == 0)) {
Rcout << "\015";
std::ostringstream buffer;

buffer << "\015";

unsigned percent = 100 * current / _end;

Rcout << "\033[31m" << percent << "%";
buffer << "\033[31m" << percent << "%";

Rcout << " ";
buffer << " ";

Rcout << "\033[32m" << "[";
buffer << "\033[32m" << "[";
unsigned n_fill = percent >> 2;
unsigned i = 0;
while (i < n_fill) {
Rcout << "=";
buffer << "=";
i++;
}
while (i < 25) {
Rcout << " ";
buffer << " ";
i++;
}
Rcout << "]";
buffer << "]";

buffer << " ";

Rcout << " ";
buffer << "\033[34m" << _label;

Rcout << "\033[34m" << _label;
Rcout << buffer.str();
}
}
};
Expand Down

0 comments on commit bf5fc9e

Please sign in to comment.