commit 1e2ffe2

delthas  ·  2025-02-18 16:11:58 +0000 UTC
parent 47cf782
Always show the message time after a message date

This can help know at which specific time a long discussion
happened.

Thanks to ~sethkush for the feature request.

Fixes: https://todo.sr.ht/~delthas/senpai/179
1 files changed,  +22, -12
+22, -12
 1@@ -999,6 +999,15 @@ func (bs *BufferList) bufferWidth(b *buffer) int {
 2 	return width
 3 }
 4 
 5+func (bs *BufferList) shouldShowDate(b *buffer, i int, yi int, y0 int) bool {
 6+	if i == 0 || yi <= y0 {
 7+		return true
 8+	}
 9+	yb, mb, dd := b.lines[i-1].At.Local().Date()
10+	ya, ma, da := b.lines[i].At.Local().Date()
11+	return yb != ya || mb != ma || dd != da
12+}
13+
14 func (bs *BufferList) DrawHorizontalBufferList(vx *Vaxis, x0, y0, width int, offset *int) {
15 	x := width
16 	for i := len(bs.list) - 1; i >= 0; i-- {
17@@ -1199,14 +1208,7 @@ func (bs *BufferList) DrawTimeline(ui *UI, x0, y0, nickColWidth int) {
18 			continue
19 		}
20 
21-		var showDate bool
22-		if i == 0 || yi <= y0 {
23-			showDate = true
24-		} else {
25-			yb, mb, dd := b.lines[i-1].At.Local().Date()
26-			ya, ma, da := b.lines[i].At.Local().Date()
27-			showDate = yb != ya || mb != ma || dd != da
28-		}
29+		showDate := bs.shouldShowDate(b, i, yi, y0)
30 		if showDate {
31 			st := vaxis.Style{
32 				Attribute: vaxis.AttrBold,
33@@ -1217,11 +1219,19 @@ func (bs *BufferList) DrawTimeline(ui *UI, x0, y0, nickColWidth int) {
34 				yd = y0
35 			}
36 			printDate(vx, x0, yd, st, line.At.Local())
37-		} else if b.lines[i-1].At.Truncate(time.Minute) != line.At.Truncate(time.Minute) && yi >= y0 {
38-			st := vaxis.Style{
39-				Foreground: ColorGray,
40+		} else {
41+			showTime := b.lines[i-1].At.Truncate(time.Minute) != line.At.Truncate(time.Minute) && yi >= y0
42+			if !showTime {
43+				// also try to show the time if we previously drew the date
44+				yp := yi - (len(b.lines[i-1].NewLines(bs.ui.vx, bs.textWidth)) + 1)
45+				showTime = i == 0 || bs.shouldShowDate(b, i-1, yp, y0)
46+			}
47+			if showTime {
48+				st := vaxis.Style{
49+					Foreground: ColorGray,
50+				}
51+				printTime(vx, x0, yi, st, line.At.Local())
52 			}
53-			printTime(vx, x0, yi, st, line.At.Local())
54 		}
55 
56 		if yi >= y0 {