From 1d37e5c8930c7542855da0a864c02ee4fd88c092 Mon Sep 17 00:00:00 2001 From: Rudy Dellomas III Date: Wed, 24 Apr 2024 19:12:28 +1000 Subject: lua: Serve viewport dimensions in viewport table These values are useful for calculating terminal positions. --- vis-lua.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/vis-lua.c b/vis-lua.c index 91ee428..a62daf8 100644 --- a/vis-lua.c +++ b/vis-lua.c @@ -1833,8 +1833,10 @@ static const struct luaL_Reg registers_funcs[] = { * Viewport currently being displayed. * Changing these values will not move the viewport. * @table viewport - * @tfield Range bytes - * @tfield Range lines + * @tfield Range bytes file bytes, from 0, at the start and end of the viewport + * @tfield Range lines file lines, from 1, at the top and bottom of the viewport + * @tfield int height lines in viewport, accounting for window decoration + * @tfield int width columns in viewport, accounting for window decoration */ /*** * The window width. @@ -1875,13 +1877,19 @@ static int window_index(lua_State *L) { l.start = view_lines_first(win->view)->lineno; l.end = view_lines_last(win->view)->lineno; - lua_createtable(L, 0, 2); + lua_createtable(L, 0, 4); lua_pushstring(L, "bytes"); pushrange(L, &b); lua_settable(L, -3); lua_pushstring(L, "lines"); pushrange(L, &l); lua_settable(L, -3); + lua_pushstring(L, "width"); + lua_pushunsigned(L, view_width_get(win->view)); + lua_settable(L, -3); + lua_pushstring(L, "height"); + lua_pushunsigned(L, view_height_get(win->view)); + lua_settable(L, -3); return 1; } -- cgit v1.2.3