First draft
This commit is contained in:
161
ui/clock.go
Normal file
161
ui/clock.go
Normal file
@@ -0,0 +1,161 @@
|
||||
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. The colon blinks every second.
|
||||
func RenderBigClock(t time.Time) string {
|
||||
h := t.Hour()
|
||||
m := t.Minute()
|
||||
s := t.Second()
|
||||
|
||||
timeStr := fmt.Sprintf("%02d:%02d:%02d", h, m, s)
|
||||
|
||||
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 s%2 == 0 {
|
||||
parts = append(parts, bigColon[i])
|
||||
} else {
|
||||
parts = append(parts, bigColonBlink[i])
|
||||
}
|
||||
}
|
||||
}
|
||||
lines[i] = strings.Join(parts, " ")
|
||||
}
|
||||
|
||||
return strings.Join(lines[:], "\n")
|
||||
}
|
||||
Reference in New Issue
Block a user