1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
|
#include "math.h"
#include <ncurses.h>
#include <stdlib.h>
#include "ui.h"
const char *uload = "█";
PROGRESS_BAR* new_progress_bar(WINDOW* scr, float total) {
PROGRESS_BAR *bar = (PROGRESS_BAR*)malloc(sizeof(PROGRESS_BAR));
bar->scr = scr;
bar->total = total;
bar->current = 0;
int x, y;
int hx, hy;
getmaxyx(scr, y, x);
hx = x/2;
hy = y/2;
wmove(scr, hy-1, 0);
wprintw(scr, uload);
wmove(scr, hy, hx-4);
wprintw(scr, "000%%");
wmove(scr, hy+1, hx);
wprintw(scr, "%.0f/%.0f", 0.0, total);
return bar;
}
void bar_step(PROGRESS_BAR* bar, float step){
bar->current += step;
int x, y;
int hx, hy;
getmaxyx(bar->scr, y, x);
hx = x/2;
hy = y/2;
float total = (bar->current/bar->total);
wmove(bar->scr, hy-1, 0);
for (int i = 0; i < ((float)x*total); i++)
wprintw(bar->scr, uload);
wmove(bar->scr, hy, hx-4);
wprintw(bar->scr,"%03.0f%% ", total*100);
int len = floor(log10(abs((int)bar->total))) + 3;
wmove(bar->scr, hy+1, hx - len);
wprintw(bar->scr, "%.0f/%.0f", bar->current, bar->total);
wmove(bar->scr,0,0);
wrefresh(bar->scr);
}
|