diff options
| author | Rudy Dellomas III <dther@dther.xyz> | 2024-04-20 03:17:14 +1000 |
|---|---|---|
| committer | Randy Palamar <randy@rnpnr.xyz> | 2024-04-29 08:36:44 -0600 |
| commit | 62ccfe59ae63858dc5c21039e907a9277134d171 (patch) | |
| tree | dd068f380b40f85174f1d2c71441a4070caf153c /ui-terminal.c | |
| parent | 8be1f68ec8a8310109a9204ec9a8599614d8d623 (diff) | |
| download | vis-62ccfe59ae63858dc5c21039e907a9277134d171.tar.gz vis-62ccfe59ae63858dc5c21039e907a9277134d171.tar.xz | |
Add Lua function to Win for directly editing cell styling by position
Diffstat (limited to 'ui-terminal.c')
| -rw-r--r-- | ui-terminal.c | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/ui-terminal.c b/ui-terminal.c index dd04f76..6ec1e41 100644 --- a/ui-terminal.c +++ b/ui-terminal.c @@ -69,6 +69,9 @@ struct UiTermWin { #include "ui-terminal-vt100.c" #endif +/* helper macro for handling UiTerm.cells */ +#define CELL_AT_POS(UI, X, Y) (((UI)->cells) + (X) + ((Y) * (UI)->width)); + __attribute__((noreturn)) static void ui_die(Ui *ui, const char *msg, va_list ap) { UiTerm *tui = (UiTerm*)ui; ui_term_backend_free(tui); @@ -305,6 +308,17 @@ static void ui_window_style_set(UiWin *w, Cell *cell, enum UiStyle id) { memcpy(&cell->style, &set, sizeof(CellStyle)); } +static bool ui_window_style_set_pos(UiWin *w, int x, int y, enum UiStyle id) { + UiTermWin *win = (UiTermWin*)w; + UiTerm *tui = win->ui; + if (x < 0 || y < 0 || y >= win->height || x >= win->width) { + return false; + } + Cell *cell = CELL_AT_POS(tui, win->x + x, win->y + y) + ui_window_style_set(w, cell, id); + return true; +} + static void ui_window_status(UiWin *w, const char *status) { UiTermWin *win = (UiTermWin*)w; if (!(win->options & UI_OPTION_STATUSBAR)) @@ -534,6 +548,7 @@ static UiWin *ui_window_new(Ui *ui, Win *w, enum UiOption options) { win->uiwin = (UiWin) { .style_set = ui_window_style_set, + .style_set_pos = ui_window_style_set_pos, .status = ui_window_status, .options_set = ui_window_options_set, .options_get = ui_window_options_get, |
