commit 96340f8

delthas  ·  2021-10-31 12:11:50 +0000 UTC
parent 19f6458
Show the current channel topic at the top of the timeline
3 files changed,  +42, -12
M app.go
M app.go
+2, -0
 1@@ -636,6 +636,7 @@ func (app *App) handleIRCEvent(netID string, ev interface{}) {
 2 			app.win.JumpBufferIndex(i)
 3 		}
 4 		if ev.Topic != "" {
 5+			app.win.SetTopic(netID, ev.Channel, ev.Topic)
 6 			app.printTopic(netID, ev.Channel)
 7 		}
 8 
 9@@ -695,6 +696,7 @@ func (app *App) handleIRCEvent(netID string, ev interface{}) {
10 	case irc.TopicChangeEvent:
11 		topic := ui.IRCString(ev.Topic).String()
12 		body := fmt.Sprintf("Topic changed to: %s", topic)
13+		app.win.SetTopic(netID, ev.Channel, ev.Topic)
14 		app.win.AddLine(netID, ev.Channel, ui.NotifyUnread, ui.Line{
15 			At:        msg.TimeOrNow(),
16 			Head:      "--",
+36, -12
 1@@ -179,6 +179,7 @@ type buffer struct {
 2 	unread     bool
 3 
 4 	lines []Line
 5+	topic string
 6 
 7 	scrollAmt int
 8 	isAtTop   bool
 9@@ -206,7 +207,7 @@ func NewBufferList() BufferList {
10 
11 func (bs *BufferList) ResizeTimeline(tlInnerWidth, tlHeight int) {
12 	bs.tlInnerWidth = tlInnerWidth
13-	bs.tlHeight = tlHeight
14+	bs.tlHeight = tlHeight - 2
15 }
16 
17 func (bs *BufferList) To(i int) bool {
18@@ -358,6 +359,15 @@ func (bs *BufferList) AddLines(netID, title string, before, after []Line) {
19 	}
20 }
21 
22+func (bs *BufferList) SetTopic(netID, title string, topic string) {
23+	idx := bs.idx(netID, title)
24+	if idx < 0 {
25+		return
26+	}
27+	b := &bs.list[idx]
28+	b.topic = topic
29+}
30+
31 func (bs *BufferList) Current() (netID, title string) {
32 	b := &bs.list[bs.current]
33 	return b.netID, b.title
34@@ -534,12 +544,22 @@ func (bs *BufferList) DrawHorizontalBufferList(screen tcell.Screen, x0, y0, widt
35 }
36 
37 func (bs *BufferList) DrawTimeline(screen tcell.Screen, x0, y0, nickColWidth int) {
38-	clearArea(screen, x0, y0, bs.tlInnerWidth+nickColWidth+9, bs.tlHeight)
39+	clearArea(screen, x0, y0, bs.tlInnerWidth+nickColWidth+9, bs.tlHeight+2)
40 
41 	b := &bs.list[bs.current]
42+
43+	xTopic := x0
44+	printString(screen, &xTopic, y0, Styled(b.topic, tcell.StyleDefault))
45+	y0++
46+	for x := x0; x < x0+bs.tlInnerWidth+nickColWidth+9; x++ {
47+		st := tcell.StyleDefault.Foreground(tcell.ColorGray)
48+		screen.SetContent(x, y0, 0x2500, nil, st)
49+	}
50+	y0++
51+
52 	yi := b.scrollAmt + y0 + bs.tlHeight
53 	for i := len(b.lines) - 1; 0 <= i; i-- {
54-		if yi < 0 {
55+		if yi < y0 {
56 			break
57 		}
58 
59@@ -552,15 +572,17 @@ func (bs *BufferList) DrawTimeline(screen tcell.Screen, x0, y0, nickColWidth int
60 			continue
61 		}
62 
63-		if i == 0 || b.lines[i-1].At.Truncate(time.Minute) != line.At.Truncate(time.Minute) {
64-			st := tcell.StyleDefault.Bold(true)
65-			printTime(screen, x0, yi, st, line.At.Local())
66-		}
67+		if yi >= y0 {
68+			if i == 0 || b.lines[i-1].At.Truncate(time.Minute) != line.At.Truncate(time.Minute) {
69+				st := tcell.StyleDefault.Bold(true)
70+				printTime(screen, x0, yi, st, line.At.Local())
71+			}
72 
73-		identSt := tcell.StyleDefault.
74-			Foreground(line.HeadColor).
75-			Reverse(line.Highlight)
76-		printIdent(screen, x0+7, yi, nickColWidth, Styled(line.Head, identSt))
77+			identSt := tcell.StyleDefault.
78+				Foreground(line.HeadColor).
79+				Reverse(line.Highlight)
80+			printIdent(screen, x0+7, yi, nickColWidth, Styled(line.Head, identSt))
81+		}
82 
83 		x := x1
84 		y := yi
85@@ -585,7 +607,9 @@ func (bs *BufferList) DrawTimeline(screen tcell.Screen, x0, y0, nickColWidth int
86 				continue
87 			}
88 
89-			screen.SetContent(x, y, r, nil, style)
90+			if yi >= y0 {
91+				screen.SetContent(x, y, r, nil, style)
92+			}
93 			x += runeWidth(r)
94 		}
95 	}
+4, -0
 1@@ -225,6 +225,10 @@ func (ui *UI) JumpBufferNetwork(netID, sub string) bool {
 2 	return false
 3 }
 4 
 5+func (ui *UI) SetTopic(netID, buffer string, topic string) {
 6+	ui.bs.SetTopic(netID, buffer, topic)
 7+}
 8+
 9 func (ui *UI) SetStatus(status string) {
10 	ui.status = status
11 }