aboutsummaryrefslogtreecommitdiff
path: root/ui-terminal.c
diff options
context:
space:
mode:
authorRandy Palamar <randy@rnpnr.xyz>2023-10-19 07:19:00 -0600
committerRandy Palamar <randy@rnpnr.xyz>2024-03-25 21:09:42 -0600
commit95bf9f59f8a9a37148bdc0787db378d62c7cd032 (patch)
tree01c8c6e8f51260cef7fa048d0f7472ab93a4a327 /ui-terminal.c
parent49442e5178296a58f8ca2e267a93b89c5cca8e5b (diff)
downloadvis-95bf9f59f8a9a37148bdc0787db378d62c7cd032.tar.gz
vis-95bf9f59f8a9a37148bdc0787db378d62c7cd032.tar.xz
ui: refactor style handling
The old style handling had a lot edge cases where one of the colours or the attribute wouldn't get applied correctly. This commit adds a new style_set() method to the Ui which should be called instead of manually touching a cell's style. This also means that the Cell struct can be made opaque since all the handling is now done inside the ui-terminal files. With this it is now viable to combine the light and dark 16 colour themes into a single base-16 theme. This theme works very well with the Linux virtual console and will now be the default theme regardless of if the terminal supports 256 colours or not. This should address the common complaints about vis not respecting the users default terminal colours. fixes #1151: Theming is sometimes partially applied or ignored see #1103: terminal no longer has transparency/opacity see #1040: Transparent background and setting options by default
Diffstat (limited to 'ui-terminal.c')
-rw-r--r--ui-terminal.c17
1 files changed, 14 insertions, 3 deletions
diff --git a/ui-terminal.c b/ui-terminal.c
index 264c6d3..cf34378 100644
--- a/ui-terminal.c
+++ b/ui-terminal.c
@@ -286,10 +286,21 @@ static void ui_window_draw(UiWin *w) {
}
}
-static CellStyle ui_window_style_get(UiWin *w, enum UiStyle style) {
+static void ui_window_style_set(UiWin *w, Cell *cell, enum UiStyle id) {
UiTermWin *win = (UiTermWin*)w;
UiTerm *tui = win->ui;
- return tui->styles[win->id * UI_STYLE_MAX + style];
+ CellStyle set, style = tui->styles[win->id * UI_STYLE_MAX + id];
+
+ if (id == UI_STYLE_DEFAULT) {
+ memcpy(&cell->style, &style, sizeof(CellStyle));
+ return;
+ }
+
+ set.fg = is_default_fg(style.fg)? cell->style.fg : style.fg;
+ set.bg = is_default_bg(style.bg)? cell->style.bg : style.bg;
+ set.attr = cell->style.attr | style.attr;
+
+ memcpy(&cell->style, &set, sizeof(CellStyle));
}
static void ui_window_status(UiWin *w, const char *status) {
@@ -520,7 +531,7 @@ static UiWin *ui_window_new(Ui *ui, Win *w, enum UiOption options) {
return NULL;
win->uiwin = (UiWin) {
- .style_get = ui_window_style_get,
+ .style_set = ui_window_style_set,
.status = ui_window_status,
.options_set = ui_window_options_set,
.options_get = ui_window_options_get,