~taiite/public-inbox

This thread contains a patchset. You're looking at the original emails, but you may wish to use the patch review UI. Review patch
1

[PATCH senpai v4] Show the current channel topic at the top of the timeline

Details
Message ID
<20211124150159.19002-1-delthas@dille.cc>
DKIM signature
pass
Download raw message
Patch: +43 -14
---
 app.go        |  3 ++-
 ui/buffers.go | 50 +++++++++++++++++++++++++++++++++++++-------------
 ui/ui.go      |  4 ++++
 3 files changed, 43 insertions(+), 14 deletions(-)

diff --git a/app.go b/app.go
index db5c776..479623c 100644
--- a/app.go
+++ b/app.go
@@ -655,7 +655,7 @@ func (app *App) handleIRCEvent(netID string, ev interface{}) {
			app.win.JumpBufferIndex(i)
		}
		if ev.Topic != "" {
			app.printTopic(netID, ev.Channel)
			app.win.SetTopic(netID, ev.Channel, ev.Topic)
		}

		// Restore last buffer
@@ -714,6 +714,7 @@ func (app *App) handleIRCEvent(netID string, ev interface{}) {
	case irc.TopicChangeEvent:
		topic := ui.IRCString(ev.Topic).String()
		body := fmt.Sprintf("Topic changed to: %s", topic)
		app.win.SetTopic(netID, ev.Channel, ev.Topic)
		app.win.AddLine(netID, ev.Channel, ui.NotifyUnread, ui.Line{
			At:        msg.TimeOrNow(),
			Head:      "--",
diff --git a/ui/buffers.go b/ui/buffers.go
index 9dc26c2..9a20abe 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 {
@@ -356,6 +357,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
@@ -532,12 +542,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
		}

@@ -550,15 +570,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
@@ -574,7 +596,7 @@ func (bs *BufferList) DrawTimeline(screen tcell.Screen, x0, y0, nickColWidth int
				x = x1
				y++
				nls = nls[1:]
				if bs.tlHeight <= y {
				if y0+bs.tlHeight <= y {
					break
				}
			}
@@ -583,7 +605,9 @@ func (bs *BufferList) DrawTimeline(screen tcell.Screen, x0, y0, nickColWidth int
				continue
			}

			screen.SetContent(x, y, r, nil, style)
			if y >= y0 {
				screen.SetContent(x, y, r, nil, style)
			}
			x += runeWidth(r)
		}
	}
diff --git a/ui/ui.go b/ui/ui.go
index 97f7148..fe5ceef 100644
--- a/ui/ui.go
+++ b/ui/ui.go
@@ -231,6 +231,10 @@ func (ui *UI) JumpBufferNetwork(netID, sub string) bool {
	return false
}

func (ui *UI) SetTopic(netID, buffer string, topic string) {
	ui.bs.SetTopic(netID, buffer, topic)
}

func (ui *UI) SetStatus(status string) {
	ui.status = status
}

base-commit: 7f70f101bc02d9b7b0ed5afc464d0fb7b1e6fa50
-- 
2.17.1
Details
Message ID
<00b15a00-6b46-0e55-f58d-875ae222d446@hirtz.pm>
In-Reply-To
<20211124150159.19002-1-delthas@dille.cc> (view parent)
DKIM signature
pass
Download raw message
Thanks, pushed!
Reply to thread Export thread (mbox)