summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordelthas <delthas@dille.cc>2022-08-16 08:41:42 +0200
committerdelthas <delthas@dille.cc>2022-08-16 08:41:42 +0200
commit464ea64d78e6b31d2ea70e70aa02bdb974bd2dc6 (patch)
treea941df3fb52e6341f757cbb3c6ff44456933ad78
parentMention /help rather than man (diff)
Show the message date instead of its time on date change
Fixes: https://todo.sr.ht/~taiite/senpai/17
-rw-r--r--ui/buffers.go13
-rw-r--r--ui/draw_utils.go13
2 files changed, 25 insertions, 1 deletions
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'