diff options
| author | Randy Palamar <randy@rnpnr.xyz> | 2023-10-19 07:19:00 -0600 |
|---|---|---|
| committer | Randy Palamar <randy@rnpnr.xyz> | 2024-03-25 21:09:42 -0600 |
| commit | 95bf9f59f8a9a37148bdc0787db378d62c7cd032 (patch) | |
| tree | 01c8c6e8f51260cef7fa048d0f7472ab93a4a327 /ui-terminal-curses.c | |
| parent | 49442e5178296a58f8ca2e267a93b89c5cca8e5b (diff) | |
| download | vis-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-curses.c')
| -rw-r--r-- | ui-terminal-curses.c | 27 |
1 files changed, 23 insertions, 4 deletions
diff --git a/ui-terminal-curses.c b/ui-terminal-curses.c index 0e7a4f1..b89d9b5 100644 --- a/ui-terminal-curses.c +++ b/ui-terminal-curses.c @@ -51,9 +51,13 @@ #define MAX_COLOR_CLOBBER 240 -static short color_clobber_idx = 0; -static uint32_t clobbering_colors[MAX_COLOR_CLOBBER]; static int change_colors = -1; +static short default_fg = -1; +static short default_bg = -1; + +static inline bool cell_color_equal(CellColor c1, CellColor c2) { + return c1 == c2; +} /* Calculate r,g,b components of one of the standard upper 240 colors */ static void get_6cube_rgb(unsigned int n, int *r, int *g, int *b) @@ -83,10 +87,13 @@ static void undo_palette(void) /* Work out the nearest color from the 256 color set, or perhaps exactly. */ static CellColor color_rgb(UiTerm *ui, uint8_t r, uint8_t g, uint8_t b) { + static short color_clobber_idx = 0; + static uint32_t clobbering_colors[MAX_COLOR_CLOBBER]; + if (change_colors == -1) change_colors = ui->vis->change_colors && can_change_color() && COLORS >= 256; if (change_colors) { - uint32_t hexrep = ((r << 16) | (g << 8) | b) + 1; + uint32_t hexrep = (r << 16) | (g << 8) | b; for (short i = 0; i < MAX_COLOR_CLOBBER; ++i) { if (clobbering_colors[i] == hexrep) return i + 16; @@ -170,7 +177,7 @@ static inline unsigned int color_pair_hash(short fg, short bg) { static short color_pair_get(short fg, short bg) { static bool has_default_colors; - static short *color2palette, default_fg, default_bg; + static short *color2palette; static short color_pairs_max, color_pair_current; if (!color2palette) { @@ -300,3 +307,15 @@ static void ui_curses_free(UiTerm *term) { bool is_default_color(CellColor c) { return c == CELL_COLOR_DEFAULT; } + +static bool is_default_bg(CellColor c) { + if (change_colors == 1) + return c == default_bg; + return is_default_color(c); +} + +static bool is_default_fg(CellColor c) { + if (change_colors == 1) + return c == default_fg; + return is_default_color(c); +} |
