diff options
author | Kartik K. Agaram <vc@akkartik.com> | 2021-11-20 21:03:38 -0800 |
---|---|---|
committer | Kartik K. Agaram <vc@akkartik.com> | 2021-11-20 21:03:38 -0800 |
commit | 02acfa7c9c9347abf2c170b0405010bc6f219fc0 (patch) | |
tree | 4ee5ff3af4f206b00a732eacde31922fe64ef448 /src/menu.c | |
parent | fa6faaa70093a88bfa3ad2f4414ff0b0c84f7c74 (diff) | |
download | teliva-02acfa7c9c9347abf2c170b0405010bc6f219fc0.tar.gz |
rename
Diffstat (limited to 'src/menu.c')
-rw-r--r-- | src/menu.c | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/src/menu.c b/src/menu.c new file mode 100644 index 0000000..b5173bb --- /dev/null +++ b/src/menu.c @@ -0,0 +1,40 @@ +#include <ncurses.h> +#include <string.h> + +#include "lua.h" + + +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); +} + +void draw_menu (lua_State *L) { + attron(A_BOLD|A_REVERSE); + for (int x = 0; x < COLS; ++x) + mvaddch(LINES-1, x, ' '); + menu_column = 2; + draw_menu_item("^x", "exit"); + draw_menu_item("^e", "edit"); + + /* render any app-specific items */ + lua_getglobal(L, "menu"); + int table = lua_gettop(L); + if (lua_istable(L, -1)) + for (lua_pushnil(L); lua_next(L, table) != 0; lua_pop(L, 1)) + draw_menu_item(lua_tostring(L, -2), lua_tostring(L, -1)); + + lua_pop(L, 1); + attroff(A_BOLD|A_REVERSE); +} |