aboutsummaryrefslogtreecommitdiff
path: root/src/tui.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/tui.c')
-rw-r--r--src/tui.c29
1 files 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++;
}
}
@@ -71,6 +65,15 @@ redraw(void)
}
void
+init(void)
+{
+ win = initscr();
+ noecho();
+ clear();
+ redraw();
+}
+
+void
display_calc(int x, int y)
{
current_idx = next_calc(current_idx);
@@ -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(&current_idx, data + sizeof(calcs), sizeof(current_idx));
free(data);
init();
+ redraw();
}
#endif