From f2200e22b05c3801b722cd46617e7bcf64538d17 Mon Sep 17 00:00:00 2001 From: gabrielgio Date: Sat, 17 Feb 2024 21:55:15 +0100 Subject: feat: Add a more "refined" UI --- lib/data.c | 6 ++++-- lib/data.h | 2 +- lib/ui.c | 20 ++++++++++++++++++-- lib/ui.h | 9 +++++++++ 4 files changed, 32 insertions(+), 5 deletions(-) (limited to 'lib') diff --git a/lib/data.c b/lib/data.c index e94e0a7..1c1a754 100644 --- a/lib/data.c +++ b/lib/data.c @@ -3,9 +3,10 @@ #include #include "data.h" +#include "../lib/util.h" const char *insert_into = "INSERT INTO words (LINE) VALUES($VVV);"; -const char *select_words = "SELECT Id, Line FROM words WHERE line like $VVV LIMIT 10;"; +const char *select_words = "SELECT Id, Line FROM words WHERE line like $VVV LIMIT $NNN;"; const char *create_table = "CREATE TABLE IF NOT EXISTS words (ID INTEGER PRIMARY KEY AUTOINCREMENT, LINE TEXT NOT NULL);"; Data* new_data(const char* con) @@ -80,7 +81,7 @@ void bootstrap(Data* data) sqlite3_finalize(stmt); } -LIST* data_select(Data* data, char *sch, int len) +LIST* data_select(Data* data, char *sch, int len, int limit) { sqlite3_stmt *stmt; int r = sqlite3_prepare_v2(data->db, select_words, -1, &stmt, NULL); @@ -95,6 +96,7 @@ LIST* data_select(Data* data, char *sch, int len) LIST *list = NULL; sqlite3_bind_text(stmt, 1, sch, len, NULL); + sqlite3_bind_int(stmt, 2, limit); int m = sqlite3_step(stmt); while(m == SQLITE_ROW) { diff --git a/lib/data.h b/lib/data.h index fcde55a..6c9f30f 100644 --- a/lib/data.h +++ b/lib/data.h @@ -39,7 +39,7 @@ void insert(Data*, char*, int); /* * Select all words. */ -LIST* data_select(Data*, char*, int); +LIST* data_select(Data*, char*, int, int); /* * Print result code from sqlite. diff --git a/lib/ui.c b/lib/ui.c index 3eae201..cd54cd4 100644 --- a/lib/ui.c +++ b/lib/ui.c @@ -56,6 +56,7 @@ TEXT_BOX* new_text_box(WINDOW* scr, int length) text->current = 0; text->text = malloc(sizeof(char)*(length+1)); memset(text->text, '\0', length); + box(scr, 0,0); return text; } @@ -82,8 +83,23 @@ void get_char(TEXT_BOX* text, void (*sch)(char*, int)) wcstombs(str, text->text, sizeof(text->text)); sch(str, (int)strlen(str)); - move(0,0); - wrefresh(text->scr); + 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); +} diff --git a/lib/ui.h b/lib/ui.h index 12ee2f4..271105a 100644 --- a/lib/ui.h +++ b/lib/ui.h @@ -21,3 +21,12 @@ typedef struct text_box TEXT_BOX* new_text_box(WINDOW*, int); void get_char(TEXT_BOX* text, void (*sch)(char*, int)); + +typedef struct panel +{ + WINDOW *scr; +} PANEL; + + +PANEL* new_panel(WINDOW*); +void write_char(PANEL*, int, char*); -- cgit v1.2.3