1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
|
package ui
import (
"strings"
"github.com/charmbracelet/lipgloss"
)
// A 5-row block font for the oversized detail-view scoreline. Each glyph is 6
// cells wide with 2-cell-thick strokes, so vertical strokes read as bold as
// the horizontals — rendered with the full block rune for the app's signature
// flair.
const blockRows = 5
var blockGlyphs = map[rune][blockRows]string{
'0': {"██████", "██ ██", "██ ██", "██ ██", "██████"},
'1': {" ██ ", "████ ", " ██ ", " ██ ", "██████"},
'2': {"██████", " ██", "██████", "██ ", "██████"},
'3': {"██████", " ██", " █████", " ██", "██████"},
'4': {"██ ██", "██ ██", "██████", " ██", " ██"},
'5': {"██████", "██ ", "██████", " ██", "██████"},
'6': {"██████", "██ ", "██████", "██ ██", "██████"},
'7': {"██████", " ██", " ██ ", " ██ ", " ██ "},
'8': {"██████", "██ ██", "██████", "██ ██", "██████"},
'9': {"██████", "██ ██", "██████", " ██", "██████"},
'-': {" ", " ", "██████", " ", " "},
' ': {" ", " ", " ", " ", " "},
}
// blockNumber renders a string of digits (and '-'/' ') as a 5-row block, each
// row a single string. Unknown runes render as blank glyphs.
func blockNumber(s string) []string {
rows := make([]string, blockRows)
for i, r := range s {
g, ok := blockGlyphs[r]
if !ok {
g = blockGlyphs[' ']
}
for row := 0; row < blockRows; row++ {
if i > 0 {
rows[row] += " " // 1-cell gap between glyphs
}
rows[row] += g[row]
}
}
return rows
}
// blockScore renders "away - home" as one big colored block: away digits in
// awayCol, home in homeCol, the dash muted. Returns a multi-line string.
func blockScore(away, home string, awayCol, homeCol lipgloss.TerminalColor) string {
render := func(s string, c lipgloss.TerminalColor) string {
return lipgloss.NewStyle().Foreground(c).Bold(true).
Render(strings.Join(blockNumber(s), "\n"))
}
gap := strings.Join(blockNumber(" "), "\n")
dash := lipgloss.NewStyle().Foreground(colMuted).Render(strings.Join(blockNumber("-"), "\n"))
return lipgloss.JoinHorizontal(lipgloss.Top,
render(away, awayCol), gap, dash, gap, render(home, homeCol))
}
|