From ecbfc2bbe9b1964c8b2563b52618393d63dc40ce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Sat, 13 Feb 2021 13:41:27 +0100 Subject: [PATCH] =?UTF-8?q?osc:=208:=20parse=20params,=20and=20the=20?= =?UTF-8?q?=E2=80=98id=E2=80=99=20parameter=20specifically?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Applications can assign an ID to the URL. This is used to associate the parts of a split up URL with each other: ╔═ file1 ════╗ ║ ╔═ file2 ═══╗ ║http://exa║Lorem ipsum║ ║le.com ║ dolor sit ║ ║ ║amet, conse║ ╚══════════║ctetur adip║ ╚═══════════╝ In the example above, ‘http://exa’ and ‘le.com’ are part of the same URL, but by necessity split up into two OSC-8 URLs. If the application sets the same ID for those two OSC-8 URLs, the terminal can ensure they are handled as one. --- osc.c | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/osc.c b/osc.c index 2f1cfe2b..fb4f15d6 100644 --- a/osc.c +++ b/osc.c @@ -1,5 +1,6 @@ #include "osc.h" +#include #include #include #include @@ -399,16 +400,36 @@ osc_uri(struct terminal *term, char *string) * time (e.g. when hovering over one of the parts with the mouse). */ - const char *params = string; + char *params = string; char *params_end = strchr(params, ';'); if (params_end == NULL) return; *params_end = '\0'; const char *uri = params_end + 1; + uint64_t id = (uint64_t)rand() << 32 | rand(); LOG_DBG("params=%s, URI=%s", params, uri); + char *ctx = NULL; + for (const char *key_value = strtok_r(params, ":", &ctx); + key_value != NULL; + key_value = strtok_r(NULL, ":", &ctx)) + { + const char *key = key_value; + char *operator = strchr(key_value, '='); + + if (operator == NULL) + continue; + *operator = '\0'; + + const char *value = operator + 1; + LOG_DBG("param: %s=%s", key, value); + + if (strcmp(key, "id") == 0) + id = (uintptr_t)value; + } + if (uri[0] == '\0') term_osc8_close(term); else