diff options
author | Nicholas Marriott <nicm@cvs.openbsd.org> | 2015-09-25 23:30:13 +0000 |
---|---|---|
committer | Nicholas Marriott <nicm@cvs.openbsd.org> | 2015-09-25 23:30:13 +0000 |
commit | c31ad6e37725171169e916f7c9da090d64d732ca (patch) | |
tree | da24fea75191d8e58afaa5024ef56347ba6155ec | |
parent | 4b0708b6a0b1f5a239e6220d67bbca26400540b3 (diff) |
If the terminal has colors=256, only try to use setaf/setab if they
exist, reported by Filipe Brandenburger.
-rw-r--r-- | usr.bin/tmux/tty.c | 27 |
1 files changed, 17 insertions, 10 deletions
diff --git a/usr.bin/tmux/tty.c b/usr.bin/tmux/tty.c index 7e6b07e5950..37226f874d1 100644 --- a/usr.bin/tmux/tty.c +++ b/usr.bin/tmux/tty.c @@ -1,4 +1,4 @@ -/* $OpenBSD: tty.c,v 1.187 2015/09/02 17:43:25 nicm Exp $ */ +/* $OpenBSD: tty.c,v 1.188 2015/09/25 23:30:12 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net> @@ -1648,14 +1648,19 @@ tty_try_256(struct tty *tty, u_char colour, const char *type) char s[32]; /* - * If the terminfo entry has 256 colours, assume that setaf and setab - * work correctly. + * If the terminfo entry has 256 colours and setaf and setab exist, + * assume that they work correctly. */ if (tty->term->flags & TERM_256COLOURS) { - if (*type == '3') + if (*type == '3') { + if (!tty_term_has(tty->term, TTYC_SETAF)) + goto fallback; tty_putcode1(tty, TTYC_SETAF, colour); - else + } else { + if (!tty_term_has(tty->term, TTYC_SETAB)) + goto fallback; tty_putcode1(tty, TTYC_SETAB, colour); + } return (0); } @@ -1663,13 +1668,15 @@ tty_try_256(struct tty *tty, u_char colour, const char *type) * If the user has specified -2 to the client, setaf and setab may not * work, so send the usual sequence. */ - if (tty->term_flags & TERM_256COLOURS) { - xsnprintf(s, sizeof s, "\033[%s;5;%hhum", type, colour); - tty_puts(tty, s); - return (0); - } + if (tty->term_flags & TERM_256COLOURS) + goto fallback; return (-1); + +fallback: + xsnprintf(s, sizeof s, "\033[%s;5;%hhum", type, colour); + tty_puts(tty, s); + return (0); } void |