diff options
-rw-r--r-- | anagrams.tlv | 12 | ||||
-rw-r--r-- | src/lcurses/window.c | 20 |
2 files changed, 31 insertions, 1 deletions
diff --git a/anagrams.tlv b/anagrams.tlv index 9a20f26..06e760e 100644 --- a/anagrams.tlv +++ b/anagrams.tlv @@ -228,6 +228,7 @@ - __teliva_timestamp: original main: >function main() + > Window:nodelay(true) > while true do > render(Window) > update(Window) @@ -236,7 +237,11 @@ - __teliva_timestamp: original update: >function update(window) - > local key = window:getch() + > local key + > while true do + > key = window:getch() + > if key then break end + > end > if key == curses.KEY_LEFT then > if cursor > 1 then > cursor = cursor-1 @@ -277,6 +282,11 @@ > for i, w in ipairs(results) do > window:addstr(w) > window:addstr(' ') + > local tmp = window:getch() + > if tmp then + > window:ungetch(tmp) + > break + > end > end > end > diff --git a/src/lcurses/window.c b/src/lcurses/window.c index 02fccb2..e3fcc70 100644 --- a/src/lcurses/window.c +++ b/src/lcurses/window.c @@ -1361,6 +1361,25 @@ Wgetch(lua_State *L) /*** +Put back a character obtained from @{getch} +@function ungetch +@int ch +@treturn OK or ERR +@see mvwgetch(3x) +@see getch +*/ +static int +Wungetch(lua_State *L) +{ + int ch = checkint(L, 2); + int result = ungetch(ch); + if (result == ERR) + return 0; + return pushintresult(result); +} + + +/*** Call @{move} then @{getch} @function mvgetch @int y @@ -1893,6 +1912,7 @@ static const luaL_Reg curses_window_fns[] = LCURSES_FUNC( Wtimeout ), LCURSES_FUNC( Wtouch ), LCURSES_FUNC( Wtouchline ), + LCURSES_FUNC( Wungetch ), LCURSES_FUNC( Wvline ), LCURSES_FUNC( Wwbkgd ), LCURSES_FUNC( Wwbkgdset ), |