diff options
author | Nicholas Marriott <nicm@cvs.openbsd.org> | 2018-02-04 10:10:40 +0000 |
---|---|---|
committer | Nicholas Marriott <nicm@cvs.openbsd.org> | 2018-02-04 10:10:40 +0000 |
commit | f5ba1de2dd00367b84591a19d477ef19fb8a2f29 (patch) | |
tree | 05cc945e38133aaeb26a2dadf879efe3e2ccf38e | |
parent | 1b54ca6acdc9689a7e6bf50054f359f95208d283 (diff) |
Upstream ncurses has introduced terminfo capabilities to specify RGB
colour ("true" or "direct" colour). These consist of new entries (such
as "xterm-direct") which have a different setaf/setab implementation,
colors and pairs set to 0x1000000 and 0x10000, and a new RGB flag.
The setaf/setab definitions seem to be geared towards what ncurses (or
emacs maybe) needs, in that the new versions do only ANSI and RGB
colours (they can't be used for the 256 colour palette); they rely on
the silly ISO colon-separated version of SGR; and they use a weird
multiplication scheme so they still only need one argument. The higher
values of colors and pairs require a recent ncurses to parse.
tmux can use the RGB flag to detect RGB colour support (keeping the old
Tc extension for backwards compatibility for now). However, as we still
want to send 256 colour information unchanged when possible, the new
setaf/setab are awkward. So when RGB is present, reserve setaf/setab
only for ANSI colours and use the escape sequences directly for 256 and
RGB colours. (To my knowledge no recent terminal uses unusual escape
sequences for these in any case.)
-rw-r--r-- | usr.bin/tmux/tmux.h | 3 | ||||
-rw-r--r-- | usr.bin/tmux/tty-term.c | 10 | ||||
-rw-r--r-- | usr.bin/tmux/tty.c | 15 |
3 files changed, 19 insertions, 9 deletions
diff --git a/usr.bin/tmux/tmux.h b/usr.bin/tmux/tmux.h index de30b0b9bfe..c868b198bd1 100644 --- a/usr.bin/tmux/tmux.h +++ b/usr.bin/tmux/tmux.h @@ -1,4 +1,4 @@ -/* $OpenBSD: tmux.h,v 1.816 2018/01/18 07:10:53 nicm Exp $ */ +/* $OpenBSD: tmux.h,v 1.817 2018/02/04 10:10:39 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com> @@ -399,6 +399,7 @@ enum tty_code_code { TTYC_MS, TTYC_OP, TTYC_REV, + TTYC_RGB, TTYC_RI, TTYC_RMACS, TTYC_RMCUP, diff --git a/usr.bin/tmux/tty-term.c b/usr.bin/tmux/tty-term.c index c6fd2a81487..22fff90b52a 100644 --- a/usr.bin/tmux/tty-term.c +++ b/usr.bin/tmux/tty-term.c @@ -1,4 +1,4 @@ -/* $OpenBSD: tty-term.c,v 1.57 2017/08/27 08:33:55 nicm Exp $ */ +/* $OpenBSD: tty-term.c,v 1.58 2018/02/04 10:10:39 nicm Exp $ */ /* * Copyright (c) 2008 Nicholas Marriott <nicholas.marriott@gmail.com> @@ -237,6 +237,7 @@ static const struct tty_term_code_entry tty_term_codes[] = { [TTYC_MS] = { TTYCODE_STRING, "Ms" }, [TTYC_OP] = { TTYCODE_STRING, "op" }, [TTYC_REV] = { TTYCODE_STRING, "rev" }, + [TTYC_RGB] = { TTYCODE_FLAG, "RGB" }, [TTYC_RI] = { TTYCODE_STRING, "ri" }, [TTYC_RMACS] = { TTYCODE_STRING, "rmacs" }, [TTYC_RMCUP] = { TTYCODE_STRING, "rmcup" }, @@ -525,8 +526,11 @@ tty_term_find(char *name, int fd, char **cause) code->type = TTYCODE_STRING; } - /* On terminals with RGB colour (TC), fill in setrgbf and setrgbb. */ - if (tty_term_flag(term, TTYC_TC) && + /* + * 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]; diff --git a/usr.bin/tmux/tty.c b/usr.bin/tmux/tty.c index b4c0f432f75..5fccc1ee1b0 100644 --- a/usr.bin/tmux/tty.c +++ b/usr.bin/tmux/tty.c @@ -1,4 +1,4 @@ -/* $OpenBSD: tty.c,v 1.299 2018/01/16 17:03:18 nicm Exp $ */ +/* $OpenBSD: tty.c,v 1.300 2018/02/04 10:10:39 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com> @@ -2051,11 +2051,15 @@ tty_try_colour(struct tty *tty, int colour, const char *type) if (colour & COLOUR_FLAG_256) { /* - * If the user has specified -2 to the client, setaf and setab - * may not work (or they may not want to use them), so send the - * usual sequence. + * If the user has specified -2 to the client (meaning + * TERM_256COLOURS is set), setaf and setab may not work (or + * they may not want to use them), so send the usual sequence. + * + * Also if RGB is set, setaf and setab do not support the 256 + * colour palette so use the sequences directly there too. */ - if (tty->term_flags & TERM_256COLOURS) + if ((tty->term_flags & TERM_256COLOURS) || + tty_term_has(tty->term, TTYC_RGB)) goto fallback_256; /* @@ -2096,6 +2100,7 @@ tty_try_colour(struct tty *tty, int colour, const char *type) fallback_256: xsnprintf(s, sizeof s, "\033[%s;5;%dm", type, colour & 0xff); + log_debug("%s: 256 colour fallback: %s", tty->client->name, s); tty_puts(tty, s); return (0); } |