diff options
| -rw-r--r-- | lua/vis.lua | 2 | ||||
| -rw-r--r-- | main.c | 1 | ||||
| -rw-r--r-- | ui-terminal.c | 1 | ||||
| -rw-r--r-- | vis-core.h | 1 | ||||
| -rw-r--r-- | vis-lua.c | 14 | ||||
| -rw-r--r-- | vis-lua.h | 1 | ||||
| -rw-r--r-- | vis.c | 4 | ||||
| -rw-r--r-- | vis.h | 1 |
8 files changed, 24 insertions, 1 deletions
diff --git a/lua/vis.lua b/lua/vis.lua index 32fb2a1..5473f17 100644 --- a/lua/vis.lua +++ b/lua/vis.lua @@ -167,6 +167,7 @@ local events = { WIN_STATUS = "Event::WIN_STATUS", -- see @{win_status} TERM_CSI = "Event::TERM_CSI", -- see @{term_csi} PROCESS_RESPONSE = "Event::PROCESS_RESPONSE", -- see @{process_response} + UI_DRAW = "Event::UI_DRAW", -- see @{ui_draw} } events.file_close = function(...) events.emit(events.FILE_CLOSE, ...) end @@ -183,6 +184,7 @@ events.win_open = function(...) events.emit(events.WIN_OPEN, ...) end events.win_status = function(...) events.emit(events.WIN_STATUS, ...) end events.term_csi = function(...) events.emit(events.TERM_CSI, ...) end events.process_response = function(...) events.emit(events.PROCESS_RESPONSE, ...) end +events.ui_draw = function(...) events.emit(events.UI_DRAW, ...) end local handlers = {} @@ -2229,6 +2229,7 @@ int main(int argc, char *argv[]) { .win_highlight = vis_lua_win_highlight, .win_status = vis_lua_win_status, .term_csi = vis_lua_term_csi, + .ui_draw = vis_lua_ui_draw, }; vis = vis_new(ui_term_new(), &event); diff --git a/ui-terminal.c b/ui-terminal.c index 6ec1e41..09e618e 100644 --- a/ui-terminal.c +++ b/ui-terminal.c @@ -392,6 +392,7 @@ static void ui_draw(Ui *ui) { ui_window_draw((UiWin*)win); if (tui->info[0]) ui_draw_string(tui, 0, tui->height-1, tui->info, NULL, UI_STYLE_INFO); + vis_event_emit(tui->vis, VIS_EVENT_UI_DRAW); ui_term_backend_blit(tui); } @@ -236,6 +236,7 @@ enum VisEvents { VIS_EVENT_WIN_HIGHLIGHT, VIS_EVENT_WIN_STATUS, VIS_EVENT_TERM_CSI, + VIS_EVENT_UI_DRAW, }; bool vis_event_emit(Vis*, enum VisEvents, ...); @@ -166,7 +166,7 @@ void vis_lua_win_status(Vis *vis, Win *win) { window_status_update(vis, win); } void vis_lua_term_csi(Vis *vis, const long *csi) { } void vis_lua_process_response(Vis *vis, const char *name, char *buffer, size_t len, ResponseType rtype) { } - +void vis_lua_ui_draw(Vis *vis) { } #else @@ -3689,4 +3689,16 @@ void vis_lua_process_response(Vis *vis, const char *name, lua_pop(L, 1); } +/*** + * Emitted immediately before the UI is drawn to the screen. + * Allows last-minute overrides to the styling of UI elements. + * + * *WARNING:* This is emitted every screen draw! + * Use sparingly and check for `nil` values! + * @function ui_draw + */ +void vis_lua_ui_draw(Vis *vis) { + vis_lua_event_call(vis, "ui_draw"); +} + #endif @@ -42,5 +42,6 @@ void vis_lua_win_highlight(Vis*, Win*); void vis_lua_win_status(Vis*, Win*); void vis_lua_term_csi(Vis*, const long *); void vis_lua_process_response(Vis *, const char *, char *, size_t, ResponseType); +void vis_lua_ui_draw(Vis*); #endif @@ -105,6 +105,10 @@ bool vis_event_emit(Vis *vis, enum VisEvents id, ...) { if (vis->event->term_csi) vis->event->term_csi(vis, va_arg(ap, const long *)); break; + case VIS_EVENT_UI_DRAW: + if (vis->event->ui_draw) + vis->event->ui_draw(vis); + break; } va_end(ap); @@ -58,6 +58,7 @@ typedef struct { void (*win_highlight)(Vis*, Win*); void (*win_status)(Vis*, Win*); void (*term_csi)(Vis*, const long *); + void (*ui_draw)(Vis*); } VisEvent; /** Union used to pass arguments to key action functions. */ |
