commit d41d7c5

delthas  ·  2021-11-24 15:01:59 +0000 UTC
parent bbb92bb
Show the current channel topic at the top of the timeline
3 files changed,  +44, -14
M app.go
M app.go
+3, -1
 1@@ -674,7 +674,8 @@ func (app *App) handleIRCEvent(netID string, ev interface{}) {
 2 			app.win.JumpBufferIndex(i)
 3 		}
 4 		if ev.Topic != "" {
 5-			app.printTopic(netID, ev.Channel)
 6+			topic := ui.IRCString(ev.Topic).String()
 7+			app.win.SetTopic(netID, ev.Channel, topic)
 8 		}
 9 
10 		// Restore last buffer
11@@ -733,6 +734,7 @@ func (app *App) handleIRCEvent(netID string, ev interface{}) {
12 	case irc.TopicChangeEvent:
13 		topic := ui.IRCString(ev.Topic).String()
14 		body := fmt.Sprintf("Topic changed to: %s", topic)
15+		app.win.SetTopic(netID, ev.Channel, topic)
16 		app.win.AddLine(netID, ev.Channel, ui.NotifyUnread, ui.Line{
17 			At:        msg.TimeOrNow(),
18 			Head:      "--",
+37, -13
  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@@ -356,6 +357,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@@ -532,12 +542,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@@ -550,15 +570,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@@ -574,7 +596,7 @@ func (bs *BufferList) DrawTimeline(screen tcell.Screen, x0, y0, nickColWidth int
 86 				x = x1
 87 				y++
 88 				nls = nls[1:]
 89-				if bs.tlHeight <= y {
 90+				if y0+bs.tlHeight <= y {
 91 					break
 92 				}
 93 			}
 94@@ -583,7 +605,9 @@ func (bs *BufferList) DrawTimeline(screen tcell.Screen, x0, y0, nickColWidth int
 95 				continue
 96 			}
 97 
 98-			screen.SetContent(x, y, r, nil, style)
 99+			if y >= y0 {
100+				screen.SetContent(x, y, r, nil, style)
101+			}
102 			x += runeWidth(r)
103 		}
104 	}
+4, -0
 1@@ -231,6 +231,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 }