dict @ 3967b61dfbee50d2072ddefced877486ce439582

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