From 5d5ff4076abe2e8aeb40980ec1b3ef9ee5fa92e6 Mon Sep 17 00:00:00 2001 From: Tristan Riehs Date: Sun, 30 Jun 2024 15:44:08 +0900 Subject: Fix TUI drawing --- src/tui.c | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/src/tui.c b/src/tui.c index aa08d52..7b49adf 100644 --- a/src/tui.c +++ b/src/tui.c @@ -27,20 +27,13 @@ static struct calc_data calcs[CALC_COUNT] = {0}; static int current_idx = 0; static WINDOW *win; -void -init(void) -{ - win = initscr(); - clear(); - refresh(); -} - static void draw_res(void) { - int j = current_idx; + int j = loop_backwards(current_idx); + int drawn = 0; - while (calcs[j].ms != 0) + while ((calcs[j].ms != 0) && (drawn < CALC_COUNT)) { printw("%d + %d = %d\t%s\t%dms\n", calcs[j].x, calcs[j].y, @@ -49,6 +42,7 @@ draw_res(void) calcs[j].ms); j = loop_backwards(j); + drawn++; } } @@ -70,6 +64,15 @@ redraw(void) refresh(); } +void +init(void) +{ + win = initscr(); + noecho(); + clear(); + redraw(); +} + void display_calc(int x, int y) { @@ -135,8 +138,9 @@ read_input(void) void display_res(bool right, int ms) { - (void) right; - (void) ms; + calcs[current_idx].right = right; + calcs[current_idx].ms = ms; + redraw(); } void @@ -164,5 +168,6 @@ post_reload(void *state) memcpy(¤t_idx, data + sizeof(calcs), sizeof(current_idx)); free(data); init(); + redraw(); } #endif -- cgit v1.2.3