1package main 2 3import ( 4 "time" 5 6 "github.com/gdamore/tcell/v2" 7 runewidth "github.com/mattn/go-runewidth" 8) 910var (11 curDate = time.Now()12)1314// Adaptive time printing depending on the distance to the current date.15//16// Inspired by https://github.com/leahneukirchen/mblaze/blob/v1.2/mscan.c#L179-L18417func adaptiveTime(t time.Time) string {18 if t.Year() != curDate.Year() {19 return t.Format("2006-01-02")20 } else if t.After(curDate) || curDate.Sub(t) > 24*time.Hour {21 return t.Format("Mon Jan 02")22 } else {23 return t.Format("Mon 15:04")24 }25}2627func drawText(s tcell.Screen, row, col int, style tcell.Style, text string) int {28 for _, r := range text {29 s.SetContent(col, row, r, nil, style)30 col += runewidth.RuneWidth(r)31 }3233 return col34}