dict @ 3967b61dfbee50d2072ddefced877486ce439582

feat: Add buggy ui component
diff --git a/data.c b/data.c
index 777dcdf58b260a0ecf8c50fb56132b34d0a6c35d..81ee9f31356c495fe4754f9105a3211f863e9956 100644
--- a/data.c
+++ b/data.c
@@ -70,7 +70,7 @@
     sqlite3_finalize(stmt);
 }
 
-LIST* select(Data* data) {
+LIST* data_select(Data* data) {
     sqlite3_stmt *stmt; 
     int r = sqlite3_prepare_v2(data->db, select_words, -1, &stmt, NULL);
 
diff --git a/data.h b/data.h
index 393f8308c1ccf9032745260ee3ef84b9d5af3462..8bc30e9396446df274a6dd39022d5e32f5d42033 100644
--- a/data.h
+++ b/data.h
@@ -39,7 +39,7 @@
 /*
  * Select all words.
  */
-LIST* select(Data*);
+LIST* data_select(Data*);
 
 /*
  * Print result code from sqlite.
diff --git a/main.c b/main.c
index dae1f2aa50de122aa0d00c8cfec74b3f939a5bfc..69a68b8de4df79435dead3ef0535736d7c6422e0 100644
--- a/main.c
+++ b/main.c
@@ -3,6 +3,7 @@ #include <stdio.h>
 #include <sqlite3.h>
 #include <ncurses.h>
 #include "data.h"
+#include "ui.h"
 
 #define BUF_SIZE 100
 
@@ -10,14 +11,13 @@ unsigned int count_lines(FILE* file);
 int load_or_save_db(sqlite3 *pInMemory, const char *zFilename, int isSave);
 
 int main() {
-    Data *data = new_data(":memory:");
-
-    bootstrap(data);
-
     setlocale(LC_ALL, "");
-    initscr();
+    initscr(); 
+    noecho();
+    cbreak();
 
-    int maxx=getmaxx(stdscr);
+    Data *data = new_data(":memory:");
+    bootstrap(data);
 
     FILE *f = fopen("dict.txt", "r");
     unsigned int lines = count_lines(f);
@@ -26,22 +26,13 @@
     char * line = NULL;
     size_t len = 0;
     ssize_t read;
-    int count = 0;
+    PROGRESS_BAR *bar = new_progress_bar(stdscr, lines);
     while ((read = getline(&line, &len, f)) != -1) {
         if (line[0] == '#' || line[0] == '\n')
             continue;
 
         insert(data, line, read-1);
-        count ++;
-        move(0,0);
-        float total = ((float)count/(float)lines);
-        printw("%03.0f%% ", total*100);
-        for (int x = 0; x < ((maxx-4)*total); x++) {
-            printw("█");
-        }
-        move(1,0);
-        printw("%d/%d",count,lines);
-        refresh();
+        bar_step(bar, 1);
     }
 
     move(2,0);
@@ -51,6 +42,9 @@     load_or_save_db(data->db, "backup.db", 1);
 
     clear();
     refresh();
+    endwin();
+
+    free_data(data);
     return 0;
 }
 
diff --git a/ui.c b/ui.c
new file mode 100644
index 0000000000000000000000000000000000000000..8837bab19ca394e22205abe5312b37350ddad5e5
--- /dev/null
+++ b/ui.c
@@ -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);
+}
diff --git a/ui.h b/ui.h
new file mode 100644
index 0000000000000000000000000000000000000000..8035d6f9955b77119212f3920905a615f49fc912
--- /dev/null
+++ b/ui.h
@@ -0,0 +1,11 @@
+#include <ncurses.h>
+
+typedef struct progress_bar {
+    float total;
+    float current;
+    WINDOW *scr;
+} PROGRESS_BAR;
+
+PROGRESS_BAR* new_progress_bar(WINDOW*, float);
+
+void bar_step(PROGRESS_BAR*, float);