commit 464ea64

delthas  ·  2022-08-16 06:41:42 +0000 UTC
parent d2f12ad
Show the message date instead of its time on date change

Fixes: https://todo.sr.ht/~taiite/senpai/17
2 files changed,  +25, -1
+12, -1
 1@@ -758,8 +758,19 @@ func (bs *BufferList) DrawTimeline(screen tcell.Screen, x0, y0, nickColWidth int
 2 		}
 3 
 4 		if yi >= y0 {
 5-			if i == 0 || b.lines[i-1].At.Truncate(time.Minute) != line.At.Truncate(time.Minute) {
 6+			var showDate bool
 7+			if i == 0 || yi == y0 {
 8+				showDate = true
 9+			} else {
10+				yb, mb, dd := b.lines[i-1].At.Local().Date()
11+				ya, ma, da := b.lines[i].At.Local().Date()
12+				showDate = yb != ya || mb != ma || dd != da
13+			}
14+			if showDate {
15 				st := tcell.StyleDefault.Bold(true)
16+				printDate(screen, x0, yi, st, line.At.Local())
17+			} else if b.lines[i-1].At.Truncate(time.Minute) != line.At.Truncate(time.Minute) {
18+				st := tcell.StyleDefault.Foreground(tcell.ColorGray)
19 				printTime(screen, x0, yi, st, line.At.Local())
20 			}
21 
+13, -0
 1@@ -42,6 +42,19 @@ func printNumber(screen tcell.Screen, x *int, y int, st tcell.Style, n int) {
 2 	printString(screen, x, y, s)
 3 }
 4 
 5+func printDate(screen tcell.Screen, x int, y int, st tcell.Style, t time.Time) {
 6+	_, m, d := t.Date()
 7+	d0 := rune(d/10) + '0'
 8+	d1 := rune(d%10) + '0'
 9+	m0 := rune(m/10) + '0'
10+	m1 := rune(m%10) + '0'
11+	screen.SetContent(x+0, y, d0, nil, st)
12+	screen.SetContent(x+1, y, d1, nil, st)
13+	screen.SetContent(x+2, y, '/', nil, st)
14+	screen.SetContent(x+3, y, m0, nil, st)
15+	screen.SetContent(x+4, y, m1, nil, st)
16+}
17+
18 func printTime(screen tcell.Screen, x int, y int, st tcell.Style, t time.Time) {
19 	hr0 := rune(t.Hour()/10) + '0'
20 	hr1 := rune(t.Hour()%10) + '0'