about summary refs log tree commit diff stats
path: root/src
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2021-11-05 18:27:32 -0700
committerKartik K. Agaram <vc@akkartik.com>2021-11-05 18:43:37 -0700
commitcab996b1941014b78bdfafb1e6d20e159e035f53 (patch)
treef9b2c06b55c9cdd8647a575b5f17c4732ee733c0 /src
parent78898d271620ee15ac576f157ca2e942420421fb (diff)
downloadteliva-cab996b1941014b78bdfafb1e6d20e159e035f53.tar.gz
make some space for the global menu
We'll eventually need some interface to add entries to it.
Diffstat (limited to 'src')
-rw-r--r--src/hanoi.lua1
-rw-r--r--src/lcurseslib.c15
-rw-r--r--src/lua.c5
3 files changed, 20 insertions, 1 deletions
diff --git a/src/hanoi.lua b/src/hanoi.lua
index 9f0b1cf..62571c3 100644
--- a/src/hanoi.lua
+++ b/src/hanoi.lua
@@ -52,6 +52,7 @@ local function render(window)
   for i,t in ipairs(tower) do
     render_tower(window, line, i*col, i, t)
   end
+  curses.refresh()
 end
 
 
diff --git a/src/lcurseslib.c b/src/lcurseslib.c
index e58a5cc..938ebed 100644
--- a/src/lcurseslib.c
+++ b/src/lcurseslib.c
@@ -8,8 +8,21 @@
 #include "lualib.h"
 
 
+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, " ^e ");
+  attron(A_REVERSE);
+  mvaddstr(LINES-1, 6, " edit ");
+  attroff(A_BOLD|A_REVERSE);
+}
+
+
 static int Prefresh (lua_State *L) {
   refresh();
+  draw_menu();
   return 1;
 }
 
@@ -23,6 +36,7 @@ static int Pstdscr (lua_State *L) {
 
 static int Pgetch (lua_State *L) {
   int c = wgetch(stdscr);
+  // TODO: handle menu here
   if (c == ERR)
     return 0;
   lua_pushinteger(L, c);
@@ -159,6 +173,7 @@ static int Wgetmaxyx (lua_State *L) {
   WINDOW *w = checkwin(L, 1);
   int y, x;
   getmaxyx(w, y, x);
+  --y;  // set aside space for the menu bar
   lua_pushinteger(L, y);
   lua_pushinteger(L, x);
   return 2;
diff --git a/src/lua.c b/src/lua.c
index b6cd675..ef44444 100644
--- a/src/lua.c
+++ b/src/lua.c
@@ -449,6 +449,9 @@ static const struct luaL_Reg array_methods [] = {
 };
 
 
+void draw_menu(void);
+
+
 int main (int argc, char **argv) {
   int status;
   struct Smain s;
@@ -467,13 +470,13 @@ int main (int argc, char **argv) {
   luaL_register(L, NULL, array_methods);  /* register array_methods in metatable */
   luaL_register(L, "array", arraylib_functions);
   initscr();
+  draw_menu();
   echo();
   s.argc = argc;
   s.argv = argv;
   status = lua_cpcall(L, &pmain, &s);
   report(L, status);
   lua_close(L);
-  getch();
   endwin();
   return (status || s.status) ? EXIT_FAILURE : EXIT_SUCCESS;
 }