From 5d702e6fbf75a1e0427694edc3d86f5a48e6a4cb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Mon, 20 Jan 2020 18:36:19 +0100 Subject: [PATCH] osc: implement OSC 12 and OSC 112 (set/reset text cursor color) --- foot.info | 2 ++ osc.c | 28 ++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/foot.info b/foot.info index 16327ca2..3e74caf2 100644 --- a/foot.info +++ b/foot.info @@ -26,6 +26,8 @@ foot+base|foot base fragment, it#8, lines#24, pairs#0x10000, + Cr=\E]112\007, + Cs=\E]12;%p1%s\007, acsc=``aaffggiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz{{||}}~~, bel=^G, blink=\E[5m, diff --git a/osc.c b/osc.c index d327d376..0b1d04d9 100644 --- a/osc.c +++ b/osc.c @@ -502,6 +502,27 @@ osc_dispatch(struct terminal *term) } case 12: /* Set cursor color */ + + /* Client queried for current value */ + if (strlen(string) == 1 && string[0] == '?') { + uint8_t r = (term->cursor_color.text >> 16) & 0xff; + uint8_t g = (term->cursor_color.text >> 8) & 0xff; + uint8_t b = (term->cursor_color.text >> 0) & 0xff; + + char reply[32]; + snprintf(reply, sizeof(reply), "\033]12;rgb:%02x/%02x/%02x\033\\", r, g, b); + term_to_slave(term, reply, strlen(reply)); + break; + } + + uint32_t color; + if (string[0] == '#' ? !parse_legacy_color(string, &color) : !parse_rgb(string, &color)) + break; + + LOG_INFO("change cursor color to %06x", color); + + term->cursor_color.cursor = 1 << 31 | color; + render_refresh(term); break; case 30: /* Set tab title */ @@ -557,6 +578,13 @@ osc_dispatch(struct terminal *term) render_refresh(term); break; + case 112: + LOG_DBG("resetting cursor color"); + term->cursor_color.text = term->default_cursor_color.text; + term->cursor_color.cursor = term->default_cursor_color.cursor; + render_refresh(term); + break; + case 555: osc_flash(term); break;