mblaze-ui

A minimal TUI for the mblaze email client

git clone https://git.8pit.net/mblaze-ui.git

 1package main
 2
 3import (
 4	"time"
 5
 6	"github.com/gdamore/tcell/v2"
 7	runewidth "github.com/mattn/go-runewidth"
 8)
 9
10var (
11	curDate = time.Now()
12)
13
14// 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-L184
17func 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}
26
27func 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	}
32
33	return col
34}