diff options
| author | Laurence de Bruxelles <lfdebrux@gmail.com> | 2025-09-19 10:19:10 +0300 |
|---|---|---|
| committer | Randy Palamar <randy@rnpnr.xyz> | 2025-12-14 06:09:11 -0700 |
| commit | 992804cb27993d5de8e6830a8ab9268045ce6892 (patch) | |
| tree | b86c44c3154370d587c46050560516fcb10d9936 /view.c | |
| parent | 6c519e91c684838bebcc6d49d894af956f6815b4 (diff) | |
| download | vis-992804cb27993d5de8e6830a8ab9268045ce6892.tar.gz vis-992804cb27993d5de8e6830a8ab9268045ce6892.tar.xz | |
Use STYLE_WHITESPACE for spaces, newlines, and tabs
Allow theming the replacement characters shown for showspaces, showtabs,
and/or shownewlines.
Diffstat (limited to 'view.c')
| -rw-r--r-- | view.c | 23 |
1 files changed, 18 insertions, 5 deletions
@@ -266,6 +266,9 @@ static bool view_add_cell(View *view, const Cell *cell) { } static bool view_expand_tab(View *view, Cell *cell) { + Win *win = (Win *)((char *)view - offsetof(Win, view)); + ui_window_style_set(&win->vis->ui, win->id, cell, UI_STYLE_WHITESPACE, false); + cell->width = 1; int displayed_width = view->tabwidth - (view->col % view->tabwidth); @@ -287,6 +290,9 @@ static bool view_expand_newline(View *view, Cell *cell) { size_t lineno = view->line->lineno; const char *symbol = view->symbols[SYNTAX_SYMBOL_EOL]; + Win *win = (Win *)((char *)view - offsetof(Win, view)); + ui_window_style_set(&win->vis->ui, win->id, cell, UI_STYLE_WHITESPACE, false); + strncpy(cell->data, symbol, sizeof(cell->data) - 1); cell->width = 1; if (!view_add_cell(view, cell)) @@ -299,6 +305,15 @@ static bool view_expand_newline(View *view, Cell *cell) { return true; } +static bool view_expand_space(View *view, Cell *cell) { + Win *win = (Win *)((char *)view - offsetof(Win, view)); + ui_window_style_set(&win->vis->ui, win->id, cell, UI_STYLE_WHITESPACE, false); + + const char *symbol = view->symbols[SYNTAX_SYMBOL_SPACE]; + strncpy(cell->data, symbol, sizeof(cell->data) - 1); + return view_add_cell(view, cell); +} + /* try to add another character to the view, return whether there was space left */ static bool view_addch(View *view, Cell *cell) { if (!view->line) @@ -318,11 +333,9 @@ static bool view_addch(View *view, Cell *cell) { return view_expand_tab(view, cell); case '\n': return view_expand_newline(view, cell); - case ' ': { - const char *symbol = view->symbols[SYNTAX_SYMBOL_SPACE]; - strncpy(cell->data, symbol, sizeof(cell->data) - 1); - return view_add_cell(view, cell); - }} + case ' ': + return view_expand_space(view, cell); + } if (ch < 128 && !isprint(ch)) { /* non-printable ascii char, represent it as ^(char + 64) */ |
