From 2964a5e74aaf09c0299d38fe756cbc91c018fd99 Mon Sep 17 00:00:00 2001 From: "Kartik K. Agaram" Date: Sat, 6 Nov 2021 12:41:14 -0700 Subject: refactor menu drawing --- src/lcurseslib.c | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/src/lcurseslib.c b/src/lcurseslib.c index 90755c3..ff9e235 100644 --- a/src/lcurseslib.c +++ b/src/lcurseslib.c @@ -19,19 +19,30 @@ static void cleanup(void) { } +int menu_column = 0; +void draw_string_on_menu(const char* s) { + mvaddstr(LINES-1, menu_column, " "); + ++menu_column; + mvaddstr(LINES-1, menu_column, s); + menu_column += strlen(s); + mvaddstr(LINES-1, menu_column, " "); + ++menu_column; +} +void draw_menu_item(const char* key, const char* name) { + attroff(A_REVERSE); + draw_string_on_menu(key); + attron(A_REVERSE); + draw_string_on_menu(name); + attroff(A_REVERSE); +} + void draw_menu (void) { attron(A_BOLD|A_REVERSE); for (int x = 0; x < COLS; ++x) mvaddch(LINES-1, x, ' '); - attroff(A_REVERSE); - mvaddstr(LINES-1, 2, " ^x "); - attron(A_REVERSE); - mvaddstr(LINES-1, 6, " exit "); - attroff(A_REVERSE); - mvaddstr(LINES-1, 12, " ^e "); - attron(A_REVERSE); - mvaddstr(LINES-1, 16, " edit "); - attroff(A_BOLD|A_REVERSE); + menu_column = 2; + draw_menu_item("^x", "exit"); + draw_menu_item("^e", "edit"); } -- cgit 1.4.1-2-gfad0