diff options
author | Kartik K. Agaram <vc@akkartik.com> | 2021-11-06 12:44:47 -0700 |
---|---|---|
committer | Kartik K. Agaram <vc@akkartik.com> | 2021-11-06 12:44:47 -0700 |
commit | ee85ad384f17e7270f6bfe42ed146406938131a1 (patch) | |
tree | 9d91bd7d14a8f2df556174038bcf48bae4fce8ea /src/lcurseslib.c | |
parent | 2964a5e74aaf09c0299d38fe756cbc91c018fd99 (diff) | |
download | teliva-ee85ad384f17e7270f6bfe42ed146406938131a1.tar.gz |
simple interface for adding to app menu
We're not going to enforce that the menu items actually do what they advertise. It's just a way to draw on the bottom line of screen, something apps aren't otherwise allowed to do.
Diffstat (limited to 'src/lcurseslib.c')
-rw-r--r-- | src/lcurseslib.c | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/src/lcurseslib.c b/src/lcurseslib.c index ff9e235..9d13f0a 100644 --- a/src/lcurseslib.c +++ b/src/lcurseslib.c @@ -36,19 +36,31 @@ void draw_menu_item(const char* key, const char* name) { attroff(A_REVERSE); } -void draw_menu (void) { +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)) { + lua_pop(L, 1); + return; + } + for (lua_pushnil(L); lua_next(L, table) != 0; lua_pop(L, 1)) + draw_menu_item(lua_tostring(L, -2), lua_tostring(L, -1)); + + attroff(A_BOLD); } static int Prefresh (lua_State *L) { refresh(); - draw_menu(); + draw_menu(L); return 1; } |