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.
This commit is contained in:
Daniel Eklöf 2021-02-13 13:41:27 +01:00
parent c600e131e2
commit ecbfc2bbe9
No known key found for this signature in database
GPG key ID: 5BBD4992C116573F

23
osc.c
View file

@ -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