summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Adam <thomas@xteddy.org>2020-01-28 12:01:28 +0000
committerThomas Adam <thomas@xteddy.org>2020-01-28 12:01:28 +0000
commit60ab7144517483d4343e7a68625e376c34557b8a (patch)
treea0ed2af485858723be0afbfba456f446aafbbd7a
parent685eb381dec7fc741a15ce11a84d8c96ed66ce42 (diff)
parenta6129e99749d2bbc8b4a991c7b5d09300aa55f39 (diff)
Merge branch 'obsd-master'
-rw-r--r--input.c8
-rw-r--r--tmux.h1
-rw-r--r--tty-keys.c6
-rw-r--r--tty-term.c28
-rw-r--r--tty.c27
5 files changed, 37 insertions, 33 deletions
diff --git a/input.c b/input.c
index a2c63e14..d7071bfe 100644
--- a/input.c
+++ b/input.c
@@ -1302,6 +1302,7 @@ input_csi_dispatch(struct input_ctx *ictx)
struct input_table_entry *entry;
int i, n, m;
u_int cx, bg = ictx->cell.cell.bg;
+ char *copy, *cp;
if (ictx->flags & INPUT_DISCARD)
return (0);
@@ -1433,6 +1434,13 @@ input_csi_dispatch(struct input_ctx *ictx)
case 6:
input_reply(ictx, "\033[%u;%uR", s->cy + 1, s->cx + 1);
break;
+ case 1337: /* Terminal version, from iTerm2. */
+ copy = xstrdup(getversion());
+ for (cp = copy; *cp != '\0'; cp++)
+ *cp = toupper((u_char)*cp);
+ input_reply(ictx, "\033[TMUX %sn", copy);
+ free(copy);
+ break;
default:
log_debug("%s: unknown '%c'", __func__, ictx->ch);
break;
diff --git a/tmux.h b/tmux.h
index 26bedf38..0248110a 100644
--- a/tmux.h
+++ b/tmux.h
@@ -1173,6 +1173,7 @@ struct tty_term {
#define TERM_NOXENL 0x2
#define TERM_DECSLRM 0x4
#define TERM_DECFRA 0x8
+#define TERM_RGBCOLOURS 0x10
int flags;
LIST_ENTRY(tty_term) entry;
diff --git a/tty-keys.c b/tty-keys.c
index 968f67ca..064f2172 100644
--- a/tty-keys.c
+++ b/tty-keys.c
@@ -1099,7 +1099,7 @@ tty_keys_device_status_report(struct tty *tty, const char *buf, size_t len,
return (-1);
if (len == 2)
return (1);
- if (buf[2] != 'I')
+ if (buf[2] != 'I' && buf[2] != 'T')
return (-1);
if (len == 3)
return (1);
@@ -1117,7 +1117,9 @@ tty_keys_device_status_report(struct tty *tty, const char *buf, size_t len,
/* Set terminal flags. */
if (strncmp(tmp, "ITERM2 ", 7) == 0)
- flags |= TERM_DECSLRM;
+ flags |= (TERM_DECSLRM|TERM_256COLOURS|TERM_RGBCOLOURS);
+ if (strncmp(tmp, "TMUX ", 5) == 0)
+ flags |= (TERM_256COLOURS|TERM_RGBCOLOURS);
log_debug("%s: received DSR %.*s", c->name, (int)*size, buf);
tty_set_flags(tty, flags);
diff --git a/tty-term.c b/tty-term.c
index 085ad933..e556df6f 100644
--- a/tty-term.c
+++ b/tty-term.c
@@ -528,11 +528,16 @@ tty_term_find(char *name, int fd, char **cause)
goto error;
}
- /* Figure out if we have 256 colours (or more). */
- if (tty_term_number(term, TTYC_COLORS) >= 256 ||
- tty_term_has(term, TTYC_RGB))
+ /* Set flag if terminal has 256 colours. */
+ if (tty_term_number(term, TTYC_COLORS) >= 256)
term->flags |= TERM_256COLOURS;
+ /* Set flag if terminal has RGB colours. */
+ if ((tty_term_flag(term, TTYC_TC) || tty_term_has(term, TTYC_RGB)) ||
+ (tty_term_has(term, TTYC_SETRGBF) &&
+ tty_term_has(term, TTYC_SETRGBB)))
+ term->flags |= TERM_RGBCOLOURS;
+
/*
* Terminals without xenl (eat newline glitch) wrap at at $COLUMNS - 1
* rather than $COLUMNS (the cursor can never be beyond $COLUMNS - 1).
@@ -567,22 +572,7 @@ tty_term_find(char *name, int fd, char **cause)
code->type = TTYCODE_STRING;
}
- /*
- * On terminals with RGB colour (Tc or RGB), fill in setrgbf and
- * setrgbb if they are missing.
- */
- if ((tty_term_flag(term, TTYC_TC) || tty_term_flag(term, TTYC_RGB)) &&
- !tty_term_has(term, TTYC_SETRGBF) &&
- !tty_term_has(term, TTYC_SETRGBB)) {
- code = &term->codes[TTYC_SETRGBF];
- code->value.string = xstrdup("\033[38;2;%p1%d;%p2%d;%p3%dm");
- code->type = TTYCODE_STRING;
- code = &term->codes[TTYC_SETRGBB];
- code->value.string = xstrdup("\033[48;2;%p1%d;%p2%d;%p3%dm");
- code->type = TTYCODE_STRING;
- }
-
- /* Log it. */
+ /* Log the capabilities. */
for (i = 0; i < tty_term_ncodes(); i++)
log_debug("%s%s", name, tty_term_describe(term, i));
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