diff options
Diffstat (limited to 'src/lcurses')
-rw-r--r-- | src/lcurses/curses.c | 46 | ||||
-rw-r--r-- | src/lcurses/curses.lua | 49 | ||||
-rw-r--r-- | src/lcurses/window.c | 14 |
3 files changed, 28 insertions, 81 deletions
diff --git a/src/lcurses/curses.c b/src/lcurses/curses.c index c5f7c3e..303607a 100644 --- a/src/lcurses/curses.c +++ b/src/lcurses/curses.c @@ -111,19 +111,12 @@ Pnew_chstr(lua_State *L) #define CCR(n, v) \ lua_pushstring(L, n); \ lua_pushinteger(L, v); \ - lua_settable(L, lua_upvalueindex(1)) + lua_settable(L, -3); #define CC(s) CCR(#s, s) #define CF(i) CCR(LCURSES_STR(LCURSES_SPLICE(KEY_F, i)), KEY_F(i)) /* -** these values may be fixed only after initialization, so this is -** called from Pinitscr, after the curses driver is initialized -** -** curses table is kept at upvalue position 1, in case the global -** name is changed by the user or even in the registration phase by -** the developer -** ** some of these values are not constant so need to register ** them directly instead of using a table */ @@ -217,8 +210,8 @@ register_curses_constants(lua_State *L) ** proper cleanup) */ -static void -cleanup(void) +void +cleanup_curses(void) { if (!isendwin()) { @@ -229,31 +222,12 @@ cleanup(void) } -/*** -Initialise screen. -@function initscr -@treturn window main screen -@see initscr(3x) -*/ +extern void stack_dump(lua_State *L); static int -Pinitscr(lua_State *L) +init_stdscr(lua_State *L) { - WINDOW *w; - - /* initialize curses */ - w = initscr(); - - /* no longer used, so clean it up */ - lua_pushstring(L, RIPOFF_TABLE); - lua_pushnil(L); - lua_settable(L, LUA_REGISTRYINDEX); - - /* failed to initialize */ - if (w == NULL) - return 0; - /* return stdscr - main window */ - lc_newwin(L, w); + lc_newwin(L, stdscr); /* save main window on registry */ lua_pushstring(L, STDSCR_REGISTRY); @@ -261,10 +235,11 @@ Pinitscr(lua_State *L) lua_rawset(L, LUA_REGISTRYINDEX); /* setup curses constants - curses.xxx numbers */ + lua_pushvalue(L, -2); register_curses_constants(L); /* install cleanup handler to help in debugging and screen trashing */ - atexit(cleanup); + atexit(cleanup_curses); return 1; } @@ -1546,10 +1521,7 @@ luaopen_curses_c(lua_State *L) luaL_register(L, "curses", curseslib); - lua_pushstring(L, "initscr"); - lua_pushvalue(L, -2); - lua_pushcclosure(L, Pinitscr, 1); - lua_settable(L, -3); + init_stdscr(L); return 1; } diff --git a/src/lcurses/curses.lua b/src/lcurses/curses.lua index bba9d12..216fb42 100644 --- a/src/lcurses/curses.lua +++ b/src/lcurses/curses.lua @@ -1,53 +1,20 @@ --- Lua bindings for curses local M = curses --- These Lua functions detect number of args, like Unified Funcs in Perl Curses --- see http://pjb.com.au/comp/lua/lcurses.html --- see http://search.cpan.org/perldoc?Curses - -function M.addch (...) - if #{...} == 3 then - return curses.stdscr():mvaddch(...) - else - return curses.stdscr():addch(...) - end -end - -function M.addstr(...) -- detect number of args, like Unified Funcs in Perl Curses - if #{...} == 3 then - return curses.stdscr():mvaddstr(...) - else - return curses.stdscr():addstr(...) - end -end +function M.addch (c) return curses.stdscr():addch(c) end +function M.mvaddch (y, x, c) return curses.stdscr():mvaddch(y, x, c) end +function M.addstr (s) return curses.stdscr():addstr(s) end +function M.mvaddstr (y, x, s) return curses.stdscr():mvaddstr(y, x, s) end function M.attrset (a) return curses.stdscr():attrset(a) end function M.clear () return curses.stdscr():clear() end function M.clrtobot () return curses.stdscr():clrtobot() end function M.clrtoeol () return curses.stdscr():clrtoeol() end -function M.getch (...) - local c - if #{...} == 2 then - c = curses.stdscr():mvgetch(...) - else - c = curses.stdscr():getch() - end - if c < 256 then - return string.char(c) - end - -- could kludge-test for utf8, e.g. c3 a9 20 c3 aa 20 c3 ab 20 e2 82 ac 0a - return c -end - -function M.getstr (...) - if #{...} > 1 then - return curses.stdscr():mvgetstr(...) - else - return curses.stdscr():getstr(...) - end -end -M.getnstr = M.getstr +function M.getch () return curses.stdscr():getch() end +function M.mvgetch (y, x) return curses.stdscr():getch(y, x) end +function M.getstr (s) return curses.stdscr():getstr(s) end +function M.mvgetstr (y, x, s) return curses.stdscr():mvgetstr(y, x, s) end function M.getyx () return curses.stdscr():getyx() end function M.keypad (b) return curses.stdscr():keypad(b) end diff --git a/src/lcurses/window.c b/src/lcurses/window.c index fd18570..9c243ea 100644 --- a/src/lcurses/window.c +++ b/src/lcurses/window.c @@ -36,8 +36,6 @@ @classmod curses.window */ -//? #include <config.h> - #include "_helpers.c" #include "chstr.c" @@ -311,10 +309,13 @@ Refresh the window terminal display from the virtual screen. @see curses.doupdate @see noutrefresh */ +extern void draw_menu (lua_State *L); static int Wrefresh(lua_State *L) { - return pushokresult(wrefresh(checkwin(L, 1))); + int result = wrefresh(checkwin(L, 1)); + draw_menu(L); + return pushokresult(result); } @@ -548,6 +549,7 @@ 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; @@ -1302,6 +1304,7 @@ Read a character from the window input. @see curses.echo @see keypad */ +extern void switch_to_editor (lua_State *L, const char *message); static int Wgetch(lua_State *L) { @@ -1310,6 +1313,11 @@ Wgetch(lua_State *L) if (c == ERR) return 0; + if (c == 24) /* ctrl-x */ + exit(0); + if (c == 5) /* ctrl-e */ + switch_to_editor(L, ""); + /* handle other standard menu hotkeys here */ return pushintresult(c); } |