From 464ea64d78e6b31d2ea70e70aa02bdb974bd2dc6 Mon Sep 17 00:00:00 2001 From: delthas Date: Tue, 16 Aug 2022 08:41:42 +0200 Subject: Show the message date instead of its time on date change Fixes: https://todo.sr.ht/~taiite/senpai/17 --- ui/buffers.go | 13 ++++++++++++- ui/draw_utils.go | 13 +++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/ui/buffers.go b/ui/buffers.go index b13465f..5e2691c 100644 --- a/ui/buffers.go +++ b/ui/buffers.go @@ -758,8 +758,19 @@ func (bs *BufferList) DrawTimeline(screen tcell.Screen, x0, y0, nickColWidth int } if yi >= y0 { - if i == 0 || b.lines[i-1].At.Truncate(time.Minute) != line.At.Truncate(time.Minute) { + var showDate bool + if i == 0 || yi == y0 { + showDate = true + } else { + yb, mb, dd := b.lines[i-1].At.Local().Date() + ya, ma, da := b.lines[i].At.Local().Date() + showDate = yb != ya || mb != ma || dd != da + } + if showDate { st := tcell.StyleDefault.Bold(true) + printDate(screen, x0, yi, st, line.At.Local()) + } else if b.lines[i-1].At.Truncate(time.Minute) != line.At.Truncate(time.Minute) { + st := tcell.StyleDefault.Foreground(tcell.ColorGray) printTime(screen, x0, yi, st, line.At.Local()) } diff --git a/ui/draw_utils.go b/ui/draw_utils.go index 45e81db..3d04f11 100644 --- a/ui/draw_utils.go +++ b/ui/draw_utils.go @@ -42,6 +42,19 @@ func printNumber(screen tcell.Screen, x *int, y int, st tcell.Style, n int) { printString(screen, x, y, s) } +func printDate(screen tcell.Screen, x int, y int, st tcell.Style, t time.Time) { + _, m, d := t.Date() + d0 := rune(d/10) + '0' + d1 := rune(d%10) + '0' + m0 := rune(m/10) + '0' + m1 := rune(m%10) + '0' + screen.SetContent(x+0, y, d0, nil, st) + screen.SetContent(x+1, y, d1, nil, st) + screen.SetContent(x+2, y, '/', nil, st) + screen.SetContent(x+3, y, m0, nil, st) + screen.SetContent(x+4, y, m1, nil, st) +} + func printTime(screen tcell.Screen, x int, y int, st tcell.Style, t time.Time) { hr0 := rune(t.Hour()/10) + '0' hr1 := rune(t.Hour()%10) + '0' -- cgit v1.2.3