-
Notifications
You must be signed in to change notification settings - Fork 38
/
osc.go
56 lines (48 loc) · 940 Bytes
/
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 terminal
import (
"log"
"os"
"fyne.io/fyne/v2/storage"
)
func (t *Terminal) handleOSC(code string) {
if len(code) <= 2 || code[1] != ';' {
return
}
switch code[0] {
case '0':
// set icon name, if Fyne supports in the future
t.setTitle(code[2:])
case '1':
// set icon name, if Fyne supports in the future
case '2':
t.setTitle(code[2:])
case '7':
t.setDirectory(code[2:])
default:
if t.debug {
log.Println("Unrecognised OSC:", code)
}
}
}
func (t *Terminal) setDirectory(uri string) {
u, err := storage.ParseURI(uri)
if err != nil {
// working around a Fyne bug where file URI does not parse host
off := 4
count := 0
for count < 3 && off < len(uri) {
off++
if uri[off] == '/' {
count++
}
}
os.Chdir(uri[off:])
return
}
// fallback to guessing it's a path
os.Chdir(u.Path())
}
func (t *Terminal) setTitle(title string) {
t.config.Title = title
t.onConfigure()
}