summaryrefslogtreecommitdiffstats
path: root/usr.bin/tmux/tty.c
diff options
context:
space:
mode:
authornicm <nicm@openbsd.org>2017-01-07 15:28:13 +0000
committernicm <nicm@openbsd.org>2017-01-07 15:28:13 +0000
commite16c16982e9481fc6dce130c45ab1780a392bdd7 (patch)
tree3f61c5ba44fc0732fbca89e3652017b23ab76bb4 /usr.bin/tmux/tty.c
parentAdd and remove some blank lines, in order to make X509_verify_cert() (diff)
downloadwireguard-openbsd-e16c16982e9481fc6dce130c45ab1780a392bdd7.tar.xz
wireguard-openbsd-e16c16982e9481fc6dce130c45ab1780a392bdd7.zip
Add support for the OSC 4 and OSC 104 palette setting escape sequences,
from S Gilles.
Diffstat (limited to 'usr.bin/tmux/tty.c')
-rw-r--r--usr.bin/tmux/tty.c38
1 files changed, 29 insertions, 9 deletions
diff --git a/usr.bin/tmux/tty.c b/usr.bin/tmux/tty.c
index 08877586c6c..e12f0e4fce7 100644
--- a/usr.bin/tmux/tty.c
+++ b/usr.bin/tmux/tty.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: tty.c,v 1.218 2016/12/07 09:16:55 nicm Exp $ */
+/* $OpenBSD: tty.c,v 1.219 2017/01/07 15:28:13 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com>
@@ -48,8 +48,10 @@ static void tty_cursor_pane(struct tty *, const struct tty_ctx *, u_int,
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_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,8 +1509,8 @@ tty_attributes(struct tty *tty, const struct grid_cell *gc,
}
/* Fix up the colours if necessary. */
- tty_check_fg(tty, &gc2);
- tty_check_bg(tty, &gc2);
+ 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,12 +1606,18 @@ tty_colours(struct tty *tty, const struct grid_cell *gc)
tty_colours_bg(tty, gc);
}
-void
-tty_check_fg(struct tty *tty, struct grid_cell *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,12 +1654,18 @@ tty_check_fg(struct tty *tty, struct grid_cell *gc)
}
}
-void
-tty_check_bg(struct tty *tty, struct grid_cell *gc)
+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,6 +1840,9 @@ tty_default_colours(struct grid_cell *gc, const struct window_pane *wp)
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,6 +1852,9 @@ tty_default_colours(struct grid_cell *gc, const struct window_pane *wp)
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];
}
}