summaryrefslogtreecommitdiff
path: root/ui
diff options
context:
space:
mode:
authordelthas <delthas@dille.cc>2022-10-17 10:33:07 +0200
committerdelthas <delthas@dille.cc>2022-10-17 10:33:07 +0200
commitf254040916ad6888ae7fb28e6a5e6a5cfd1c810b (patch)
treecdd07428fb13557d8849478a195028e760675efa /ui
parentSwitch 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.
Diffstat (limited to 'ui')
-rw-r--r--ui/style.go10
1 files changed, 6 insertions, 4 deletions
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(""),
})
}
}