From 9e786030df1e68428fb2fdfa00a26c367ebb475c Mon Sep 17 00:00:00 2001 From: nicm Date: Thu, 12 Jan 2017 00:19:32 +0000 Subject: [PATCH 1/3] Fix setting the palette of aixterm colours (90-97). --- screen-write.c | 2 +- tmux.h | 6 +----- tty.c | 21 +++++++++++++-------- window.c | 28 ++++++++++++++++++++++++---- 4 files changed, 39 insertions(+), 18 deletions(-) diff --git a/screen-write.c b/screen-write.c index 0fe23df8..227316cb 100644 --- a/screen-write.c +++ b/screen-write.c @@ -1049,7 +1049,7 @@ screen_write_cell(struct screen_write_ctx *ctx, const struct grid_cell *gc) width = gc->data.width; /* - * If this is a wide character and there is no room on the screen, for + * If this is a wide character and there is no room on the screen for * the entire character, don't print it. */ if (!(s->mode & MODE_WRAP) && (width > 1 && diff --git a/tmux.h b/tmux.h index 3108f81e..e63b51b7 100644 --- a/tmux.h +++ b/tmux.h @@ -860,11 +860,6 @@ struct window_pane { TAILQ_HEAD(window_panes, window_pane); RB_HEAD(window_pane_tree, window_pane); -#define WINDOW_PANE_PALETTE_HAS(wp, c) \ - ((wp) != NULL && (wp)->palette != NULL && \ - ((c) < 0x100 || (c) & COLOUR_FLAG_256) && \ - (wp)->palette[(c) & 0xff] != 0) - /* Window structure. */ struct window { u_int id; @@ -2157,6 +2152,7 @@ void window_set_name(struct window *, const char *); void window_remove_ref(struct window *); void winlink_clear_flags(struct winlink *); int winlink_shuffle_up(struct session *, struct winlink *); +int window_pane_get_palette(const struct window_pane *, int); /* layout.c */ u_int layout_count_cells(struct layout_cell *); diff --git a/tty.c b/tty.c index d1a72599..dcf5e181 100644 --- a/tty.c +++ b/tty.c @@ -1609,11 +1609,12 @@ tty_check_fg(struct tty *tty, const struct window_pane *wp, { u_char r, g, b; u_int colours; + int c; /* Perform substitution if this pane has a palette */ if ((~gc->flags & GRID_FLAG_NOPALETTE) && - gc->fg != 8 && WINDOW_PANE_PALETTE_HAS(wp, gc->fg)) - gc->fg = wp->palette[gc->fg & 0xff]; + (c = window_pane_get_palette(wp, gc->fg)) != -1) + gc->fg = c; /* Is this a 24-bit colour? */ if (gc->fg & COLOUR_FLAG_RGB) { @@ -1657,11 +1658,12 @@ tty_check_bg(struct tty *tty, const struct window_pane *wp, { u_char r, g, b; u_int colours; + int c; /* Perform substitution if this pane has a palette */ if ((~gc->flags & GRID_FLAG_NOPALETTE) && - gc->bg != 8 && WINDOW_PANE_PALETTE_HAS(wp, gc->bg)) - gc->bg = wp->palette[gc->bg & 0xff]; + (c = window_pane_get_palette(wp, gc->bg)) != -1) + gc->bg = c; /* Is this a 24-bit colour? */ if (gc->bg & COLOUR_FLAG_RGB) { @@ -1817,6 +1819,7 @@ tty_default_colours(struct grid_cell *gc, const struct window_pane *wp) struct window *w = wp->window; struct options *oo = w->options; const struct grid_cell *agc, *pgc, *wgc; + int c; if (w->flags & WINDOW_STYLECHANGED) { w->flags &= ~WINDOW_STYLECHANGED; @@ -1838,8 +1841,9 @@ tty_default_colours(struct grid_cell *gc, const struct window_pane *wp) else gc->fg = wgc->fg; - if (gc->fg != 8 && WINDOW_PANE_PALETTE_HAS(wp, gc->fg)) - gc->fg = wp->palette[gc->fg & 0xff]; + if (gc->fg != 8 && + (c = window_pane_get_palette(wp, gc->fg)) != -1) + gc->fg = c; } if (gc->bg == 8) { @@ -1850,8 +1854,9 @@ tty_default_colours(struct grid_cell *gc, const struct window_pane *wp) else gc->bg = wgc->bg; - if (gc->bg != 8 && WINDOW_PANE_PALETTE_HAS(wp, gc->bg)) - gc->bg = wp->palette[gc->bg & 0xff]; + if (gc->bg != 8 && + (c = window_pane_get_palette(wp, gc->bg)) != -1) + gc->bg = c; } } diff --git a/window.c b/window.c index 57df3a12..cd4af43a 100644 --- a/window.c +++ b/window.c @@ -464,12 +464,12 @@ window_redraw_active_switch(struct window *w, struct window_pane *wp) * If the now active or inactive pane do not have a custom style or if * the palette is different, they need to be redrawn. */ - if (WINDOW_PANE_PALETTE_HAS(w->active, w->active->colgc.fg) || - WINDOW_PANE_PALETTE_HAS(w->active, w->active->colgc.bg) || + if (window_pane_get_palette(w->active, w->active->colgc.fg) != -1 || + window_pane_get_palette(w->active, w->active->colgc.bg) != -1 || style_equal(&grid_default_cell, &w->active->colgc)) w->active->flags |= PANE_REDRAW; - if (WINDOW_PANE_PALETTE_HAS(wp, wp->colgc.fg) || - WINDOW_PANE_PALETTE_HAS(wp, wp->colgc.bg) || + if (window_pane_get_palette(wp, wp->colgc.fg) != -1 || + window_pane_get_palette(wp, wp->colgc.bg) != -1 || style_equal(&grid_default_cell, &wp->colgc)) wp->flags |= PANE_REDRAW; } @@ -1517,3 +1517,23 @@ winlink_shuffle_up(struct session *s, struct winlink *wl) return (idx); } + +int +window_pane_get_palette(const struct window_pane *wp, int c) +{ + int new; + + if (wp == NULL || wp->palette == NULL) + return (-1); + + new = -1; + if (c < 8) + new = wp->palette[c]; + else if (c >= 90 && c <= 97) + new = wp->palette[7 + c - 90]; + else if (c & COLOUR_FLAG_256) + new = wp->palette[c & ~COLOUR_FLAG_256]; + if (new == 0) + return (-1); + return (new); +} From 0752fdaf6aaba298bdb7e4ba241d481c531c2b64 Mon Sep 17 00:00:00 2001 From: nicm Date: Thu, 12 Jan 2017 00:24:28 +0000 Subject: [PATCH 2/3] Erm the aixterm colours should start at 8, not 7. --- window.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/window.c b/window.c index cd4af43a..454b5a45 100644 --- a/window.c +++ b/window.c @@ -1530,7 +1530,7 @@ window_pane_get_palette(const struct window_pane *wp, int c) if (c < 8) new = wp->palette[c]; else if (c >= 90 && c <= 97) - new = wp->palette[7 + c - 90]; + new = wp->palette[8 + c - 90]; else if (c & COLOUR_FLAG_256) new = wp->palette[c & ~COLOUR_FLAG_256]; if (new == 0) From 9b6aeacdc0118d97c35e822c958e925f12b513ed Mon Sep 17 00:00:00 2001 From: nicm Date: Thu, 12 Jan 2017 00:30:41 +0000 Subject: [PATCH 3/3] aixterm colours can be used if -2 is given, as well as if TERM tells us the terminal has >=16 colours. --- tty.c | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/tty.c b/tty.c index dcf5e181..59a8a93f 100644 --- a/tty.c +++ b/tty.c @@ -1625,13 +1625,17 @@ tty_check_fg(struct tty *tty, const struct window_pane *wp, } else return; } - colours = tty_term_number(tty->term, TTYC_COLORS); + + /* How many colours does this terminal have? */ + if ((tty->term->flags|tty->term_flags) & TERM_256COLOURS) + colours = 256; + else + colours = tty_term_number(tty->term, TTYC_COLORS); /* Is this a 256-colour colour? */ if (gc->fg & COLOUR_FLAG_256) { /* And not a 256 colour mode? */ - if (!(tty->term->flags & TERM_256COLOURS) && - !(tty->term_flags & TERM_256COLOURS)) { + if (colours != 256) { gc->fg = colour_256to16(gc->fg); if (gc->fg & 8) { gc->fg &= 7; @@ -1674,7 +1678,12 @@ tty_check_bg(struct tty *tty, const struct window_pane *wp, } else return; } - colours = tty_term_number(tty->term, TTYC_COLORS); + + /* How many colours does this terminal have? */ + if ((tty->term->flags|tty->term_flags) & TERM_256COLOURS) + colours = 256; + else + colours = tty_term_number(tty->term, TTYC_COLORS); /* Is this a 256-colour colour? */ if (gc->bg & COLOUR_FLAG_256) { @@ -1683,8 +1692,7 @@ tty_check_bg(struct tty *tty, const struct window_pane *wp, * palette. Bold background doesn't exist portably, so just * discard the bold bit if set. */ - if (!(tty->term->flags & TERM_256COLOURS) && - !(tty->term_flags & TERM_256COLOURS)) { + if (colours != 256) { gc->bg = colour_256to16(gc->bg); if (gc->bg & 8) { gc->bg &= 7;