Files
woke/ui/clock.go
2026-02-02 19:38:02 +02:00

165 lines
2.8 KiB
Go

package ui
import (
"fmt"
"strings"
"time"
)
// Each digit is 8 chars wide x 7 lines tall, using block characters.
var bigDigits = [10][]string{
// 0
{
" ██████ ",
"██ ██",
"██ ████",
"██ ██ ██",
"████ ██",
"██ ██",
" ██████ ",
},
// 1
{
" ██ ",
" ████ ",
" ██ ",
" ██ ",
" ██ ",
" ██ ",
" ██████",
},
// 2
{
" ██████ ",
"██ ██",
" ██",
" █████ ",
"██ ",
"██ ██",
"████████",
},
// 3
{
" ██████ ",
"██ ██",
" ██",
" █████ ",
" ██",
"██ ██",
" ██████ ",
},
// 4
{
"██ ██",
"██ ██",
"██ ██",
"████████",
" ██",
" ██",
" ██",
},
// 5
{
"████████",
"██ ",
"██ ",
"███████ ",
" ██",
"██ ██",
" ██████ ",
},
// 6
{
" ██████ ",
"██ ",
"██ ",
"███████ ",
"██ ██",
"██ ██",
" ██████ ",
},
// 7
{
"████████",
"██ ██",
" ██ ",
" ██ ",
" ██ ",
" ██ ",
" ██ ",
},
// 8
{
" ██████ ",
"██ ██",
"██ ██",
" ██████ ",
"██ ██",
"██ ██",
" ██████ ",
},
// 9
{
" ██████ ",
"██ ██",
"██ ██",
" ███████",
" ██",
" ██",
" ██████ ",
},
}
var bigColon = []string{
" ",
" ██ ",
" ██ ",
" ",
" ██ ",
" ██ ",
" ",
}
var bigColonBlink = []string{
" ",
" ",
" ",
" ",
" ",
" ",
" ",
}
// RenderBigClock renders the current time as massive ASCII block digits.
// Format: HH:MM:SS in 24h. blinkOnMs/blinkOffMs control the colon blink cycle.
func RenderBigClock(t time.Time, blinkOnMs, blinkOffMs int) string {
h := t.Hour()
m := t.Minute()
s := t.Second()
timeStr := fmt.Sprintf("%02d:%02d:%02d", h, m, s)
cycle := int64(blinkOnMs + blinkOffMs)
colonVisible := t.UnixMilli()%cycle < int64(blinkOnMs)
var lines [7]string
for i := range lines {
var parts []string
for _, ch := range timeStr {
switch {
case ch >= '0' && ch <= '9':
parts = append(parts, bigDigits[ch-'0'][i])
case ch == ':':
if colonVisible {
parts = append(parts, bigColon[i])
} else {
parts = append(parts, bigColonBlink[i])
}
}
}
lines[i] = strings.Join(parts, " ")
}
return strings.Join(lines[:], "\n")
}