diff options
author | Gabriel A. Giovanini <mail@gabrielgio.me> | 2024-02-14 11:59:10 +0100 |
---|---|---|
committer | Gabriel A. Giovanini <g.giovanini@gridx.de> | 2024-02-14 12:29:28 +0100 |
commit | 3967b61dfbee50d2072ddefced877486ce439582 (patch) | |
tree | 800856749a232fa5ed92ab1d51b43c1218f59232 /ui.c | |
parent | 03aa0fe6c664f74e8e4e5877ef89b4e053b30bc5 (diff) | |
download | dict-3967b61dfbee50d2072ddefced877486ce439582.tar.gz dict-3967b61dfbee50d2072ddefced877486ce439582.tar.bz2 dict-3967b61dfbee50d2072ddefced877486ce439582.zip |
feat: Add buggy ui component
Diffstat (limited to 'ui.c')
-rw-r--r-- | ui.c | 63 |
1 files changed, 63 insertions, 0 deletions
@@ -0,0 +1,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); +} |