From 33b2d68aa9c98b1c28f34bc6dc908b94b57083c6 Mon Sep 17 00:00:00 2001 From: Boris Faure Date: Sun, 26 May 2019 23:02:53 +0200 Subject: [PATCH] termptyesc: handle OSC 11 that reports background color It can also be used to set background color but that's not implemented --- src/bin/termptyesc.c | 40 +++++++++++++++++++++++++++++++++++----- src/bin/tyfuzz.c | 12 ++++++++---- tests/osc-11-query.sh | 6 ++++++ tests/tests.results | 1 + 4 files changed, 50 insertions(+), 9 deletions(-) create mode 100755 tests/osc-11-query.sh diff --git a/src/bin/termptyesc.c b/src/bin/termptyesc.c index f8f385ff..be37adf6 100644 --- a/src/bin/termptyesc.c +++ b/src/bin/termptyesc.c @@ -32,6 +32,10 @@ #define OSC 0x9d #define DEL 0x7f +#define TERMPTY_WRITE_STR(_S) \ + termpty_write(ty, _S, strlen(_S)) + + /* XXX: all handle_ functions return the number of bytes successfully read, 0 * if not enough bytes could be read */ @@ -3633,6 +3637,34 @@ _handle_xterm_777_command(Termpty *ty, *title_end = ';'; } +static void +_handle_xterm_11_command(Termpty *ty, Eina_Unicode *p) +{ + int r = 0, g = 0, b = 0; + char buf[32]; + size_t l; + + if (!*p) + goto err; + + /* only support query mode for the moment */ + if (*p != '?') + goto err; + + if (termpty_color_class_get(ty, "BG", &r, &g, &b, NULL) != 0) + { + ERR("error getting color class 'BG'"); + } + TERMPTY_WRITE_STR("\033]11;rgb:"); + l = snprintf(buf, sizeof(buf), "%.2X/%.2X/%.2X", r, g, b); + termpty_write(ty, buf, l); + TERMPTY_WRITE_STR("\007"); + + return; +err: + ty->decoding_error = EINA_TRUE; +} + static int _handle_esc_osc(Termpty *ty, const Eina_Unicode *c, const Eina_Unicode *ce) { @@ -3670,9 +3702,6 @@ _handle_esc_osc(Termpty *ty, const Eina_Unicode *c, const Eina_Unicode *ce) else return 0; -#define TERMPTY_WRITE_STR(_S) \ - termpty_write(ty, _S, strlen(_S)) - arg = _osc_arg_get(&p); switch (arg) { @@ -3777,6 +3806,9 @@ _handle_esc_osc(Termpty *ty, const Eina_Unicode *c, const Eina_Unicode *ce) #endif } break; + case 11: + _handle_xterm_11_command(ty, p); + break; case 50: DBG("xterm font support"); if (!*p) @@ -3804,8 +3836,6 @@ _handle_esc_osc(Termpty *ty, const Eina_Unicode *c, const Eina_Unicode *ce) break; } -#undef TERMPTY_WRITE_STR - return cc - c; err: WRN("invalid xterm sequence"); diff --git a/src/bin/tyfuzz.c b/src/bin/tyfuzz.c index 69281f12..e1c1d12a 100644 --- a/src/bin/tyfuzz.c +++ b/src/bin/tyfuzz.c @@ -233,10 +233,14 @@ termpty_color_class_get(Termpty *ty EINA_UNUSED, const char *key, { if (strncmp(key, "BG", strlen("BG")) == 0) { - *r = 131; - *g = 132; - *b = 133; - *a = 134; + if (r) + *r = 131; + if (g) + *g = 132; + if (b) + *b = 133; + if (a) + *a = 134; return 0; } return -1; diff --git a/tests/osc-11-query.sh b/tests/osc-11-query.sh new file mode 100755 index 00000000..f26cdf80 --- /dev/null +++ b/tests/osc-11-query.sh @@ -0,0 +1,6 @@ +#!/bin/sh + +# query background color +printf '\033]11;?\007' +sleep 0.1 +#should print ^]]11;rgb:83/84/85^G diff --git a/tests/tests.results b/tests/tests.results index d43b42fd..c4ae8508 100644 --- a/tests/tests.results +++ b/tests/tests.results @@ -121,3 +121,4 @@ mouse_reporting_mode_normal_ext_urxvt.sh bf68099047410f102e71d2e451875c69 mouse_reporting_mode_mouse_move_pressed_ext_urxvt.sh 59f3e59b60b3a43260de6a80135489eb mouse_reporting_mode_all_ext_urxvt.sh a11bbc8ebea42d06cc3ad823b52c09b3 shift_in_out.sh 3896bcc6887998bbc41b43840a6b2e33 +osc-11-query.sh fa4a07e289cc7b223404bb580dc413bf