From: Rui Guo Date: Thu, 13 Aug 2009 14:59:49 +0000 (+0800) Subject: Implement get_lines & get_history for window object. X-Git-Url: https://repo.or.cz/w/screen-lua.git/commitdiff_plain/39111f1749878afbe648208ccea96b37fe4ae840 Implement get_lines & get_history for window object. --- diff --git a/src/lua.c b/src/lua.c index 03dacd0..8547e55 100644 --- a/src/lua.c +++ b/src/lua.c @@ -506,11 +506,61 @@ window_get_showing_canvases(lua_State *L) return 1; } +static int +window_getlines(lua_State *L) +{ + struct win *w = check_window(L, 1); + int i; + lua_newtable(L); + for (i = 0; i < fore->w_height; i++) + { + char *p = (char *)w->w_mlines[i].image; + int k, save; + for (k = fore->w_width - 1; k >= 0 && p[k] == ' '; k--) + ; + k +=(p[k] != ' '); + save = p[k]; + p[k] = 0; + lua_pushinteger(L, i); + lua_pushstring(L, p); + lua_settable(L, -3); + p[k] = save; + } + + return 1; +} + +static int +window_gethistory(lua_State *L) +{ + struct win *w = check_window(L, 1); + int i; + lua_newtable(L); + for (i = 0; i < fore->w_height; i++) + { + char *p = (char *) w->w_hlines[(w->w_histidx + i) % w->w_histheight].image; + int k, save; + for (k = fore->w_width - 1; k >= 0 && p[k] == ' '; k--) + ; + k +=(p[k] != ' '); + save = p[k]; + p[k] = 0; + lua_pushinteger(L, i); + lua_pushstring(L, p); + lua_settable(L, -3); + p[k] = save; + } + + return 1; +} + static const luaL_reg window_methods[] = { {"get_monitor_status", window_get_monitor_status}, {"showing_canvases", window_get_showing_canvases}, {"stuff", window_stuff}, {"activate", window_activate}, + {"get_lines", window_getlines}, + {"get_history", window_gethistory}, {"hook", LuaRegEvent}, {0, 0} };