Added prefix to progress bar, perc right
This commit is contained in:
parent
5bb2d7268c
commit
35ed58b012
@ -27,23 +27,34 @@ int term::cols() const {
|
|||||||
return _ws.ws_col;
|
return _ws.ws_col;
|
||||||
}
|
}
|
||||||
|
|
||||||
void term::progress(double cur, double total) const {
|
void term::progress(int prefixlen,
|
||||||
|
const std::string& prefix,
|
||||||
|
double cur,
|
||||||
|
double total) const
|
||||||
|
{
|
||||||
// use unicode to make nice bar
|
// use unicode to make nice bar
|
||||||
const char* bar[8] = {
|
const char* bar[8] = {
|
||||||
u8"\u258F", u8"\u258E", u8"\u258D", u8"\u258C",
|
u8"\u258F", u8"\u258E", u8"\u258D", u8"\u258C",
|
||||||
u8"\u258B", u8"\u258A", u8"\u2589", u8"\u2588"
|
u8"\u258B", u8"\u258A", u8"\u2589", u8"\u2588"
|
||||||
};
|
};
|
||||||
int barwidth = cols() - 5;
|
int perclen = 5;
|
||||||
|
int barwidth = cols() - perclen - prefixlen - 1;
|
||||||
int maxsteps = barwidth * 8;
|
int maxsteps = barwidth * 8;
|
||||||
int steps = round(cur * maxsteps / total);
|
int steps = round(cur * maxsteps / total);
|
||||||
int perc = round(100 * cur / total);
|
int perc = round(100 * cur / total);
|
||||||
*_out << '\r' << std::setw(3) << perc << "% ";
|
int fill_len = barwidth - steps / 8;
|
||||||
|
*_out << '\r' << std::setw(prefixlen) << prefix << ' ';
|
||||||
|
grayf(8);
|
||||||
for (int i = 0; i < steps / 8; ++i) {
|
for (int i = 0; i < steps / 8; ++i) {
|
||||||
*_out << bar[7];
|
*_out << bar[7];
|
||||||
}
|
}
|
||||||
if (steps % 8) {
|
if (steps % 8) {
|
||||||
*_out << bar[steps % 8 - 1];
|
*_out << bar[steps % 8 - 1];
|
||||||
|
fill_len--;
|
||||||
}
|
}
|
||||||
|
reset();
|
||||||
|
*_out << std::string(fill_len, ' ');
|
||||||
|
*_out << ' ' << std::setw(3) << perc << '%';
|
||||||
}
|
}
|
||||||
|
|
||||||
void term::hide_cursor() const {
|
void term::hide_cursor() const {
|
||||||
|
@ -5,6 +5,7 @@
|
|||||||
#include <termios.h>
|
#include <termios.h>
|
||||||
#include <sys/ioctl.h>
|
#include <sys/ioctl.h>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
namespace sc {
|
namespace sc {
|
||||||
|
|
||||||
@ -21,7 +22,10 @@ namespace sc {
|
|||||||
int rows() const;
|
int rows() const;
|
||||||
int cols() const;
|
int cols() const;
|
||||||
|
|
||||||
void progress(double cur, double total) const;
|
void progress(int prefixlen,
|
||||||
|
const std::string& prefix,
|
||||||
|
double cur,
|
||||||
|
double total) const;
|
||||||
|
|
||||||
void hide_cursor() const;
|
void hide_cursor() const;
|
||||||
void show_cursor() const;
|
void show_cursor() const;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user