From 02acfa7c9c9347abf2c170b0405010bc6f219fc0 Mon Sep 17 00:00:00 2001 From: "Kartik K. Agaram" Date: Sat, 20 Nov 2021 21:03:38 -0800 Subject: rename --- src/Makefile | 2 +- src/lcurseslib.c | 40 ---------------------------------------- src/menu.c | 40 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 41 insertions(+), 41 deletions(-) delete mode 100644 src/lcurseslib.c create mode 100644 src/menu.c (limited to 'src') diff --git a/src/Makefile b/src/Makefile index c17467a..76c26ac 100644 --- a/src/Makefile +++ b/src/Makefile @@ -27,7 +27,7 @@ CORE_O= lapi.o lcode.o ldebug.o ldo.o ldump.o lfunc.o lgc.o llex.o lmem.o \ lobject.o lopcodes.o lparser.o lstate.o lstring.o ltable.o ltm.o \ lundump.o lvm.o lzio.o \ kilo.o -LIB_O= lauxlib.o lbaselib.o lcurseslib.o ldblib.o liolib.o lmathlib.o \ +LIB_O= lauxlib.o lbaselib.o menu.o ldblib.o liolib.o lmathlib.o \ loslib.o ltablib.o lstrlib.o loadlib.o linit.o \ lcurses/curses.o luasocket/socket.a diff --git a/src/lcurseslib.c b/src/lcurseslib.c deleted file mode 100644 index b5173bb..0000000 --- a/src/lcurseslib.c +++ /dev/null @@ -1,40 +0,0 @@ -#include -#include - -#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); -} 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 +#include + +#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); +} -- cgit 1.4.1-2-gfad0