From 03d7dba5d86afa797eac49e75d37554590ef66c3 Mon Sep 17 00:00:00 2001 From: nicm Date: Fri, 25 Sep 2015 23:30:12 +0000 Subject: [PATCH 1/2] If the terminal has colors=256, only try to use setaf/setab if they exist, reported by Filipe Brandenburger. --- tty.c | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/tty.c b/tty.c index c4dfde1d..7be952c8 100644 --- a/tty.c +++ b/tty.c @@ -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 From 695a591f8e9bce3fe3dd22a23a337f0fa548b543 Mon Sep 17 00:00:00 2001 From: nicm Date: Fri, 25 Sep 2015 23:30:24 +0000 Subject: [PATCH 2/2] Adding colors=256 to *256color* was always pretty stupid and now it won't work (without adding setaf@:setab@ too). --- options-table.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/options-table.c b/options-table.c index b9431483..cfec138d 100644 --- a/options-table.c +++ b/options-table.c @@ -107,8 +107,7 @@ const struct options_table_entry server_options_table[] = { { .name = "terminal-overrides", .type = OPTIONS_TABLE_STRING, - .default_str = "*256col*:colors=256" - ",xterm*:XT:Ms=\\E]52;%p1%s;%p2%s\\007" + .default_str = "xterm*:XT:Ms=\\E]52;%p1%s;%p2%s\\007" ":Cs=\\E]12;%p1%s\\007:Cr=\\E]112\\007" ":Ss=\\E[%p1%d q:Se=\\E[2 q,screen*:XT" },