commit e3066fa
delthas
·
2024-07-18 11:00:20 +0000 UTC
parent f52ab05
Support ctrl+click to open links on foot I don't really like ctrl+shift+o :P
4 files changed,
+48,
-6
M
app.go
+17,
-1
1@@ -571,7 +571,7 @@ func (app *App) handleMouseEvent(ev vaxis.Mouse) {
2 } else if x > w-app.win.MemberWidth() && y >= 2 {
3 app.win.ClickMember(y - 2 + app.win.MemberOffset())
4 } else {
5- app.win.Click(x, y)
6+ app.win.Click(x, y, ev)
7 }
8 }
9 if ev.Button == vaxis.MouseMiddleButton {
10@@ -591,6 +591,9 @@ func (app *App) handleMouseEvent(ev vaxis.Mouse) {
11 }
12 }
13 }
14+ if ev.Button == vaxis.MouseRightButton {
15+ app.win.Click(x, y, ev)
16+ }
17 }
18 if ev.EventType == vaxis.EventRelease {
19 if x < app.win.ChannelWidth()-1 {
20@@ -871,6 +874,19 @@ func (app *App) fetchImage(link string) (image.Image, error) {
21 }
22
23 func (app *App) handleLinkEvent(ev *events.EventClickLink) {
24+ if ev.Event.Modifiers == vaxis.ModCtrl {
25+ if strings.HasPrefix(ev.Link, "-") {
26+ // Avoid injection of parameters.
27+ // Sadly xdg-open does not support "--"...
28+ return
29+ }
30+ go func() {
31+ cmd := exec.Command("xdg-open", ev.Link)
32+ cmd.Run()
33+ }()
34+ return
35+ }
36+
37 app.imageLoading = true
38 go func() {
39 img, err := app.fetchImage(ev.Link)
+16,
-2
1@@ -1,12 +1,25 @@
2 package events
3
4-import "image"
5+import (
6+ "image"
7+
8+ "git.sr.ht/~rockorager/vaxis"
9+)
10+
11+type EventClickSetEvent interface {
12+ SetEvent(vaxis.Mouse)
13+}
14
15 type EventClick struct {
16+ Event vaxis.Mouse
17 NetID string
18 Buffer string
19 }
20
21+func (e *EventClick) SetEvent(ev vaxis.Mouse) {
22+ e.Event = ev
23+}
24+
25 type EventClickNick struct {
26 EventClick
27 Nick string
28@@ -14,7 +27,8 @@ type EventClickNick struct {
29
30 type EventClickLink struct {
31 EventClick
32- Link string
33+ Link string
34+ Mouse bool
35 }
36
37 type EventImageLoaded struct {
+6,
-1
1@@ -1061,6 +1061,10 @@ func (bs *BufferList) DrawTimeline(ui *UI, x0, y0, nickColWidth int) {
2 if 0 < len(nextStyles) && nextStyles[0].Start == lbi {
3 style = nextStyles[0].Style
4 nextStyles = nextStyles[1:]
5+
6+ if bs.ui.mouseLinks && style.Hyperlink != "" && style.UnderlineStyle == 0 {
7+ style.UnderlineStyle = vaxis.UnderlineDotted
8+ }
9 }
10 if 0 < len(nls) && lbi == nls[0] {
11 x = x1
12@@ -1100,7 +1104,8 @@ func (bs *BufferList) DrawTimeline(ui *UI, x0, y0, nickColWidth int) {
13 NetID: b.netID,
14 Buffer: b.title,
15 },
16- Link: style.Hyperlink,
17+ Link: style.Hyperlink,
18+ Mouse: ui.mouseLinks,
19 },
20 })
21 }
M
ui/ui.go
+9,
-2
1@@ -10,6 +10,7 @@ import (
2 "git.sr.ht/~rockorager/vaxis"
3 "git.sr.ht/~rockorager/vaxis/widgets/align"
4
5+ "git.sr.ht/~delthas/senpai/events"
6 "git.sr.ht/~delthas/senpai/irc"
7 )
8
9@@ -72,6 +73,8 @@ type UI struct {
10 clickEvents []clickEvent
11
12 image vaxis.Image
13+
14+ mouseLinks bool
15 }
16
17 func New(config Config) (ui *UI, err error) {
18@@ -106,6 +109,8 @@ func New(config Config) (ui *UI, err error) {
19 ui.vx.window.Clear()
20 ui.vx.ShowCursor(0, h-2, vaxis.CursorBeam)
21
22+ ui.mouseLinks = ui.config.LocalIntegrations && strings.HasPrefix(ui.vx.TerminalID(), "foot")
23+
24 ui.exit.Store(false)
25
26 ui.Events = make(chan any, 128)
27@@ -237,10 +242,12 @@ func (ui *UI) ClickMember(i int) {
28 ui.memberClicked = i
29 }
30
31-func (ui *UI) Click(x, y int) {
32+func (ui *UI) Click(x, y int, event vaxis.Mouse) {
33 for _, ev := range ui.clickEvents {
34 if x >= ev.xb && x < ev.xe && y == ev.y {
35- ui.Events <- ev.event
36+ e := ev.event
37+ e.(events.EventClickSetEvent).SetEvent(event)
38+ ui.Events <- e
39 break
40 }
41 }