This is an automated email from the git hooks/post-receive script.
git pushed a commit to branch tymux-10-quiet-head
in repository terminology.
View the commit online.
commit 31a6e056899ac5b73510aae1fd9297e1e47e88a8
Author: Boris Faure <[email protected]>
AuthorDate: Fri Oct 30 15:05:44 2026 +0000
termptyesc: answer OSC 4 colour queries
A palette query, OSC 4 ; c ; ?, is answered with the colour of the
textgrid's extended palette entry, one reply per '?', in request order.
The reply echoes the request's terminator, so that BEL in gets BEL out.
The reply writer takes a prefix and a terminator instead of a hardcoded
OSC number; OSC 10/11/12 keep ST for now. Their replies must be
switched to echoing in their own commit, as it moves their checksums.
Out of range: an index above 255 stops the parsing and drops the rest,
as does a missing spec. A non-numeric index and a bare OSC 4 are
errors, and the '4;' quirk dropping the rest of the sequence is gone
with the "cc - c < 3" check that came with it.
---
src/bin/termio.c | 21 ++++++++++++++
src/bin/termio.h | 3 ++
src/bin/termptyesc.c | 77 ++++++++++++++++++++++++++++++++++++++++++-------
src/bin/tytest_common.c | 15 ++++++++++
tests/osc-4-query.sh | 40 +++++++++++++++++++++++++
tests/tests.results | 1 +
6 files changed, 146 insertions(+), 11 deletions(-)
diff --git a/src/bin/termio.c b/src/bin/termio.c
index 50e7dd14..872e6ad9 100644
--- a/src/bin/termio.c
+++ b/src/bin/termio.c
@@ -196,6 +196,27 @@ termio_reset_main_colors(Evas_Object *termio)
termio_reset_fg_color(termio);
}
+Eina_Bool
+termio_palette_color_get(const Evas_Object *obj, int idx,
+ int *r, int *g, int *b)
+{
+ Termio *sd = evas_object_smart_data_get(obj);
+ int cr = 0, cg = 0, cb = 0, ca = 0;
+
+ if (!sd)
+ return EINA_FALSE;
+ if ((idx < 0) || (idx > 255))
+ return EINA_FALSE;
+ evas_object_textgrid_palette_get(
+ sd->grid.obj,
+ EVAS_TEXTGRID_PALETTE_EXTENDED, idx,
+ &cr, &cg, &cb, &ca);
+ *r = cr;
+ *g = cg;
+ *b = cb;
+ return EINA_TRUE;
+}
+
void
termio_fg_color_get(const Evas_Object *obj, int *r, int *g, int *b)
{
diff --git a/src/bin/termio.h b/src/bin/termio.h
index 37c97008..adbffbf2 100644
--- a/src/bin/termio.h
+++ b/src/bin/termio.h
@@ -109,4 +109,7 @@ void
termio_reset_cursor_color(Evas_Object *termio);
void
termio_reset_main_colors(Evas_Object *termio);
+Eina_Bool
+termio_palette_color_get(const Evas_Object *obj, int idx,
+ int *r, int *g, int *b);
#endif
diff --git a/src/bin/termptyesc.c b/src/bin/termptyesc.c
index 750786dd..0145ab85 100644
--- a/src/bin/termptyesc.c
+++ b/src/bin/termptyesc.c
@@ -4673,11 +4673,17 @@ _handle_xterm_777_command(Termpty *ty,
*title_end = ';';
}
+/* the reply echoes the request's terminator, as xterm does: BEL in,
+ * BEL out, ST in, ST out (ctlseqs.txt, "Terminator") */
static void
-_write_xterm_color_response(Termpty *ty, uint8_t number, int r, int g, int b)
+_write_xterm_color_response(Termpty *ty, const char *prefix,
+ int r, int g, int b, Eina_Bool bel)
{
char buf[64];
- int l = snprintf(buf, sizeof(buf), "\033]%d;rgb:%.2x%.2x/%.2x%.2x/%.2x%.2x\033\\", number, r, r, g, g, b, b);
+ int l = snprintf(buf, sizeof(buf),
+ "\033]%s;rgb:%.2x%.2x/%.2x%.2x/%.2x%.2x%s",
+ prefix, r, r, g, g, b, b,
+ bel ? "\007" : "\033\\");
termpty_write(ty, buf, l);
}
@@ -4696,7 +4702,7 @@ _handle_xterm_10_command(Termpty *ty, Eina_Unicode *p, int len)
int r, g, b;
termio_fg_color_get(ty->obj, &r, &g, &b);
- _write_xterm_color_response(ty, 10, r, g, b);
+ _write_xterm_color_response(ty, "10", r, g, b, EINA_FALSE);
}
else
{
@@ -4732,6 +4738,7 @@ _handle_xterm_set_color_class(Termpty *ty, Eina_Unicode *p, int len,
if (*p == '?')
{
int r = 0, g = 0, b = 0;
+ char pfx[8];
if (edje_object_color_class_get(obj, color_class, &r, &g, &b, NULL,
NULL, NULL, NULL, NULL,
@@ -4739,7 +4746,8 @@ _handle_xterm_set_color_class(Termpty *ty, Eina_Unicode *p, int len,
{
ERR("error getting color class '%s' on obj %p", color_class, obj);
}
- _write_xterm_color_response(ty, number, r, g, b);
+ snprintf(pfx, sizeof(pfx), "%u", (unsigned int)number);
+ _write_xterm_color_response(ty, pfx, r, g, b, EINA_FALSE);
}
else
{
@@ -5219,6 +5227,57 @@ found:
return cc + 1 - c;
}
+/* OSC 4: query (and, to come, set) palette colours. Each entry is
+ * "idx;spec", the spec running to the next ';' or to the end of the
+ * payload. An out-of-range index or a bad spec stops the parsing and
+ * drops the rest, as xterm does (misc.c, ChangeAnsiColorRequest) */
+static void
+_handle_osc_palette_set(Termpty *ty, Eina_Unicode *p, Eina_Bool bel)
+{
+ if (!p || !*p)
+ goto err;
+
+ while (*p)
+ {
+ Eina_Unicode *spec;
+ int idx, spec_len;
+
+ idx = _osc_arg_get(ty, &p);
+ if (idx < 0)
+ return;
+ if (idx > 255)
+ break;
+ spec = p;
+ while (*p && (*p != ';'))
+ p++;
+ spec_len = p - spec;
+
+ if ((spec_len == 1) && (*spec == '?'))
+ {
+ int r, g, b;
+ char pfx[16];
+
+ if (!termio_palette_color_get(ty->obj, idx, &r, &g, &b))
+ break;
+ snprintf(pfx, sizeof(pfx), "4;%d", idx);
+ _write_xterm_color_response(ty, pfx, r, g, b, bel);
+ }
+ else
+ {
+ WRN("set palette, not supported");
+ break;
+ }
+
+ if (!*p)
+ break;
+ p++;
+ }
+ return;
+
+err:
+ ty->decoding_error = EINA_TRUE;
+}
+
static int
_handle_esc_osc(Termpty *ty, const Eina_Unicode *c, const Eina_Unicode *ce)
{
@@ -5228,6 +5287,7 @@ _handle_esc_osc(Termpty *ty, const Eina_Unicode *c, const Eina_Unicode *ce)
int len = 0;
int arg;
int payload_len; /* the OSC string length, without its terminator */
+ Eina_Bool bel; /* the request was terminated by BEL, not ST */
cc = c;
p = buf;
@@ -5264,6 +5324,7 @@ _handle_esc_osc(Termpty *ty, const Eina_Unicode *c, const Eina_Unicode *ce)
payload_len = p - buf;
*p = '\0';
p = buf;
+ bel = (*cc == BEL);
if ((*cc == ST) || (*cc == BEL) || (*cc == '\\'))
cc++;
else
@@ -5334,13 +5395,7 @@ _handle_esc_osc(Termpty *ty, const Eina_Unicode *c, const Eina_Unicode *ce)
if (ty->cb.set_title.func) ty->cb.set_title.func(ty->cb.set_title.data);
break;
case 4:
- if (!p || !*p)
- goto err;
- // XXX: set palette entry. not supported.
- ty->decoding_error = EINA_TRUE;
- WRN("set palette, not supported");
- if ((cc - c) < 3)
- return 0;
+ _handle_osc_palette_set(ty, p, bel);
break;
case 7:
DBG("set working directory");
diff --git a/src/bin/tytest_common.c b/src/bin/tytest_common.c
index 96c65798..7bed22bb 100644
--- a/src/bin/tytest_common.c
+++ b/src/bin/tytest_common.c
@@ -452,6 +452,21 @@ termio_reset_main_colors(Evas_Object *termio)
termio_reset_fg_color(termio);
}
+Eina_Bool
+termio_palette_color_get(const Evas_Object *obj EINA_UNUSED, int idx,
+ int *r, int *g, int *b)
+{
+ unsigned char cr, cg, cb, ca;
+
+ if ((idx < 0) || (idx > 255))
+ return EINA_FALSE;
+ colors_256_get(idx, &cr, &cg, &cb, &ca);
+ *r = cr;
+ *g = cg;
+ *b = cb;
+ return EINA_TRUE;
+}
+
Eina_Bool
termio_bg_is_dark(const Evas_Object *obj EINA_UNUSED)
{
diff --git a/tests/osc-4-query.sh b/tests/osc-4-query.sh
new file mode 100644
index 00000000..c87277ff
--- /dev/null
+++ b/tests/osc-4-query.sh
@@ -0,0 +1,40 @@
+#!/bin/sh
+
+# OSC 4 queries: one reply per '?', in request order, echoing the
+# request's terminator (BEL in, BEL out; ST in, ST out)
+
+# BEL in, BEL out
+printf '\033]4;1;?\007'
+# ST in, ST out
+printf '\033]4;9;?\033\\'
+# cube and grey ramp ends
+printf '\033]4;16;?\007'
+printf '\033]4;231;?\007'
+printf '\033]4;255;?\007'
+# several queries in one sequence: one reply each, in order
+printf '\033]4;0;?;15;?;196;?\007'
+# opentui's burst: sixteen queries back to back
+i=0
+while [ $i -lt 16 ]; do
+ printf '\033]4;%d;?\007' "$i"
+ i=$((i + 1))
+done
+# out of range stops: only 3 is answered
+printf '\033]4;3;?;256;?;4;?\007'
+# non-numeric index stops: nothing
+printf '\033]4;x;?\007'
+# missing spec: nothing
+printf '\033]4;5\007'
+# bare OSC 4 and OSC 4; : nothing
+printf '\033]4\007'
+printf '\033]4;\007'
+
+## replies:
+# \e]4;1;rgb:c0c0/0000/0000\a
+# \e]4;9;rgb:ffff/8080/8080\e\
+# \e]4;16;rgb:0000/0000/0000\a
+# \e]4;231;rgb:ffff/ffff/ffff\a
+# \e]4;255;rgb:eeee/eeee/eeee\a
+# \e]4;0;rgb:0000/0000/0000\a \e]4;15;rgb:ffff/ffff/ffff\a \e]4;196;rgb:ffff/0000/0000\a
+# sixteen replies, for 0 to 15
+# \e]4;3;rgb:c0c0/0000/0000\a
diff --git a/tests/tests.results b/tests/tests.results
index c3408002..ce96df63 100644
--- a/tests/tests.results
+++ b/tests/tests.results
@@ -138,6 +138,7 @@ link_detection.sh 9b1fa98961f82d55d98ff9c00e2ee960
selection_with_tabs.sh 213c7c2d9a8acc731e0b326a88bb71ef
selection_empty_lines.sh 2ae3aa22572ef150457b63ed9a78efdc
osc-invalid.sh e5933e7dd49d52b80240e352f4ff8965
+osc-4-query.sh 931d15bee6dffe2631cd127d6528a733
osc-no-payload.sh 8aa7b12e298dfbeb5a48dcc48ea2f9a8
osc-colors-ris.sh b9cde87fbfcf5e02a0d906a8dee7dff3
osc-110-112.sh 15d223b8ed1276fdc5fe2a708bc3b3db
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.