-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy paththeme.go
More file actions
115 lines (102 loc) · 3.16 KB
/
theme.go
File metadata and controls
115 lines (102 loc) · 3.16 KB
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
package main
import "fmt"
// ─── Symbols ───────────────────────────────────────────────────────────────
const (
symBranch = "\ue0a0"
)
// ─── ANSI codes ────────────────────────────────────────────────────────────
var (
ansiReset = "\x1b[0m"
ansiBold = "\x1b[1m"
ansiItalic = "\x1b[3m"
// Base accent colors (used by palette constructors)
accentGreen = hexToAnsi("#9ece6a", false)
accentRed = hexToAnsi("#f7768e", false)
accentYellow = hexToAnsi("#e0af68", false)
accentOrange = hexToAnsi("#ff9e64", false)
accentPaleOrange = hexToAnsi("#d4a373", false)
accentGray = hexToAnsi("#565f89", false)
)
// ─── Palette ───────────────────────────────────────────────────────────────
// palette holds all foreground colors used by segment builders.
// Switching palettes changes the entire status line appearance.
type palette struct {
muted string
soft string
active string
separator string
git string
prompt string
green string
red string
yellow string
orange string
paleOrange string
gray string
}
// pal is the active color palette, set in main() based on context health.
var pal *palette
// normalPalette returns the standard Tokyo Night color palette.
func normalPalette() *palette {
return &palette{
muted: hexToAnsi("#565f89", false),
soft: hexToAnsi("#a9b1d6", false),
active: hexToAnsi("#c0caf5", false),
separator: hexToAnsi("#3b4261", false),
git: hexToAnsi("#7aa2f7", false),
prompt: hexToAnsi("#565f89", false),
green: accentGreen,
red: accentRed,
yellow: accentYellow,
orange: accentOrange,
paleOrange: accentPaleOrange,
gray: accentGray,
}
}
// alertPalette returns a palette where all colors are red,
// signaling critical context window depletion.
func alertPalette() *palette {
return &palette{
muted: accentRed,
soft: accentRed,
active: accentRed,
separator: accentRed,
git: accentRed,
prompt: accentRed,
green: accentRed,
red: accentRed,
yellow: accentRed,
orange: accentRed,
paleOrange: accentRed,
gray: accentRed,
}
}
// hexToAnsi converts a #RRGGBB hex color to an ANSI true-color escape code.
func hexToAnsi(hex string, isBg bool) string {
if len(hex) != 7 || hex[0] != '#' {
return ""
}
r := parseHexByte(hex[1:3])
g := parseHexByte(hex[3:5])
b := parseHexByte(hex[5:7])
code := 38
if isBg {
code = 48
}
return fmt.Sprintf("\x1b[%d;2;%d;%d;%dm", code, r, g, b)
}
func parseHexByte(s string) int {
val := 0
for _, c := range s {
val <<= 4
switch {
case c >= '0' && c <= '9':
val += int(c - '0')
case c >= 'a' && c <= 'f':
val += int(c-'a') + 10
case c >= 'A' && c <= 'F':
val += int(c-'A') + 10
}
}
return val
}