commit c1a3108

delthas  ·  2024-07-17 10:29:20 +0000 UTC
parent d8907e9
Add the count of unread highlights to the window title

Fixes: https://todo.sr.ht/~delthas/senpai/165
3 files changed,  +19, -3
M app.go
M app.go
+7, -3
 1@@ -280,11 +280,15 @@ func (app *App) eventLoop() {
 2 				currentMembers = s.Names(buffer)
 3 			}
 4 			app.win.Draw(currentMembers)
 5+			var title strings.Builder
 6+			if higlights := app.win.Highlights(); higlights > 0 {
 7+				fmt.Fprintf(&title, "(%d) ", higlights)
 8+			}
 9 			if netID != "" && buffer != "" {
10-				app.win.SetTitle(fmt.Sprintf("%s — senpai", buffer))
11-			} else {
12-				app.win.SetTitle("senpai")
13+				fmt.Fprintf(&title, "%s - ", buffer)
14 			}
15+			title.WriteString("senpai")
16+			app.win.SetTitle(title.String())
17 		}
18 	}
19 	go func() {
+8, -0
 1@@ -659,6 +659,14 @@ func (bs *BufferList) LinesAboveOffset() int {
 2 	return len(b.lines) - b.scrollAmt
 3 }
 4 
 5+func (bs *BufferList) Highlights() int {
 6+	n := 0
 7+	for _, b := range bs.list {
 8+		n += b.highlights
 9+	}
10+	return n
11+}
12+
13 func (bs *BufferList) at(netID, title string) (int, *buffer) {
14 	if netID == "" && title == Overlay {
15 		return -1, bs.overlay
+4, -0
 1@@ -578,6 +578,10 @@ func (ui *UI) Notify(title string, body string) {
 2 	ui.vx.Notify(title, body)
 3 }
 4 
 5+func (ui *UI) Highlights() int {
 6+	return ui.bs.Highlights()
 7+}
 8+
 9 func (ui *UI) ImageReady() bool {
10 	if ui.image == nil {
11 		return false