diff options
| author | Marc André Tanner <mat@brain-dump.org> | 2016-11-14 15:54:26 +0100 |
|---|---|---|
| committer | Marc André Tanner <mat@brain-dump.org> | 2016-11-14 15:54:26 +0100 |
| commit | b79da95d4b97125de10e3dc66a88bc475e23b4d3 (patch) | |
| tree | 77064db720d7e33e3666a4bcfce177ce24d6a982 | |
| parent | b701de666e1c2b89bcff67bb309c5f8997ce5c8c (diff) | |
| download | vis-b79da95d4b97125de10e3dc66a88bc475e23b4d3.tar.gz vis-b79da95d4b97125de10e3dc66a88bc475e23b4d3.tar.xz | |
vis-lua: add vis.ui.colors denoting the number of available colors
| -rw-r--r-- | README.md | 2 | ||||
| -rw-r--r-- | ui-curses.c | 5 | ||||
| -rw-r--r-- | ui.h | 1 | ||||
| -rw-r--r-- | vis-lua.c | 26 |
4 files changed, 34 insertions, 0 deletions
@@ -585,6 +585,8 @@ At this time there exists no API stability guarantees. - `MODE_NORMAL`, `MODE_OPERATOR_PENDING`, `MODE_INSERT`, `MODE_REPLACE`, `MODE_VISUAL`, `MODE_VISUAL_LINE` mode constants - `mode` current mode (one of the above constants) - `lexers` LPeg lexer support module + - `ui` + - `colors` number of colors available - `events` hooks - `start()` - `quit()` diff --git a/ui-curses.c b/ui-curses.c index aa9643a..d9981e0 100644 --- a/ui-curses.c +++ b/ui-curses.c @@ -1133,6 +1133,10 @@ static void ui_terminal_restore(Ui *ui) { curs_set(0); } +static int ui_colors(Ui *ui) { + return COLORS; +} + Ui *ui_curses_new(void) { UiCurses *uic = calloc(1, sizeof(UiCurses)); @@ -1186,6 +1190,7 @@ Ui *ui_curses_new(void) { .getkey = ui_getkey, .terminal_save = ui_terminal_save, .terminal_restore = ui_terminal_restore, + .colors = ui_colors, }; struct sigaction sa; @@ -70,6 +70,7 @@ struct Ui { void (*terminal_save)(Ui*); void (*terminal_restore)(Ui*); TermKey* (*termkey_get)(Ui*); + int (*colors)(Ui*); }; struct UiWin { @@ -758,6 +758,11 @@ static int vis_index(lua_State *L) { lua_pushboolean(L, vis_macro_recording(vis)); return 1; } + + if (strcmp(key, "ui") == 0) { + obj_ref_new(L, vis->ui, "vis.ui"); + return 1; + } } return index_common(L); @@ -789,6 +794,21 @@ static const struct luaL_Reg vis_lua[] = { { NULL, NULL }, }; +static int ui_index(lua_State *L) { + Win *win = obj_ref_check(L, 1, "vis.ui"); + if (!win) { + lua_pushnil(L); + return 1; + } + + return index_common(L); +} + +static const struct luaL_Reg ui_funcs[] = { + { "__index", ui_index }, + { NULL, NULL }, +}; + static int window_index(lua_State *L) { Win *win = obj_ref_check(L, 1, "vis.window"); if (!win) { @@ -1462,6 +1482,12 @@ void vis_lua_init(Vis *vis) { luaL_setfuncs(L, window_cursor_funcs, 0); obj_type_new(L, "vis.window.cursors"); luaL_setfuncs(L, window_cursors_funcs, 0); + + obj_type_new(L, "vis.ui"); + luaL_setfuncs(L, ui_funcs, 0); + lua_pushunsigned(L, vis->ui->colors(vis->ui)); + lua_setfield(L, -2, "colors"); + obj_type_new(L, "vis"); luaL_setfuncs(L, vis_lua, 0); |
