From b55f6925d360dcb8109b90b266c0e9c2fc625b0c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Sat, 13 Feb 2021 12:41:57 +0100 Subject: [PATCH] osc: parse OSC-8, by calling term_osc8_{open,close} as appropriate --- osc.c | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/osc.c b/osc.c index 801b04e9..2f1cfe2b 100644 --- a/osc.c +++ b/osc.c @@ -376,6 +376,45 @@ osc_set_pwd(struct terminal *term, char *string) free(host); } +static void +osc_uri(struct terminal *term, char *string) +{ + /* + * \E]8;;URI\e\\ + * + * Params are key=value pairs, separated by ‘:’. + * + * The only defined key (as of 2020-05-31) is ‘id’, which is used + * to group split-up URIs: + * + * ╔═ file1 ════╗ + * ║ ╔═ file2 ═══╗ + * ║http://exa║Lorem ipsum║ + * ║le.com ║ dolor sit ║ + * ║ ║amet, conse║ + * ╚══════════║ctetur adip║ + * ╚═══════════╝ + * + * This lets a terminal emulator highlight both parts at the same + * time (e.g. when hovering over one of the parts with the mouse). + */ + + const char *params = string; + char *params_end = strchr(params, ';'); + if (params_end == NULL) + return; + + *params_end = '\0'; + const char *uri = params_end + 1; + + LOG_DBG("params=%s, URI=%s", params, uri); + + if (uri[0] == '\0') + term_osc8_close(term); + else + term_osc8_open(term, uri); +} + static void osc_notify(struct terminal *term, char *string) { @@ -553,6 +592,10 @@ osc_dispatch(struct terminal *term) osc_set_pwd(term, string); break; + case 8: + osc_uri(term, string); + break; + case 10: case 11: { /* Set default foreground/background color */