termptyesc: handle OSC 11 that reports background color

It can also be used to set background color but that's not implemented
This commit is contained in:
Boris Faure 2019-05-26 23:02:53 +02:00
parent 7e677abfb9
commit 33b2d68aa9
4 changed files with 50 additions and 9 deletions

View File

@ -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");

View File

@ -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;

6
tests/osc-11-query.sh Executable file
View File

@ -0,0 +1,6 @@
#!/bin/sh
# query background color
printf '\033]11;?\007'
sleep 0.1
#should print ^]]11;rgb:83/84/85^G

View File

@ -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