From 96340f8c4d91f59f6e39767891f9bb52d7fad329 Mon Sep 17 00:00:00 2001 From: delthas Date: Sun, 31 Oct 2021 13:11:50 +0100 Subject: Show the current channel topic at the top of the timeline --- ui/buffers.go | 48 ++++++++++++++++++++++++++++++++++++------------ 1 file changed, 36 insertions(+), 12 deletions(-) (limited to 'ui/buffers.go') diff --git a/ui/buffers.go b/ui/buffers.go index 3e13302..a087a81 100644 --- a/ui/buffers.go +++ b/ui/buffers.go @@ -179,6 +179,7 @@ type buffer struct { unread bool lines []Line + topic string scrollAmt int isAtTop bool @@ -206,7 +207,7 @@ func NewBufferList() BufferList { func (bs *BufferList) ResizeTimeline(tlInnerWidth, tlHeight int) { bs.tlInnerWidth = tlInnerWidth - bs.tlHeight = tlHeight + bs.tlHeight = tlHeight - 2 } func (bs *BufferList) To(i int) bool { @@ -358,6 +359,15 @@ func (bs *BufferList) AddLines(netID, title string, before, after []Line) { } } +func (bs *BufferList) SetTopic(netID, title string, topic string) { + idx := bs.idx(netID, title) + if idx < 0 { + return + } + b := &bs.list[idx] + b.topic = topic +} + func (bs *BufferList) Current() (netID, title string) { b := &bs.list[bs.current] return b.netID, b.title @@ -534,12 +544,22 @@ func (bs *BufferList) DrawHorizontalBufferList(screen tcell.Screen, x0, y0, widt } func (bs *BufferList) DrawTimeline(screen tcell.Screen, x0, y0, nickColWidth int) { - clearArea(screen, x0, y0, bs.tlInnerWidth+nickColWidth+9, bs.tlHeight) + clearArea(screen, x0, y0, bs.tlInnerWidth+nickColWidth+9, bs.tlHeight+2) b := &bs.list[bs.current] + + xTopic := x0 + printString(screen, &xTopic, y0, Styled(b.topic, tcell.StyleDefault)) + y0++ + for x := x0; x < x0+bs.tlInnerWidth+nickColWidth+9; x++ { + st := tcell.StyleDefault.Foreground(tcell.ColorGray) + screen.SetContent(x, y0, 0x2500, nil, st) + } + y0++ + yi := b.scrollAmt + y0 + bs.tlHeight for i := len(b.lines) - 1; 0 <= i; i-- { - if yi < 0 { + if yi < y0 { break } @@ -552,15 +572,17 @@ func (bs *BufferList) DrawTimeline(screen tcell.Screen, x0, y0, nickColWidth int continue } - if i == 0 || b.lines[i-1].At.Truncate(time.Minute) != line.At.Truncate(time.Minute) { - st := tcell.StyleDefault.Bold(true) - printTime(screen, x0, yi, st, line.At.Local()) - } + if yi >= y0 { + if i == 0 || b.lines[i-1].At.Truncate(time.Minute) != line.At.Truncate(time.Minute) { + st := tcell.StyleDefault.Bold(true) + printTime(screen, x0, yi, st, line.At.Local()) + } - identSt := tcell.StyleDefault. - Foreground(line.HeadColor). - Reverse(line.Highlight) - printIdent(screen, x0+7, yi, nickColWidth, Styled(line.Head, identSt)) + identSt := tcell.StyleDefault. + Foreground(line.HeadColor). + Reverse(line.Highlight) + printIdent(screen, x0+7, yi, nickColWidth, Styled(line.Head, identSt)) + } x := x1 y := yi @@ -585,7 +607,9 @@ func (bs *BufferList) DrawTimeline(screen tcell.Screen, x0, y0, nickColWidth int continue } - screen.SetContent(x, y, r, nil, style) + if yi >= y0 { + screen.SetContent(x, y, r, nil, style) + } x += runeWidth(r) } } -- cgit v1.2.3