| 1 | package termscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis/widgets/term`/ |
| 2 | |
| 3 | import ( |
| 4 | "encoding/base64scip-go gomod github.com/golang/go/src go1.18 `encoding/base64`/" |
| 5 | "fmtscip-go gomod github.com/golang/go/src go1.18 fmt/" |
| 6 | "git.sr.ht/~rockorager/vaxis/logscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis/log`/" |
| 7 | "stringsscip-go gomod github.com/golang/go/src go1.18 strings/" |
| 8 | ) |
| 9 | |
| 10 | func (vt *Modelscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis/widgets/term`/Model#) oscscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis/widgets/term`/Model#osc().(data string) { |
| 11 | selector, val, found := cutStringscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis/widgets/term`/cutString().(data, ";") |
| 12 | if !found { |
| 13 | return |
| 14 | } |
| 15 | switch selector { |
| 16 | case "0", "2": |
| 17 | vt.postEventscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis/widgets/term`/Model#postEvent().(EventTitlescip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis/widgets/term`/EventTitle#(val)) |
| 18 | case "8": |
| 19 | if vt.OSC8scip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis/widgets/term`/Model#OSC8. { |
| 20 | params, url, found := cutStringscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis/widgets/term`/cutString().(val, ";") |
| 21 | if !found { |
| 22 | return |
| 23 | } |
| 24 | vt.cursorscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis/widgets/term`/Model#cursor..Hyperlinkscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/Style#Hyperlink. = url |
| 25 | vt.cursorscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis/widgets/term`/Model#cursor..HyperlinkParamsscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/Style#HyperlinkParams. = params |
| 26 | } |
| 27 | case "9": |
| 28 | vt.postEventscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis/widgets/term`/Model#postEvent().(EventNotifyscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis/widgets/term`/EventNotify#{Bodyscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis/widgets/term`/EventNotify#Body.: val}) |
| 29 | case "11": |
| 30 | if val == "?" { |
| 31 | if vt.vxscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis/widgets/term`/Model#vx. == nil { |
| 32 | return |
| 33 | } |
| 34 | rgb := vt.vxscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis/widgets/term`/Model#vx..QueryBackgroundscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/Vaxis#QueryBackground().().Paramsscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/Color#Params().() |
| 35 | if len(rgb) == 0 { |
| 36 | return |
| 37 | } |
| 38 | resp := fmtscip-go gomod github.com/golang/go/src go1.18 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.18 fmt/Sprintf().("\x1b]11;rgb:%02x/%02x/%02x\x07", rgb[0], rgb[1], rgb[2]) |
| 39 | vt.ptyscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis/widgets/term`/Model#pty..WriteStringscip-go gomod github.com/golang/go/src go1.18 os/File#WriteString().(resp) |
| 40 | } |
| 41 | case "52": |
| 42 | _, val, _ := cutStringscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis/widgets/term`/cutString().(val, ";") |
| 43 | decodedBytes, err := base64scip-go gomod github.com/golang/go/src go1.18 `encoding/base64`/.StdEncodingscip-go gomod github.com/golang/go/src go1.18 `encoding/base64`/StdEncoding..DecodeStringscip-go gomod github.com/golang/go/src go1.18 `encoding/base64`/Encoding#DecodeString().(val) |
| 44 | if err != nil { |
| 45 | logscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis/log`/.Errorscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis/log`/Error().("[term] error decoding Base64") |
| 46 | return |
| 47 | } |
| 48 | vt.vxscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis/widgets/term`/Model#vx..ClipboardPushscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/Vaxis#ClipboardPush().(string(decodedBytes)) |
| 49 | case "777": |
| 50 | selector, val, found := cutStringscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis/widgets/term`/cutString().(val, ";") |
| 51 | if !found { |
| 52 | return |
| 53 | } |
| 54 | switch selector { |
| 55 | case "notify": |
| 56 | title, body, found := cutStringscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis/widgets/term`/cutString().(val, ";") |
| 57 | if !found { |
| 58 | return |
| 59 | } |
| 60 | vt.postEventscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis/widgets/term`/Model#postEvent().(EventNotifyscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis/widgets/term`/EventNotify#{ |
| 61 | Titlescip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis/widgets/term`/EventNotify#Title.: title, |
| 62 | Bodyscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis/widgets/term`/EventNotify#Body.: body, |
| 63 | }) |
| 64 | } |
| 65 | } |
| 66 | } |
| 67 | |
| 68 | // parses an osc8 payload into the URL and optional ID |
| 69 | func osc8scip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis/widgets/term`/osc8().(val string) (string, string) { |
| 70 | // OSC 8 ; params ; url ST |
| 71 | // params: key1=value1:key2=value2 |
| 72 | var id string |
| 73 | params, url, found := cutStringscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis/widgets/term`/cutString().(val, ";") |
| 74 | if !found { |
| 75 | return "", "" |
| 76 | } |
| 77 | for _, param := range stringsscip-go gomod github.com/golang/go/src go1.18 strings/.Splitscip-go gomod github.com/golang/go/src go1.18 strings/Split().(params, ":") { |
| 78 | key, val, found := cutStringscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis/widgets/term`/cutString().(param, "=") |
| 79 | if !found { |
| 80 | continue |
| 81 | } |
| 82 | switch key { |
| 83 | case "id": |
| 84 | id = val |
| 85 | } |
| 86 | } |
| 87 | return url, id |
| 88 | } |
| 89 | |
| 90 | // Copied from stdlib to here for go 1.16 compat |
| 91 | func cutStringscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis/widgets/term`/cutString().(s string, sep string) (before string, after string, found bool) { |
| 92 | if i := stringsscip-go gomod github.com/golang/go/src go1.18 strings/.Indexscip-go gomod github.com/golang/go/src go1.18 strings/Index().(s, sep); i >= 0 { |
| 93 | return s[:i], s[i+len(sep):], true |
| 94 | } |
| 95 | return s, "", false |
| 96 | } |