1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
|
#include "osc.h"
#include "../internal.h"
#include <stdlib.h>
#include <string.h>
static void osc7_cwd(struct term *t, const char *uri)
{
if (!term_has_prefix_ci(uri, "file://"))
return;
const char *p = uri + 7;
const char *slash = strchr(p, '/');
const char *path = slash ? slash : p;
char *cwd = malloc(strlen(path) + 1);
if (!cwd)
return;
char *d = cwd;
while (*path) {
int hi, lo;
if (*path == '%' && (hi = term_hex_nib(path[1])) >= 0 &&
(lo = term_hex_nib(path[2])) >= 0) {
*d++ = (char)(hi * 16 + lo);
path += 3;
} else {
*d++ = *path++;
}
}
*d = '\0';
free(t->cwd);
t->cwd = cwd;
}
static void osc777_notify(struct term *t, const char *params)
{
if (strncmp(params, "notify;", 7))
return;
const char *title = params + 7;
const char *sep = strchr(title, ';');
if (!sep)
return;
char *wsep = (char *)sep;
*wsep = '\0';
t->cb.notify(t->cb.ud, title, sep + 1);
*wsep = ';';
}
void term_osc_misc_dispatch(struct term *t, long code, const char *params)
{
if (!params)
return;
switch (code) {
case 7:
osc7_cwd(t, params);
break;
case 9:
if (t->cb.notify && strncmp(params, "4;", 2))
t->cb.notify(t->cb.ud, "wsap_term", params);
break;
case 22:
free(t->pointer_shape);
t->pointer_shape = *params ? term_strdup(params) : NULL;
break;
case 777:
if (t->cb.notify)
osc777_notify(t, params);
break;
default:
break;
}
}
|