diff options
author | 2020-09-19 13:18:44 -0400 | |
---|---|---|
committer | 2020-09-19 13:18:44 -0400 | |
commit | 28a73bcf0fe6fa9cd97e50734fb243c625284a89 (patch) | |
tree | 185e7334cfea073086690ec88d46fea3bc0a365f /src/textadept.c | |
parent | 84388249c689a8a3d0a893d095dde86600186e6d (diff) | |
download | textadept-28a73bcf0fe6fa9cd97e50734fb243c625284a89.tar.gz textadept-28a73bcf0fe6fa9cd97e50734fb243c625284a89.zip |
Added `ui.update()` for unit tests.
Diffstat (limited to 'src/textadept.c')
-rw-r--r-- | src/textadept.c | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/src/textadept.c b/src/textadept.c index 0c68ab53..9b1a8b8a 100644 --- a/src/textadept.c +++ b/src/textadept.c @@ -816,6 +816,20 @@ static int menu(lua_State *L) { #endif } +/** `ui.update()` Lua function. */ +static int update_ui(lua_State *L) { +#if GTK + while (gtk_events_pending()) gtk_main_iteration(); +#elif (CURSES && !_WIN32) + struct timeval timeout = {0, 1e5}; // 0.1s + int nfds = os_spawn_pushfds(L); + while (select(nfds, lua_touserdata(L, -1), NULL, NULL, &timeout) > 0) + if (os_spawn_readfds(L) >= 0) refresh_all(); + lua_pop(L, 1); // fd_set +#endif + return 0; +} + /** `ui.__index` Lua metamethod. */ static int ui_index(lua_State *L) { const char *key = lua_tostring(L, 2); @@ -1572,6 +1586,7 @@ static bool init_lua(lua_State *L, int argc, char **argv, bool reinit) { lua_pushcfunction(L, get_split_table), lua_setfield(L, -2, "get_split_table"); lua_pushcfunction(L, goto_view), lua_setfield(L, -2, "goto_view"); lua_pushcfunction(L, menu), lua_setfield(L, -2, "menu"); + lua_pushcfunction(L, update_ui), lua_setfield(L, -2, "update"); set_metatable(L, -1, "ta_ui", ui_index, ui_newindex); lua_setglobal(L, "ui"); |