=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/tmux/tty.c,v retrieving revision 1.218 retrieving revision 1.219 diff -c -r1.218 -r1.219 *** src/usr.bin/tmux/tty.c 2016/12/07 09:16:55 1.218 --- src/usr.bin/tmux/tty.c 2017/01/07 15:28:13 1.219 *************** *** 1,4 **** ! /* $OpenBSD: tty.c,v 1.218 2016/12/07 09:16:55 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott --- 1,4 ---- ! /* $OpenBSD: tty.c,v 1.219 2017/01/07 15:28:13 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott *************** *** 48,55 **** u_int); static void tty_colours(struct tty *, const struct grid_cell *); ! static void tty_check_fg(struct tty *, struct grid_cell *); ! static void tty_check_bg(struct tty *, struct grid_cell *); static void tty_colours_fg(struct tty *, const struct grid_cell *); static void tty_colours_bg(struct tty *, const struct grid_cell *); --- 48,57 ---- u_int); static void tty_colours(struct tty *, const struct grid_cell *); ! static void tty_check_fg(struct tty *, const struct window_pane *, ! struct grid_cell *); ! static void tty_check_bg(struct tty *, const struct window_pane *, ! struct grid_cell *); static void tty_colours_fg(struct tty *, const struct grid_cell *); static void tty_colours_bg(struct tty *, const struct grid_cell *); *************** *** 1507,1514 **** } /* Fix up the colours if necessary. */ ! tty_check_fg(tty, &gc2); ! tty_check_bg(tty, &gc2); /* If any bits are being cleared, reset everything. */ if (tc->attr & ~gc2.attr) --- 1509,1516 ---- } /* Fix up the colours if necessary. */ ! tty_check_fg(tty, wp, &gc2); ! tty_check_bg(tty, wp, &gc2); /* If any bits are being cleared, reset everything. */ if (tc->attr & ~gc2.attr) *************** *** 1604,1615 **** tty_colours_bg(tty, gc); } ! void ! tty_check_fg(struct tty *tty, struct grid_cell *gc) { u_char r, g, b; u_int colours; /* Is this a 24-bit colour? */ if (gc->fg & COLOUR_FLAG_RGB) { /* Not a 24-bit terminal? Translate to 256-colour palette. */ --- 1606,1623 ---- tty_colours_bg(tty, gc); } ! static void ! tty_check_fg(struct tty *tty, const struct window_pane *wp, ! struct grid_cell *gc) { u_char r, g, b; u_int colours; + /* 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]; + /* Is this a 24-bit colour? */ if (gc->fg & COLOUR_FLAG_RGB) { /* Not a 24-bit terminal? Translate to 256-colour palette. */ *************** *** 1646,1657 **** } } ! void ! tty_check_bg(struct tty *tty, struct grid_cell *gc) { u_char r, g, b; u_int colours; /* Is this a 24-bit colour? */ if (gc->bg & COLOUR_FLAG_RGB) { /* Not a 24-bit terminal? Translate to 256-colour palette. */ --- 1654,1671 ---- } } ! static void ! tty_check_bg(struct tty *tty, const struct window_pane *wp, ! struct grid_cell *gc) { u_char r, g, b; u_int colours; + /* 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]; + /* Is this a 24-bit colour? */ if (gc->bg & COLOUR_FLAG_RGB) { /* Not a 24-bit terminal? Translate to 256-colour palette. */ *************** *** 1826,1831 **** --- 1840,1848 ---- gc->fg = agc->fg; 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->bg == 8) { *************** *** 1835,1840 **** --- 1852,1860 ---- gc->bg = agc->bg; else gc->bg = wgc->bg; + + if (gc->bg != 8 && WINDOW_PANE_PALETTE_HAS(wp, gc->bg)) + gc->bg = wp->palette[gc->bg & 0xff]; } }