diff options
author | Gabriel A. Giovanini <mail@gabrielgio.me> | 2024-04-15 22:16:28 +0200 |
---|---|---|
committer | Gabriel A. Giovanini <mail@gabrielgio.me> | 2024-04-15 22:16:28 +0200 |
commit | 6dd0c4747aa57227b5898fc639e3f2b643ce013c (patch) | |
tree | e43ee077469b5c28fcf46dba51eb03e53214fad5 /lib/ui.c | |
parent | 6ed576974dec969ad2745a451a6f680a3cdbcfc4 (diff) | |
download | dict-6dd0c4747aa57227b5898fc639e3f2b643ce013c.tar.gz dict-6dd0c4747aa57227b5898fc639e3f2b643ce013c.tar.bz2 dict-6dd0c4747aa57227b5898fc639e3f2b643ce013c.zip |
feat: Remove C implementation
Diffstat (limited to 'lib/ui.c')
-rw-r--r-- | lib/ui.c | 105 |
1 files changed, 0 insertions, 105 deletions
diff --git a/lib/ui.c b/lib/ui.c deleted file mode 100644 index cd54cd4..0000000 --- a/lib/ui.c +++ /dev/null @@ -1,105 +0,0 @@ -#define NCURSES_WIDECHAR 1 - -#include <ncurses.h> -#include <math.h> -#include <stdlib.h> -#include <string.h> -#include <wchar.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; - 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); -} - -TEXT_BOX* new_text_box(WINDOW* scr, int length) -{ - TEXT_BOX *text = (TEXT_BOX*)malloc(sizeof(TEXT_BOX)); - text->scr = scr; - text->length = length; - text->current = 0; - text->text = malloc(sizeof(char)*(length+1)); - memset(text->text, '\0', length); - box(scr, 0,0); - return text; -} - -void get_char(TEXT_BOX* text, void (*sch)(char*, int)) -{ - while(1) { - wchar_t c; - get_wch((wint_t*)&c); - - switch(c) { - case KEY_BACKSPACE: - if (text->current > 0) { - text->text[text->current--] = '\0'; - } - break; - default: - if (text->current < (text->length-2)) { - text->text[text->current] = c; - text->text[++text->current] = '\0'; - } - } - - char str[text->length]; - wcstombs(str, text->text, sizeof(text->text)); - sch(str, (int)strlen(str)); - - wmove(text->scr,1,1); - wprintw(text->scr, "%*ls", text->current,text->text); - wrefresh(text->scr); - } -} - -PANEL* new_panel(WINDOW* scr) -{ - PANEL *panel = (PANEL*)malloc(sizeof(PANEL)); - panel->scr = scr; - box(scr, 0,0); - return panel; -} -void write_char(PANEL* panel, int l, char *text) -{ - int x = getmaxx(panel->scr); - wmove(panel->scr, l+1, 1); - wprintw(panel->scr, "%.*s", x-3, text); - wrefresh(panel->scr); -} |