commit abb4909
delthas
·
2024-07-17 11:14:26 +0000 UTC
parent eada435
Make nicks in the timeline clickable Fixes: https://todo.sr.ht/~delthas/senpai/92
3 files changed,
+36,
-2
M
app.go
+16,
-0
1@@ -503,6 +503,8 @@ func (app *App) handleUIEvent(ev interface{}) bool {
2 app.win.JumpBufferNetwork(ev.NetID, ev.Buffer)
3 case statusLine:
4 app.addStatusLine(ev.netID, ev.line)
5+ case *events.EventClickNick:
6+ app.handleNickEvent(ev)
7 case *events.EventClickLink:
8 app.handleLinkEvent(ev)
9 case *events.EventImageLoaded:
10@@ -825,6 +827,20 @@ func (app *App) handleKeyEvent(ev vaxis.Key) {
11 }
12 }
13
14+func (app *App) handleNickEvent(ev *events.EventClickNick) {
15+ s := app.sessions[ev.NetID]
16+ if s == nil {
17+ return
18+ }
19+ i, added := app.win.AddBuffer(ev.NetID, "", ev.Nick)
20+ app.win.JumpBufferIndex(i)
21+ if added {
22+ s.MonitorAdd(ev.Nick)
23+ s.ReadGet(ev.Nick)
24+ s.NewHistoryRequest(ev.Nick).WithLimit(500).Latest()
25+ }
26+}
27+
28 func (app *App) fetchImage(link string) (image.Image, error) {
29 c := http.Client{
30 Timeout: 6 * time.Second,
+16,
-1
1@@ -1032,7 +1032,22 @@ func (bs *BufferList) DrawTimeline(ui *UI, x0, y0, nickColWidth int) {
2 if line.Highlight {
3 identSt.Attribute |= vaxis.AttrReverse
4 }
5- printIdent(vx, x0+7, yi, nickColWidth, Styled(line.Head, identSt))
6+ xb, xe := printIdent(vx, x0+7, yi, nickColWidth, Styled(line.Head, identSt))
7+
8+ if !strings.HasSuffix(line.Head, "--") && !strings.HasSuffix(line.Head, "!!") {
9+ ui.clickEvents = append(ui.clickEvents, clickEvent{
10+ xb: xb,
11+ xe: xe,
12+ y: yi,
13+ event: &events.EventClickNick{
14+ EventClick: events.EventClick{
15+ NetID: b.netID,
16+ Buffer: b.title,
17+ },
18+ Nick: line.Head,
19+ },
20+ })
21+ }
22 }
23
24 x := x1
+4,
-1
1@@ -161,7 +161,7 @@ func printString(vx *Vaxis, x *int, y int, s StyledString) {
2 }
3 }
4
5-func printIdent(vx *Vaxis, x, y, width int, s StyledString) {
6+func printIdent(vx *Vaxis, x, y, width int, s StyledString) (xb int, xe int) {
7 s.string = truncate(vx, s.string, width, "\u2026")
8 x += width - stringWidth(vx, s.string)
9 var st vaxis.Style
10@@ -169,6 +169,7 @@ func printIdent(vx *Vaxis, x, y, width int, s StyledString) {
11 st = s.styles[0].Style
12 }
13 setCell(vx, x-1, y, ' ', st)
14+ xb = x
15 printString(vx, &x, y, s)
16 if len(s.styles) != 0 {
17 // TODO check if it's not a style that is from the truncated
18@@ -176,6 +177,8 @@ func printIdent(vx *Vaxis, x, y, width int, s StyledString) {
19 st = s.styles[len(s.styles)-1].Style
20 }
21 setCell(vx, x, y, ' ', st)
22+ xe = x
23+ return
24 }
25
26 func printNumber(vx *Vaxis, x *int, y int, st vaxis.Style, n int) {