dict @ 0667e9c0a77791b739bcb359b0ed9f33abbc4133

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