mirror of
https://codeberg.org/dnkl/foot.git
synced 2026-02-04 04:06:06 -05:00
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:
parent
c600e131e2
commit
ecbfc2bbe9
1 changed files with 22 additions and 1 deletions
23
osc.c
23
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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue