diff options
author | delthas <delthas@dille.cc> | 2022-10-17 10:33:07 +0200 |
---|---|---|
committer | delthas <delthas@dille.cc> | 2022-10-17 10:33:07 +0200 |
commit | f254040916ad6888ae7fb28e6a5e6a5cfd1c810b (patch) | |
tree | cdd07428fb13557d8849478a195028e760675efa | |
parent | Switch to the upstream tcell implementation of OSC 8 hyperlink (diff) |
Add OSC 8 hyperlink IDs
OSC 8 hyperlink ID support was merged into tcell. We can now use those
IDs to help terminal emulators identify links spanning multiple lines,
possibly highlighting the whole link whe it is hovered, or creating a
single link hotkey for them.
-rw-r--r-- | cmd/senpai/main.go | 3 | ||||
-rw-r--r-- | go.mod | 4 | ||||
-rw-r--r-- | go.sum | 8 | ||||
-rw-r--r-- | ui/style.go | 10 |
4 files changed, 15 insertions, 10 deletions
diff --git a/cmd/senpai/main.go b/cmd/senpai/main.go index d177a8b..241c4c3 100644 --- a/cmd/senpai/main.go +++ b/cmd/senpai/main.go @@ -4,6 +4,7 @@ import ( "flag" "fmt" "io/ioutil" + "math/rand" "os" "os/signal" "path" @@ -24,6 +25,8 @@ func main() { flag.BoolVar(&debug, "debug", false, "show raw protocol data in the home buffer") flag.Parse() + rand.Seed(time.Now().UnixNano()) + if configPath == "" { configDir, err := os.UserConfigDir() if err != nil { @@ -4,8 +4,8 @@ go 1.16 require ( git.sr.ht/~emersion/go-scfg v0.0.0-20201019143924-142a8aa629fc - github.com/gdamore/tcell/v2 v2.5.4-0.20220911202027-96bb70f9efec - github.com/mattn/go-runewidth v0.0.13 + github.com/gdamore/tcell/v2 v2.5.4-0.20221017053904-7557ac2a6c89 + github.com/mattn/go-runewidth v0.0.14 golang.org/x/net v0.0.0-20220127200216-cd36cc0744dd golang.org/x/term v0.0.0-20210927222741-03fcf44c2211 golang.org/x/time v0.0.0-20210611083556-38a9dc6acbc6 @@ -4,8 +4,8 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/gdamore/encoding v1.0.0 h1:+7OoQ1Bc6eTm5niUzBa0Ctsh6JbMW6Ra+YNuAtDBdko= github.com/gdamore/encoding v1.0.0/go.mod h1:alR0ol34c49FCSBLjhosxzcPHQbf2trDkoo5dl+VrEg= -github.com/gdamore/tcell/v2 v2.5.4-0.20220911202027-96bb70f9efec h1:wvcbNOhEpZhHp4F9eIvB7fn0CDsQt9EXlHHyvxfb284= -github.com/gdamore/tcell/v2 v2.5.4-0.20220911202027-96bb70f9efec/go.mod h1:wSkrPaXoiIWZqW/g7Px4xc79di6FTcpB8tvaKJ6uGBo= +github.com/gdamore/tcell/v2 v2.5.4-0.20221017053904-7557ac2a6c89 h1:Q8/8bqReXToMTLZKmhNSQf6nabdAWcL0VtFz9DySzVc= +github.com/gdamore/tcell/v2 v2.5.4-0.20221017053904-7557ac2a6c89/go.mod h1:02iy8Omp2FMM0oDqEohCtRma57vIEg/mnw8zkEmDc6I= github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 h1:El6M4kTTCOh6aBiKaUGG7oYTSPP8MxqL4YI3kZKwcP4= github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510/go.mod h1:pupxD2MaaD3pAXIBCelhxNneeOaAeabZDe5s4K6zSpQ= github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= @@ -13,8 +13,8 @@ github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= github.com/lucasb-eyer/go-colorful v1.2.0 h1:1nnpGOrhyZZuNyfu1QjKiUICQ74+3FNCN69Aj6K7nkY= github.com/lucasb-eyer/go-colorful v1.2.0/go.mod h1:R4dSotOR9KMtayYi1e77YzuveK+i7ruzyGqttikkLy0= -github.com/mattn/go-runewidth v0.0.13 h1:lTGmDsbAYt5DmK6OnoV7EuIF1wEIFAcxld6ypU4OSgU= -github.com/mattn/go-runewidth v0.0.13/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w= +github.com/mattn/go-runewidth v0.0.14 h1:+xnbZSEeDbOIg5/mE6JF0w6n9duR1l3/WmbinWVwUuU= +github.com/mattn/go-runewidth v0.0.14/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w= github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA= github.com/rivo/uniseg v0.2.0 h1:S1pD9weZBuJdFmowNwbpi7BJ8TNftyUImj/0WQi72jY= github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc= diff --git a/ui/style.go b/ui/style.go index cb24304..506a03d 100644 --- a/ui/style.go +++ b/ui/style.go @@ -2,6 +2,7 @@ package ui import ( "fmt" + "math/rand" "net/url" "strconv" "strings" @@ -141,6 +142,7 @@ func (s StyledString) ParseURLs() StyledString { if u, err := url.Parse(link); err != nil || u.Scheme == "" { link = "https://" + link } + id := fmt.Sprintf("_%10d", rand.Int31()) // find last style starting before or at url begin for ; j < len(s.styles); j++ { st := s.styles[j] @@ -149,7 +151,7 @@ func (s StyledString) ParseURLs() StyledString { } if st.Start == ub { // a style already starts at this position, edit it - lastStyle.Style = lastStyle.Style.Url(link) + lastStyle.Style = lastStyle.Style.Url(link).UrlId(id) } lastStyle = st styles = append(styles, st) @@ -158,7 +160,7 @@ func (s StyledString) ParseURLs() StyledString { // no style existed at this position, add one from the last style styles = append(styles, rangedStyle{ Start: ub, - Style: lastStyle.Style.Url(link), + Style: lastStyle.Style.Url(link).UrlId(id), }) } // find last style starting before or at url end @@ -168,7 +170,7 @@ func (s StyledString) ParseURLs() StyledString { break } if st.Start < ue { - st.Style = st.Style.Url(link) + st.Style = st.Style.Url(link).UrlId(id) } lastStyle = st styles = append(styles, st) @@ -177,7 +179,7 @@ func (s StyledString) ParseURLs() StyledString { // no style existed at this position, add one from the last style without the hyperlink styles = append(styles, rangedStyle{ Start: ue, - Style: lastStyle.Style.Url(""), + Style: lastStyle.Style.Url("").UrlId(""), }) } } |