~taiite/public-inbox

senpai: ui/buffers: Show unread bar above unread messages v2 PROPOSED

Adnan Maolood: 1
 ui/buffers: Show unread bar above unread messages

 1 files changed, 26 insertions(+), 10 deletions(-)
Export patchset (mbox)
How do I use this?

Copy & paste the following snippet into your terminal to import this patchset into git:

curl -s https://lists.sr.ht/~taiite/public-inbox/patches/32021/mbox | git am -3
Learn more about email & git

[PATCH senpai v2] ui/buffers: Show unread bar above unread messages Export this patch

Implements: https://todo.sr.ht/~taiite/senpai/76
---
 ui/buffers.go | 36 ++++++++++++++++++++++++++----------
 1 file changed, 26 insertions(+), 10 deletions(-)

diff --git a/ui/buffers.go b/ui/buffers.go
index db2a462..51b555b 100644
--- a/ui/buffers.go
+++ b/ui/buffers.go
@@ -186,6 +186,7 @@ type buffer struct {
	highlights int
	unread     bool
	read       time.Time
	lastRead   time.Time
	openedOnce bool

	lines []Line
@@ -244,6 +245,8 @@ func (bs *BufferList) HasOverlay() bool {
}

func (bs *BufferList) To(i int) bool {
	// Treat all visible messages in the current buffer as read
	bs.list[bs.current].lastRead = bs.list[bs.current].read
	bs.overlay = nil
	if i == bs.current {
		return false
@@ -265,19 +268,11 @@ func (bs *BufferList) ShowBufferNumbers(enabled bool) {
}

func (bs *BufferList) Next() {
	bs.overlay = nil
	bs.current = (bs.current + 1) % len(bs.list)
	b := bs.cur()
	b.highlights = 0
	b.unread = false
	bs.To((bs.current + 1) % len(bs.list))
}

func (bs *BufferList) Previous() {
	bs.overlay = nil
	bs.current = (bs.current - 1 + len(bs.list)) % len(bs.list)
	b := bs.cur()
	b.highlights = 0
	b.unread = false
	bs.To((bs.current - 1 + len(bs.list)) % len(bs.list))
}

func (bs *BufferList) Add(netID, netName, title string) (i int, added bool) {
@@ -378,6 +373,12 @@ func (bs *BufferList) AddLine(netID, title string, notify NotifyType, line Line)
		}
	}

	// If this is the current buffer, and we have read *all* messages,
	// treat new messages as read also
	if b == current && b.scrollAmt == 0 && line.Readable {
		b.lastRead = line.At
	}

	if notify != NotifyNone && b != current {
		b.unread = true
	}
@@ -760,6 +761,21 @@ func (bs *BufferList) DrawTimeline(screen tcell.Screen, x0, y0, nickColWidth int
			}
			x += runeWidth(r)
		}

		// Draw unread bar before the first unread line
		if i > 0 && line.At.After(b.lastRead) && !b.lines[i-1].At.After(b.lastRead) {
			yi--
			if yi < y0 {
				break
			}
			style := tcell.StyleDefault.Bold(true)
			for x := x1; x < x1+bs.tlInnerWidth; x++ {
				screen.SetContent(x, yi, '-', nil, style)
			}
			const msg = " UNREAD MESSAGES "
			x2 := x1 + bs.tlInnerWidth/2 - len(msg)/2
			printString(screen, &x2, yi, Styled(msg, style))
		}
	}

	b.isAtTop = y0 <= yi
-- 
2.34.2
Disregard this patch, it has a few issues.