diff options
author | Nicholas Marriott <nicm@cvs.openbsd.org> | 2020-08-19 06:37:24 +0000 |
---|---|---|
committer | Nicholas Marriott <nicm@cvs.openbsd.org> | 2020-08-19 06:37:24 +0000 |
commit | 08af00ae7de19a601b5ff3fd5acd53ba37a6a9b4 (patch) | |
tree | 73ccdda51e0352c8ecf3c7df74214f627d092f75 /usr.bin | |
parent | 8821fcd74d26c36c0ec3493419ad4acb68ab85b3 (diff) |
Respond to colour requests if a colour is available, from Michal Goral.
Diffstat (limited to 'usr.bin')
-rw-r--r-- | usr.bin/tmux/input.c | 46 |
1 files changed, 37 insertions, 9 deletions
diff --git a/usr.bin/tmux/input.c b/usr.bin/tmux/input.c index 659a1ec84ce..0110a6535d3 100644 --- a/usr.bin/tmux/input.c +++ b/usr.bin/tmux/input.c @@ -1,4 +1,4 @@ -/* $OpenBSD: input.c,v 1.182 2020/07/24 07:05:37 nicm Exp $ */ +/* $OpenBSD: input.c,v 1.183 2020/08/19 06:37:23 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com> @@ -65,7 +65,7 @@ struct input_param { INPUT_MISSING, INPUT_NUMBER, INPUT_STRING - } type; + } type; union { int num; char *str; @@ -81,7 +81,7 @@ struct input_ctx { struct input_cell cell; struct input_cell old_cell; - u_int old_cx; + u_int old_cx; u_int old_cy; int old_mode; @@ -121,7 +121,7 @@ struct input_ctx { * All input received since we were last in the ground state. Sent to * control clients on connection. */ - struct evbuffer *since_ground; + struct evbuffer *since_ground; }; /* Helper functions. */ @@ -2459,13 +2459,31 @@ input_osc_parse_colour(const char *p, u_int *r, u_int *g, u_int *b) return (1); } +/* Reply to a colour request. */ +static void +input_osc_colour_reply(struct input_ctx *ictx, u_int n, int c) +{ + u_char r, g, b; + const char *end; + + if (c == 8 || (~c & COLOUR_FLAG_RGB)) + return; + colour_split_rgb(c, &r, &g, &b); + + if (ictx->input_end == INPUT_END_BEL) + end = "\007"; + else + end = "\033\\"; + input_reply(ictx, "\033]%u;rgb:%02hhx/%02hhx/%02hhx%s", n, r, g, b, end); +} + /* Handle the OSC 4 sequence for setting (multiple) palette entries. */ static void input_osc_4(struct input_ctx *ictx, const char *p) { struct window_pane *wp = ictx->wp; char *copy, *s, *next = NULL; - long idx; + long idx; u_int r, g, b; if (wp == NULL) @@ -2497,17 +2515,22 @@ bad: free(copy); } -/* Handle the OSC 10 sequence for setting foreground colour. */ +/* Handle the OSC 10 sequence for setting and querying foreground colour. */ static void input_osc_10(struct input_ctx *ictx, const char *p) { struct window_pane *wp = ictx->wp; + struct grid_cell defaults; u_int r, g, b; if (wp == NULL) return; - if (strcmp(p, "?") == 0) + + if (strcmp(p, "?") == 0) { + tty_default_colours(&defaults, wp); + input_osc_colour_reply(ictx, 10, defaults.fg); return; + } if (!input_osc_parse_colour(p, &r, &g, &b)) goto bad; @@ -2520,17 +2543,22 @@ bad: log_debug("bad OSC 10: %s", p); } -/* Handle the OSC 11 sequence for setting background colour. */ +/* Handle the OSC 11 sequence for setting and querying background colour. */ static void input_osc_11(struct input_ctx *ictx, const char *p) { struct window_pane *wp = ictx->wp; + struct grid_cell defaults; u_int r, g, b; if (wp == NULL) return; - if (strcmp(p, "?") == 0) + + if (strcmp(p, "?") == 0) { + tty_default_colours(&defaults, wp); + input_osc_colour_reply(ictx, 11, defaults.bg); return; + } if (!input_osc_parse_colour(p, &r, &g, &b)) goto bad; |