aboutsummaryrefslogtreecommitdiff
path: root/ui.c
diff options
context:
space:
mode:
authorGabriel A. Giovanini <mail@gabrielgio.me>2024-02-15 23:20:23 +0100
committerGabriel A. Giovanini <mail@gabrielgio.me>2024-02-15 23:20:23 +0100
commitc573d3b7954296d95a0f8a79b8ac2ca261d86a02 (patch)
treec7bc998800ffc625d5c57c8aa17da5edb2ebeefd /ui.c
parent0667e9c0a77791b739bcb359b0ed9f33abbc4133 (diff)
downloaddict-c573d3b7954296d95a0f8a79b8ac2ca261d86a02.tar.gz
dict-c573d3b7954296d95a0f8a79b8ac2ca261d86a02.tar.bz2
dict-c573d3b7954296d95a0f8a79b8ac2ca261d86a02.zip
fix: Add better support for utf-8
Diffstat (limited to 'ui.c')
-rw-r--r--ui.c40
1 files changed, 39 insertions, 1 deletions
diff --git a/ui.c b/ui.c
index 2e779e3..9762859 100644
--- a/ui.c
+++ b/ui.c
@@ -1,6 +1,10 @@
-#include "math.h"
+#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 = "█";
@@ -42,3 +46,37 @@ void bar_step(PROGRESS_BAR* bar, float step){
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);
+ return text;
+}
+
+void get_char(TEXT_BOX* text) {
+ 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';
+ }
+ }
+ move(0,0);
+ wrefresh(text->scr);
+ wprintw(text->scr, "%*ls", text->current,text->text);
+ }
+}