Renamed print->write, added some more fflush()es, converted some macros
into proper functions.
This commit is contained in:
parent
2121e5b037
commit
01612abb5a
@ -82,7 +82,7 @@ static int Lbtui_getkey(lua_State *L)
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int Lbtui_print(lua_State *L)
|
||||
static int Lbtui_write(lua_State *L)
|
||||
{
|
||||
btui_t **bt = (btui_t**)lua_touserdata(L, 1);
|
||||
if (bt == NULL) luaL_error(L, "Not a BTUI object");
|
||||
@ -445,7 +445,7 @@ static const luaL_Reg Rclass_metamethods[] =
|
||||
{"disable", Lbtui_disable},
|
||||
{"withdisabled", Lbtui_withdisabled},
|
||||
{"getkey", Lbtui_getkey},
|
||||
{"print", Lbtui_print},
|
||||
{"write", Lbtui_write},
|
||||
{"clear", Lbtui_clear},
|
||||
{"flush", Lbtui_flush},
|
||||
{"move", Lbtui_move},
|
||||
|
10
Lua/test.lua
10
Lua/test.lua
@ -6,7 +6,7 @@ btui(function(bt)
|
||||
while key ~= "q" and key ~= "Ctrl-c" do
|
||||
if key == "?" then
|
||||
bt:withdisabled(function()
|
||||
io.write("OK? ")
|
||||
io.write("Press enter to continue.")
|
||||
io.flush()
|
||||
io.read()
|
||||
end)
|
||||
@ -19,7 +19,7 @@ btui(function(bt)
|
||||
bt:withfg(.8,.95,.2, function()
|
||||
bt:linebox(x, y, 30, 1);
|
||||
bt:move(x, y)
|
||||
bt:print("Pressed: ", key)
|
||||
bt:write("Pressed: ", key)
|
||||
end)
|
||||
|
||||
bt:withattributes("bg_blue", "fg_black", function()
|
||||
@ -29,12 +29,14 @@ btui(function(bt)
|
||||
bt:fillbox(center-2, 0, w+4, 3)
|
||||
bt:shadow(center-2, 0, w+4, 3)
|
||||
bt:move(center, 1)
|
||||
bt:print(title)
|
||||
bt:write(title)
|
||||
end)
|
||||
|
||||
bt:withattributes("faint", function()
|
||||
local s = ("Size: (%dx%d)"):format(bt:width(), bt:height())
|
||||
bt:move(bt:width()-#s, bt:height()-1)
|
||||
bt:print(s)
|
||||
bt:write(s)
|
||||
end)
|
||||
|
||||
local mouse_x, mouse_y
|
||||
key, mouse_x, mouse_y = bt:getkey()
|
||||
|
@ -131,7 +131,7 @@ before the error is printed. Here's a simple example program:
|
||||
bt:disable() -- Disables btui
|
||||
bt:withdisabled(fn) -- Calls "fn" with btui disabled, then re-enables btui
|
||||
bt:getkey(timeout=-1) -- Returns a keypress (and optionally, mouse x and y coordinates). The optional timeout argument specifies how long, in tenths of a second, to wait for the next keypress.
|
||||
bt:print() -- Print text to the terminal
|
||||
bt:write() -- Write text to the terminal
|
||||
bt:clear(type="screen") -- Clear the terminal. Options are: "screen", "right", "left", "above", "below", "line"
|
||||
bt:flush() -- Flush the terminal output. Most operations do this anyways.
|
||||
bt:move(x, y) -- Move the cursor to the given position. (0,0) is the top left corner.
|
||||
|
35
btui.h
35
btui.h
@ -39,19 +39,19 @@ int btui_set_fg(btui_t *bt, unsigned char r, unsigned char g, unsigned char b);
|
||||
int btui_set_bg(btui_t *bt, unsigned char r, unsigned char g, unsigned char b);
|
||||
int btui_set_fg_hex(btui_t *bt, int hex);
|
||||
int btui_set_bg_hex(btui_t *bt, int hex);
|
||||
#define btui_printf(bt, ...) fprintf((bt)->out, __VA_ARGS__)
|
||||
#define btui_puts(bt, s) fputs(s, (bt)->out)
|
||||
#define btui_flush(bt) fflush((bt)->out)
|
||||
void btui_draw_linebox(btui_t *bt, int x, int y, int w, int h);
|
||||
void btui_fill_box(btui_t *bt, int x, int y, int w, int h);
|
||||
void btui_draw_shadow(btui_t *bt, int x, int y, int w, int h);
|
||||
int btui_puts(btui_t *bt, const char *s);
|
||||
int btui_flush(btui_t *bt);
|
||||
int btui_suspend(btui_t *bt);
|
||||
#define btui_clear_below(bt) fputs("\033[J", (bt)->out)
|
||||
#define btui_clear_above(bt) fputs("\033[1J", (bt)->out)
|
||||
#define btui_clear_screen(bt) fputs("\033[2J", (bt)->out)
|
||||
#define btui_clear_right(bt) fputs("\033[K", (bt)->out)
|
||||
#define btui_clear_left(bt) fputs("\033[1K", (bt)->out)
|
||||
#define btui_clear_line(bt) fputs("\033[2K", (bt)->out)
|
||||
#define btui_suspend(bt) kill(getpid(), SIGTSTP)
|
||||
void btui_draw_linebox(btui_t *bt, int x, int y, int w, int h);
|
||||
void btui_fill_box(btui_t *bt, int x, int y, int w, int h);
|
||||
void btui_draw_shadow(btui_t *bt, int x, int y, int w, int h);
|
||||
#define btui_printf(bt, ...) fprintf((bt)->out, __VA_ARGS__)
|
||||
|
||||
static btui_t current_bt;
|
||||
|
||||
@ -614,6 +614,7 @@ void btui_draw_linebox(btui_t *bt, int x, int y, int w, int h)
|
||||
for (int i = 0; i < w; i++)
|
||||
fputc('q', bt->out);
|
||||
fputs("j\033(B", bt->out);
|
||||
fflush(bt->out);
|
||||
}
|
||||
|
||||
void btui_fill_box(btui_t *bt, int x, int y, int w, int h)
|
||||
@ -626,6 +627,7 @@ void btui_fill_box(btui_t *bt, int x, int y, int w, int h)
|
||||
fputc(' ', bt->out);
|
||||
}
|
||||
}
|
||||
fflush(bt->out);
|
||||
}
|
||||
|
||||
void btui_draw_shadow(btui_t *bt, int x, int y, int w, int h)
|
||||
@ -640,6 +642,25 @@ void btui_draw_shadow(btui_t *bt, int x, int y, int w, int h)
|
||||
fputc('a', bt->out);
|
||||
}
|
||||
fputs("\033(B", bt->out);
|
||||
fflush(bt->out);
|
||||
}
|
||||
|
||||
int btui_puts(btui_t *bt, const char *s)
|
||||
{
|
||||
int ret = fputs(s, bt->out);
|
||||
fflush(bt->out);
|
||||
return ret;
|
||||
}
|
||||
|
||||
int btui_flush(btui_t *bt)
|
||||
{
|
||||
return fflush(bt->out);
|
||||
}
|
||||
|
||||
int btui_suspend(btui_t *bt)
|
||||
{
|
||||
(void)bt;
|
||||
return kill(getpid(), SIGTSTP);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user