Added scroll to more APIs

This commit is contained in:
Bruce Hill 2020-04-19 16:57:05 -07:00
parent 8ac3870d60
commit 5c3b7ec2da
3 changed files with 25 additions and 0 deletions

View File

@ -223,6 +223,7 @@ static int Lbtui_fillbox(lua_State *L)
btui_fill_box(*bt, x, y, w, h);
return 0;
}
static int Lbtui_shadow(lua_State *L)
{
btui_t **bt = (btui_t**)lua_touserdata(L, 1);
@ -240,6 +241,21 @@ static int Lbtui_shadow(lua_State *L)
return 0;
}
static int Lbtui_scroll(lua_State *L)
{
btui_t **bt = (btui_t**)lua_touserdata(L, 1);
if (bt == NULL) luaL_error(L, "Not a BTUI object");
int isnum;
lua_Integer firstline = lua_tointegerx(L, 2, &isnum);
if (!isnum) luaL_argerror(L, 2, "expected integer for first line");
lua_Integer lastline = lua_tointegerx(L, 3, &isnum);
if (!isnum) luaL_argerror(L, 3, "expected integer for last line");
lua_Integer scroll = lua_tointegerx(L, 4, &isnum);
if (!isnum) luaL_argerror(L, 4, "expected integer for scroll amount");
btui_scroll(*bt, firstline, lastline, scroll);
return 0;
}
static int Lbtui_setattributes(lua_State *L)
{
btui_t **bt = (btui_t**)lua_touserdata(L, 1);
@ -456,6 +472,7 @@ static const luaL_Reg Rclass_metamethods[] =
{"suspend", Lbtui_suspend},
{"linebox", Lbtui_linebox},
{"fillbox", Lbtui_fillbox},
{"scroll", Lbtui_scroll},
{"shadow", Lbtui_shadow},
{"width", Lbtui_width},
{"height", Lbtui_height},

View File

@ -150,6 +150,13 @@ class BTUI:
assert self._btui
libbtui.btui_move_cursor(self._btui, int(x), int(y))
def scroll(self, firstline, lastline=None, amount=None):
assert self._btui
if amount is None:
amount = firstline
firstline, lastline = 1, self.height
libbtui.btui_scroll(self._btui, firstline, lastline, amount)
def flush(self):
assert self._btui
libbtui.btui_flush(self._btui)

View File

@ -99,6 +99,7 @@ constants, including terminal escape values and keycodes.
int btui_move_cursor(btui_t *bt, int x, int y);
#define btui_printf(bt, ...) fprintf((bt)->out, __VA_ARGS__)
int btui_puts(btui_t *bt, const char *s);
int btui_scroll(btui_t *bt, int firstline, int lastline, int scroll_amount);
int btui_set_attributes(btui_t *bt, attr_t attrs);
int btui_set_bg(btui_t *bt, unsigned char r, unsigned char g, unsigned char b);
int btui_set_bg_hex(btui_t *bt, int hex);