aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lua/vis.lua2
-rw-r--r--main.c1
-rw-r--r--ui-terminal.c1
-rw-r--r--vis-core.h1
-rw-r--r--vis-lua.c14
-rw-r--r--vis-lua.h1
-rw-r--r--vis.c4
-rw-r--r--vis.h1
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 = {}
diff --git a/main.c b/main.c
index 8e5ad42..8aa31c6 100644
--- a/main.c
+++ b/main.c
@@ -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);
}
diff --git a/vis-core.h b/vis-core.h
index 8d3980c..4f81e4c 100644
--- a/vis-core.h
+++ b/vis-core.h
@@ -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, ...);
diff --git a/vis-lua.c b/vis-lua.c
index 3d80293..91ee428 100644
--- a/vis-lua.c
+++ b/vis-lua.c
@@ -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
diff --git a/vis-lua.h b/vis-lua.h
index d622ff5..b4f3f51 100644
--- a/vis-lua.h
+++ b/vis-lua.h
@@ -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
diff --git a/vis.c b/vis.c
index e287405..0c05558 100644
--- a/vis.c
+++ b/vis.c
@@ -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);
diff --git a/vis.h b/vis.h
index b67d3c5..8287a45 100644
--- a/vis.h
+++ b/vis.h
@@ -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. */