anagrams.tlv: slightly more responsive

Now we cancel screen-painting if any key is pressed.

However it looks like just computing the list of anagrams can take a
long time.
This commit is contained in:
Kartik K. Agaram 2022-03-05 09:47:47 -08:00
parent 520cc09997
commit 057f4a2870
2 changed files with 31 additions and 1 deletions

View File

@ -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
>

View File

@ -1360,6 +1360,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
@ -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 ),