commit e193ae4

delthas  ·  2024-07-19 13:53:22 +0000 UTC
parent 4c7c6de
Render formatting and links in topics
4 files changed,  +45, -6
M app.go
M app.go
+2, -2
 1@@ -1177,7 +1177,7 @@ func (app *App) handleIRCEvent(netID string, ev interface{}) {
 2 			app.win.JumpBufferIndex(i)
 3 		}
 4 		if ev.Topic != "" {
 5-			topic := ui.IRCString(ev.Topic).String()
 6+			topic := ui.IRCString(ev.Topic).ParseURLs()
 7 			app.win.SetTopic(netID, ev.Channel, topic)
 8 		}
 9 
10@@ -1214,7 +1214,7 @@ func (app *App) handleIRCEvent(netID string, ev interface{}) {
11 	case irc.TopicChangeEvent:
12 		line := app.formatEvent(ev)
13 		app.win.AddLine(netID, ev.Channel, line)
14-		topic := ui.IRCString(ev.Topic).String()
15+		topic := ui.IRCString(ev.Topic).ParseURLs()
16 		app.win.SetTopic(netID, ev.Channel, topic)
17 	case irc.ModeChangeEvent:
18 		if !app.cfg.StatusEnabled {
+41, -3
 1@@ -216,7 +216,7 @@ type buffer struct {
 2 	unreadSkip optional
 3 
 4 	lines []Line
 5-	topic string
 6+	topic StyledString
 7 
 8 	scrollAmt int // offset in lines from the bottom
 9 	isAtTop   bool
10@@ -538,7 +538,7 @@ func (bs *BufferList) SetFocused(focused bool) {
11 	}
12 }
13 
14-func (bs *BufferList) SetTopic(netID, title string, topic string) {
15+func (bs *BufferList) SetTopic(netID, title string, topic StyledString) {
16 	_, b := bs.at(netID, title)
17 	if b == nil {
18 		return
19@@ -961,7 +961,45 @@ func (bs *BufferList) DrawTimeline(ui *UI, x0, y0, nickColWidth int) {
20 	}
21 
22 	xTopic := x0
23-	printString(vx, &xTopic, y0, Styled(b.topic, vaxis.Style{}))
24+	{
25+		// TODO: factorize this (same code for drawing timeline)
26+
27+		var st vaxis.Style
28+		nextStyles := b.topic.styles
29+
30+		i := 0
31+		sr := []rune(b.topic.string)
32+		for len(sr) > 0 {
33+			if 0 < len(nextStyles) && nextStyles[0].Start == i {
34+				st = nextStyles[0].Style
35+				nextStyles = nextStyles[1:]
36+
37+				if bs.ui.mouseLinks && st.Hyperlink != "" && st.UnderlineStyle == 0 {
38+					st.UnderlineStyle = vaxis.UnderlineDotted
39+				}
40+			}
41+			dx, di := printCluster(vx, xTopic, y0, -1, sr, st)
42+			xTopic += dx
43+			i += len(string(sr[:di]))
44+			sr = sr[di:]
45+
46+			if st.Hyperlink != "" {
47+				ui.clickEvents = append(ui.clickEvents, clickEvent{
48+					xb: xTopic - dx,
49+					xe: xTopic,
50+					y:  y0,
51+					event: &events.EventClickLink{
52+						EventClick: events.EventClick{
53+							NetID:  b.netID,
54+							Buffer: b.title,
55+						},
56+						Link:  st.Hyperlink,
57+						Mouse: ui.mouseLinks,
58+					},
59+				})
60+			}
61+		}
62+	}
63 	y0++
64 	drawHorizontalLine(vx, x0, y0, bs.tlInnerWidth+nickColWidth+9)
65 	y0++
+1, -0
1@@ -157,6 +157,7 @@ func printString(vx *Vaxis, x *int, y int, s StyledString) {
2 		}
3 		dx, di := printCluster(vx, *x, y, -1, sr, st)
4 		*x += dx
5+		i += len(string(sr[:di]))
6 		sr = sr[di:]
7 	}
8 }
+1, -1
1@@ -461,7 +461,7 @@ func (ui *UI) SetFocused(focused bool) {
2 	ui.bs.SetFocused(focused)
3 }
4 
5-func (ui *UI) SetTopic(netID, buffer string, topic string) {
6+func (ui *UI) SetTopic(netID, buffer string, topic StyledString) {
7 	ui.bs.SetTopic(netID, buffer, topic)
8 }
9