summaryrefslogtreecommitdiffstats
path: root/tty.c
diff options
context:
space:
mode:
authornicm <nicm>2020-01-28 11:39:51 +0000
committernicm <nicm>2020-01-28 11:39:51 +0000
commita6129e99749d2bbc8b4a991c7b5d09300aa55f39 (patch)
treefcfccf41c309a9db3a8b3af30bc629bdb9169f4c /tty.c
parent84995ae1726589b5fb04e002e43496775e0ebfcd (diff)
If we can identify the terminal as iTerm2 or as tmux, we can be sure
they support 256 and RGB colours, so set those flags too.
Diffstat (limited to 'tty.c')
-rw-r--r--tty.c27
1 files changed, 15 insertions, 12 deletions
diff --git a/tty.c b/tty.c
index 3d58f05b..54c3be30 100644
--- a/tty.c
+++ b/tty.c
@@ -2386,11 +2386,10 @@ tty_check_fg(struct tty *tty, struct window_pane *wp, struct grid_cell *gc)
/* Is this a 24-bit colour? */
if (gc->fg & COLOUR_FLAG_RGB) {
/* Not a 24-bit terminal? Translate to 256-colour palette. */
- if (!tty_term_has(tty->term, TTYC_SETRGBF)) {
- colour_split_rgb(gc->fg, &r, &g, &b);
- gc->fg = colour_find_rgb(r, g, b);
- } else
+ if ((tty->term->flags|tty->term_flags) & TERM_RGBCOLOURS)
return;
+ colour_split_rgb(gc->fg, &r, &g, &b);
+ gc->fg = colour_find_rgb(r, g, b);
}
/* How many colours does this terminal have? */
@@ -2436,11 +2435,10 @@ tty_check_bg(struct tty *tty, struct window_pane *wp, struct grid_cell *gc)
/* Is this a 24-bit colour? */
if (gc->bg & COLOUR_FLAG_RGB) {
/* Not a 24-bit terminal? Translate to 256-colour palette. */
- if (!tty_term_has(tty->term, TTYC_SETRGBB)) {
- colour_split_rgb(gc->bg, &r, &g, &b);
- gc->bg = colour_find_rgb(r, g, b);
- } else
+ if ((tty->term->flags|tty->term_flags) & TERM_RGBCOLOURS)
return;
+ colour_split_rgb(gc->bg, &r, &g, &b);
+ gc->bg = colour_find_rgb(r, g, b);
}
/* How many colours does this terminal have? */
@@ -2617,15 +2615,14 @@ tty_try_colour(struct tty *tty, int colour, const char *type)
}
if (colour & COLOUR_FLAG_RGB) {
+ colour_split_rgb(colour & 0xffffff, &r, &g, &b);
if (*type == '3') {
if (!tty_term_has(tty->term, TTYC_SETRGBF))
- return (-1);
- colour_split_rgb(colour & 0xffffff, &r, &g, &b);
+ goto fallback_rgb;
tty_putcode3(tty, TTYC_SETRGBF, r, g, b);
} else {
if (!tty_term_has(tty->term, TTYC_SETRGBB))
- return (-1);
- colour_split_rgb(colour & 0xffffff, &r, &g, &b);
+ goto fallback_rgb;
tty_putcode3(tty, TTYC_SETRGBB, r, g, b);
}
return (0);
@@ -2638,6 +2635,12 @@ fallback_256:
log_debug("%s: 256 colour fallback: %s", tty->client->name, s);
tty_puts(tty, s);
return (0);
+
+fallback_rgb:
+ xsnprintf(s, sizeof s, "\033[%s;2;%d;%d;%dm", type, r, g, b);
+ log_debug("%s: RGB colour fallback: %s", tty->client->name, s);
+ tty_puts(tty, s);
+ return (0);
}
static void