-
Notifications
You must be signed in to change notification settings - Fork 0
/
osc.go
56 lines (52 loc) · 1.09 KB
/
osc.go
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
package tcellterm
import (
"strings"
)
func (vt *VT) osc(data string) {
selector, val, found := cutString(data, ";")
if !found {
return
}
switch selector {
case "0", "2":
ev := &EventTitle{
EventTerminal: newEventTerminal(vt),
title: val,
}
vt.postEvent(ev)
case "8":
if vt.OSC8 {
url, id := osc8(val)
vt.cursor.attrs = vt.cursor.attrs.Url(url)
vt.cursor.attrs = vt.cursor.attrs.UrlId(id)
}
}
}
// parses an osc8 payload into the URL and optional ID
func osc8(val string) (string, string) {
// OSC 8 ; params ; url ST
// params: key1=value1:key2=value2
var id string
params, url, found := cutString(val, ";")
if !found {
return "", ""
}
for _, param := range strings.Split(params, ":") {
key, val, found := cutString(param, "=")
if !found {
continue
}
switch key {
case "id":
id = val
}
}
return url, id
}
// Copied from stdlib to here for go 1.16 compat
func cutString(s string, sep string) (before string, after string, found bool) {
if i := strings.Index(s, sep); i >= 0 {
return s[:i], s[i+len(sep):], true
}
return s, "", false
}