From 8262b9c00bd1cfa50fb9b5a2416da7195becde90 Mon Sep 17 00:00:00 2001 From: nicm Date: Sun, 4 Aug 2024 09:35:30 +0000 Subject: [PATCH] The Linux console has some bugs with bright colours. It seems likely that it is emulating them by setting a bright (or bold) flag; however, when the colour is changed from a bright colour (say SGR 96) to a non-bright (say SGR 36), the flag is not reset, so the new colour remains as bright. SGR 39 (default colour) also does not reset, so you end up with the bright default colour. Work around this by sending SGR 0 when switching away from a bright colour, and disable AX for TERM=linux. Also make the check for AX simpler and do not check for the op capability is not actually used. GitHub issue 3976. --- usr.bin/tmux/options-table.c | 4 ++-- usr.bin/tmux/tty.c | 31 +++++++++++++++---------------- 2 files changed, 17 insertions(+), 18 deletions(-) diff --git a/usr.bin/tmux/options-table.c b/usr.bin/tmux/options-table.c index 760fadf61e8..f1e85609206 100644 --- a/usr.bin/tmux/options-table.c +++ b/usr.bin/tmux/options-table.c @@ -1,4 +1,4 @@ -/* $OpenBSD: options-table.c,v 1.174 2024/05/14 09:32:37 nicm Exp $ */ +/* $OpenBSD: options-table.c,v 1.175 2024/08/04 09:35:30 nicm Exp $ */ /* * Copyright (c) 2011 Nicholas Marriott @@ -398,7 +398,7 @@ const struct options_table_entry options_table[] = { .type = OPTIONS_TABLE_STRING, .scope = OPTIONS_TABLE_SERVER, .flags = OPTIONS_TABLE_IS_ARRAY, - .default_str = "", + .default_str = "linux*:AX@", .separator = ",", .text = "List of terminal capabilities overrides." }, diff --git a/usr.bin/tmux/tty.c b/usr.bin/tmux/tty.c index 3e1120c1f00..124cb357d62 100644 --- a/usr.bin/tmux/tty.c +++ b/usr.bin/tmux/tty.c @@ -1,4 +1,4 @@ -/* $OpenBSD: tty.c,v 1.436 2024/05/14 10:11:09 nicm Exp $ */ +/* $OpenBSD: tty.c,v 1.437 2024/08/04 09:35:30 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott @@ -2670,28 +2670,18 @@ tty_colours(struct tty *tty, const struct grid_cell *gc) */ if (COLOUR_DEFAULT(gc->fg) || COLOUR_DEFAULT(gc->bg)) { /* - * If don't have AX but do have op, send sgr0 (op can't - * actually be used because it is sometimes the same as sgr0 - * and sometimes isn't). This resets both colours to default. - * + * If don't have AX, send sgr0. This resets both colours to default. * Otherwise, try to set the default colour only as needed. */ - have_ax = tty_term_flag(tty->term, TTYC_AX); - if (!have_ax && tty_term_has(tty->term, TTYC_OP)) + if (!tty_term_flag(tty->term, TTYC_AX)) tty_reset(tty); else { if (COLOUR_DEFAULT(gc->fg) && !COLOUR_DEFAULT(tc->fg)) { - if (have_ax) - tty_puts(tty, "\033[39m"); - else if (tc->fg != 7) - tty_putcode_i(tty, TTYC_SETAF, 7); + tty_puts(tty, "\033[39m"); tc->fg = gc->fg; } if (COLOUR_DEFAULT(gc->bg) && !COLOUR_DEFAULT(tc->bg)) { - if (have_ax) - tty_puts(tty, "\033[49m"); - else if (tc->bg != 0) - tty_putcode_i(tty, TTYC_SETAB, 0); + tty_puts(tty, "\033[49m"); tc->bg = gc->bg; } } @@ -2703,7 +2693,7 @@ tty_colours(struct tty *tty, const struct grid_cell *gc) /* * Set the background colour. This must come after the foreground as - * tty_colour_fg() can call tty_reset(). + * tty_colours_fg() can call tty_reset(). */ if (!COLOUR_DEFAULT(gc->bg) && gc->bg != tc->bg) tty_colours_bg(tty, gc); @@ -2851,6 +2841,15 @@ tty_colours_fg(struct tty *tty, const struct grid_cell *gc) struct grid_cell *tc = &tty->cell; char s[32]; + /* + * If the current colour is an aixterm bright colour and the new is not, + * reset because some terminals do not clear bright correctly. + */ + if (tty->cell.fg >= 90 && + tty->cell.bg <= 97 && + (gc->fg < 90 || gc->fg > 97)) + tty_reset(tty); + /* Is this a 24-bit or 256-colour colour? */ if (gc->fg & COLOUR_FLAG_RGB || gc->fg & COLOUR_FLAG_256) { if (tty_try_colour(tty, gc->fg, "38") == 0) -- 2.20.1