diff options
| author | Marc André Tanner <mat@brain-dump.org> | 2016-05-20 13:21:31 +0200 |
|---|---|---|
| committer | Marc André Tanner <mat@brain-dump.org> | 2016-05-22 00:05:30 +0200 |
| commit | 70641c44040751ae6ff6f3d7567448dcc2fcc061 (patch) | |
| tree | afaacd7f3f65dee5172c5effa825ab5e06fc0568 /vis-lua.c | |
| parent | e29bbbb8ea4f59d277a6e4f50d7d2501ddd04b07 (diff) | |
| download | vis-70641c44040751ae6ff6f3d7567448dcc2fcc061.tar.gz vis-70641c44040751ae6ff6f3d7567448dcc2fcc061.tar.xz | |
vis-lua: add bindings for new view style functions
Diffstat (limited to 'vis-lua.c')
| -rw-r--r-- | vis-lua.c | 44 |
1 files changed, 44 insertions, 0 deletions
@@ -672,11 +672,36 @@ static int window_map(lua_State *L) { return keymap(L, win->vis, win); } +static int window_style_define(lua_State *L) { + Win *win = obj_ref_check(L, 1, "vis.window"); + bool ret = false; + if (win) { + enum UiStyle id = luaL_checkunsigned(L, 2); + const char *style = luaL_checkstring(L, 3); + ret = view_style_define(win->view, id, style); + } + lua_pushboolean(L, ret); + return 1; +} + +static int window_style(lua_State *L) { + Win *win = obj_ref_check(L, 1, "vis.window"); + if (win) { + enum UiStyle style = luaL_checkunsigned(L, 2); + size_t start = checkpos(L, 3); + size_t end = checkpos(L, 4); + view_style(win->view, style, start, end); + } + return 0; +} + static const struct luaL_Reg window_funcs[] = { { "__index", window_index }, { "__newindex", window_newindex }, { "cursors_iterator", window_cursors_iterator }, { "map", window_map }, + { "style_define", window_style_define }, + { "style", window_style }, { NULL, NULL }, }; @@ -1138,6 +1163,25 @@ void vis_lua_init(Vis *vis) { luaL_setfuncs(L, file_lines_funcs, 0); luaL_newmetatable(L, "vis.window"); luaL_setfuncs(L, window_funcs, 0); + + static const struct { + enum UiStyle id; + const char *name; + } styles[] = { + { UI_STYLE_DEFAULT, "STYLE_DEFAULT" }, + { UI_STYLE_CURSOR, "STYLE_CURSOR" }, + { UI_STYLE_CURSOR_PRIMARY, "STYLE_CURSOR_PRIMARY" }, + { UI_STYLE_CURSOR_LINE, "STYLE_CURSOR_LINE" }, + { UI_STYLE_SELECTION, "STYLE_SELECTION" }, + { UI_STYLE_LINENUMBER, "STYLE_LINENUMBER" }, + { UI_STYLE_COLOR_COLUMN, "STYLE_COLOR_COLUMN" }, + }; + + for (size_t i = 0; i < LENGTH(styles); i++) { + lua_pushunsigned(L, styles[i].id); + lua_setfield(L, -2, styles[i].name); + } + luaL_newmetatable(L, "vis.window.cursor"); luaL_setfuncs(L, window_cursor_funcs, 0); luaL_newmetatable(L, "vis.window.cursors"); |
