aboutsummaryrefslogtreecommitdiff
path: root/osc.c
diff options
context:
space:
mode:
authorDaniel Eklöf <daniel@ekloef.se>2021-02-13 12:41:27 +0000
committerDaniel Eklöf <daniel@ekloef.se>2021-02-21 19:14:52 +0000
commitecbfc2bbe9b1964c8b2563b52618393d63dc40ce (patch)
tree1e9d44cf0d461bc36a37f6bf144d56fad264211e /osc.c
parentmain: initialize pseudo-random generator (diff)
osc: 8: parse params, and the ‘id’ parameter specifically
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.
Diffstat (limited to 'osc.c')
-rw-r--r--osc.c23
1 files changed, 22 insertions, 1 deletions
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 <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <errno.h>
@@ -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