Skip to content

Commit d3e28a2

Browse files
committed
fix(Color): don't use shared global state (Color.BG etc.)
Fix bug where the colorscheme colors are off/incorrect when a palette is require()'d, whether directly or indirectly, anytime before compilation occurs (e.g. compilation that occurs during colorscheme load). For details, see issue #362. Also, add a test (in `test/`) which disallows the direct or indirect use of the global static/class fields of the `Color` class (e.g. `Color.BG`). Fixes: #362
1 parent 43b6536 commit d3e28a2

14 files changed

+326
-358
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ The format is based on [Keep a Changelog], and this project adheres to [Semantic
1414
### Issues Fix
1515

1616
- Fixed JSX/TSX tags are missing highlights with nvim 0.10 (#360)
17+
- Fixed loading palette or spec before colorscheme disrupts colors (#362 fixed-by #363)
1718

1819
## [v1.1.2] - 05 August 2024
1920

lua/github-theme/group/modules/treesitter.lua

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ function M.get(spec, config, _opts)
88
-- being integrated.
99
local primitives = require(
1010
'github-theme.palette.primitives.'
11-
.. require('github-theme.config').theme
11+
.. spec.palette.meta.name
1212
:gsub('^github_(.-)_default$', '%1')
1313
:gsub('^github_(.-)$', '%1')
1414
)

lua/github-theme/palette/github_dark.lua

+34-37
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,7 @@ local scale = primitives.scale
1414
C.WHITE = C(scale.white)
1515
C.BLACK = C(scale.black)
1616
C.BG = C(scale.gray[7])
17-
18-
local function alpha(color, a)
19-
return color:alpha_blend(a):to_css()
20-
end
17+
local BG = C(scale.gray[7])
2118

2219
local palette = {
2320
scale = scale,
@@ -52,86 +49,86 @@ local palette = {
5249
border = {
5350
default = scale.gray[9],
5451
muted = scale.gray[8],
55-
subtle = alpha(C.from_rgba(240, 246, 252, 1), 0.1),
52+
subtle = BG:blend(C.from_rgba(240, 246, 252, 1), 0.1):to_css(),
5653
},
5754

5855
neutral = {
5956
emphasis_plus = scale.gray[5],
6057
emphasis = scale.gray[5],
61-
muted = alpha(C.from_rgba(110, 118, 129, 1), 0.4),
62-
subtle = alpha(C.from_rgba(110, 118, 129, 1), 0.1),
58+
muted = BG:blend(C.from_rgba(110, 118, 129, 1), 0.4):to_css(),
59+
subtle = BG:blend(C.from_rgba(110, 118, 129, 1), 0.1):to_css(),
6360
},
6461

6562
accent = {
6663
fg = '#2f81f7',
6764
emphasis = scale.blue[6],
68-
muted = alpha(C.from_rgba(56, 139, 253, 1), 0.4),
69-
subtle = alpha(C.from_rgba(56, 139, 253, 1), 0.15),
65+
muted = BG:blend(C.from_rgba(56, 139, 253, 1), 0.4):to_css(),
66+
subtle = BG:blend(C.from_rgba(56, 139, 253, 1), 0.15):to_css(),
7067
},
7168

7269
success = {
7370
fg = scale.green[4],
7471
emphasis = scale.green[6],
75-
muted = alpha(C.from_rgba(46, 160, 67, 1), 0.4),
76-
subtle = alpha(C.from_rgba(46, 160, 67, 1), 0.15),
72+
muted = BG:blend(C.from_rgba(46, 160, 67, 1), 0.4):to_css(),
73+
subtle = BG:blend(C.from_rgba(46, 160, 67, 1), 0.15):to_css(),
7774
},
7875

7976
attention = {
8077
fg = scale.yellow[4],
8178
emphasis = scale.yellow[6],
82-
muted = alpha(C.from_rgba(187, 128, 9, 1), 0.4),
83-
subtle = alpha(C.from_rgba(187, 128, 9, 1), 0.15),
79+
muted = BG:blend(C.from_rgba(187, 128, 9, 1), 0.4):to_css(),
80+
subtle = BG:blend(C.from_rgba(187, 128, 9, 1), 0.15):to_css(),
8481
},
8582

8683
severe = {
8784
fg = scale.orange[5],
8885
emphasis = scale.orange[6],
89-
muted = alpha(C.from_rgba(219, 109, 40, 1), 0.4),
90-
subtle = alpha(C.from_rgba(219, 109, 40, 1), 0.1),
86+
muted = BG:blend(C.from_rgba(219, 109, 40, 1), 0.4):to_css(),
87+
subtle = BG:blend(C.from_rgba(219, 109, 40, 1), 0.1):to_css(),
9188
},
9289

9390
danger = {
9491
fg = scale.red[5],
9592
emphasis = scale.red[6],
96-
muted = alpha(C.from_rgba(248, 81, 73, 1), 0.4),
97-
subtle = alpha(C.from_rgba(248, 81, 73, 1), 0.1),
93+
muted = BG:blend(C.from_rgba(248, 81, 73, 1), 0.4):to_css(),
94+
subtle = BG:blend(C.from_rgba(248, 81, 73, 1), 0.1):to_css(),
9895
},
9996

10097
open = {
10198
fg = scale.green[4],
10299
emphasis = scale.green[6],
103-
muted = alpha(C.from_rgba(46, 160, 67, 1), 0.4),
104-
subtle = alpha(C.from_rgba(46, 160, 67, 1), 0.15),
100+
muted = BG:blend(C.from_rgba(46, 160, 67, 1), 0.4):to_css(),
101+
subtle = BG:blend(C.from_rgba(46, 160, 67, 1), 0.15):to_css(),
105102
},
106103

107104
done = {
108105
fg = scale.purple[5],
109106
emphasis = scale.purple[6],
110-
muted = alpha(C.from_rgba(163, 113, 247, 1), 0.4),
111-
subtle = alpha(C.from_rgba(163, 113, 247, 1), 0.1),
107+
muted = BG:blend(C.from_rgba(163, 113, 247, 1), 0.4):to_css(),
108+
subtle = BG:blend(C.from_rgba(163, 113, 247, 1), 0.1):to_css(),
112109
},
113110

114111
closed = {
115112
fg = scale.red[5],
116113
emphasis = scale.red[6],
117-
muted = alpha(C.from_rgba(248, 81, 73, 1), 0.4),
118-
subtle = alpha(C.from_rgba(248, 81, 73, 1), 0.15),
114+
muted = BG:blend(C.from_rgba(248, 81, 73, 1), 0.4):to_css(),
115+
subtle = BG:blend(C.from_rgba(248, 81, 73, 1), 0.15):to_css(),
119116
},
120117

121118
sponsors = {
122119
fg = scale.pink[5],
123120
emphasis = scale.pink[6],
124-
muted = alpha(C.from_rgba(219, 97, 162, 1), 0.4),
125-
subtle = alpha(C.from_rgba(219, 97, 162, 1), 0.1),
121+
muted = BG:blend(C.from_rgba(219, 97, 162, 1), 0.4):to_css(),
122+
subtle = BG:blend(C.from_rgba(219, 97, 162, 1), 0.1):to_css(),
126123
},
127124
}
128125

129126
local function generate_spec(pal)
130127
-- stylua: ignore start
131128
local spec = {
132-
bg0 = alpha(C(pal.canvas.inset), 0.75), -- Dark bg (popup and float)
129+
bg0 = BG:blend(C(pal.canvas.inset), 0.75):to_css(), -- Dark bg (popup and float)
133130
bg1 = pal.canvas.default, -- Default bg
134-
bg2 = alpha(C(pal.neutral.emphasis), 0.1), -- Lighter bg (colorcolumn Folds)
131+
bg2 = BG:blend(C(pal.neutral.emphasis), 0.1):to_css(), -- Lighter bg (colorcolumn Folds)
135132
bg3 = pal.scale.gray[6], -- Lighter bg (cursor line)
136133
bg4 = pal.scale.gray[4], -- Conceal
137134

@@ -140,9 +137,9 @@ local function generate_spec(pal)
140137
fg2 = pal.fg.muted, -- Darker fg (status line)
141138
fg3 = pal.scale.gray[5], -- Darker fg (line numbers, fold columns)
142139

143-
sel0 = alpha(C(pal.accent.fg), 0.30), -- Visual selection bg
144-
sel1 = alpha(C(pal.accent.muted), 0.90), -- Popup sel bg
145-
sel2 = alpha(C(pal.scale.yellow[1]), 0.20), -- Search bg
140+
sel0 = BG:blend(C(pal.accent.fg), 0.30):to_css(), -- Visual selection bg
141+
sel1 = BG:blend(C(pal.accent.muted), 0.90):to_css(), -- Popup sel bg
142+
sel2 = BG:blend(C(pal.scale.yellow[1]), 0.20):to_css(), -- Search bg
146143
}
147144

148145
spec.syntax = {
@@ -178,16 +175,16 @@ local function generate_spec(pal)
178175
}
179176

180177
spec.diag_bg = {
181-
error = C(spec.bg1):blend(C(spec.diag.error), 0.15):to_css(),
182-
warn = C(spec.bg1):blend(C(spec.diag.warn), 0.15):to_css(),
183-
info = C(spec.bg1):blend(C(spec.diag.info), 0.15):to_css(),
184-
hint = C(spec.bg1):blend(C(spec.diag.hint), 0.15):to_css(),
178+
error = BG:blend(C(spec.diag.error), 0.15):to_css(),
179+
warn = BG:blend(C(spec.diag.warn), 0.15):to_css(),
180+
info = BG:blend(C(spec.diag.info), 0.15):to_css(),
181+
hint = BG:blend(C(spec.diag.hint), 0.15):to_css(),
185182
}
186183

187184
spec.diff = {
188-
add = alpha(C(pal.scale.green[6]), 0.15),
189-
delete = alpha(C(pal.scale.red[6]), 0.15),
190-
change = alpha(C(pal.scale.yellow[6]), 0.15),
185+
add = BG:blend(C(pal.scale.green[6]), 0.15):to_css(),
186+
delete = BG:blend(C(pal.scale.red[6]), 0.15):to_css(),
187+
change = BG:blend(C(pal.scale.yellow[6]), 0.15):to_css(),
191188
text = spec.fg0
192189
}
193190

lua/github-theme/palette/github_dark_colorblind.lua

+34-37
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,7 @@ local scale = primitives.scale
1414
C.WHITE = C(scale.white)
1515
C.BLACK = C(scale.black)
1616
C.BG = C(assert(primitives.canvas.default))
17-
18-
local function alpha(color, a)
19-
return color:alpha_blend(a):to_css()
20-
end
17+
local BG = C(assert(primitives.canvas.default))
2118

2219
local palette = {
2320
scale = scale,
@@ -47,86 +44,86 @@ local palette = {
4744
border = {
4845
default = scale.gray[7],
4946
muted = scale.gray[8],
50-
subtle = alpha(C.from_rgba(240, 246, 252, 1), 0.1),
47+
subtle = BG:blend(C.from_rgba(240, 246, 252, 1), 0.1):to_css(),
5148
},
5249

5350
neutral = {
5451
emphasis_plus = scale.gray[5],
5552
emphasis = scale.gray[5],
56-
muted = alpha(C.from_rgba(110, 118, 129, 1), 0.4),
57-
subtle = alpha(C.from_rgba(110, 118, 129, 1), 0.1),
53+
muted = BG:blend(C.from_rgba(110, 118, 129, 1), 0.4):to_css(),
54+
subtle = BG:blend(C.from_rgba(110, 118, 129, 1), 0.1):to_css(),
5855
},
5956

6057
accent = {
6158
fg = scale.blue[4],
6259
emphasis = scale.blue[6],
63-
muted = alpha(C.from_rgba(56, 139, 253, 1), 0.4),
64-
subtle = alpha(C.from_rgba(56, 139, 253, 1), 0.15),
60+
muted = BG:blend(C.from_rgba(56, 139, 253, 1), 0.4):to_css(),
61+
subtle = BG:blend(C.from_rgba(56, 139, 253, 1), 0.15):to_css(),
6562
},
6663

6764
success = {
6865
fg = scale.green[4],
6966
emphasis = scale.green[6],
70-
muted = alpha(C.from_rgba(46, 160, 67, 1), 0.4),
71-
subtle = alpha(C.from_rgba(46, 160, 67, 1), 0.15),
67+
muted = BG:blend(C.from_rgba(46, 160, 67, 1), 0.4):to_css(),
68+
subtle = BG:blend(C.from_rgba(46, 160, 67, 1), 0.15):to_css(),
7269
},
7370

7471
attention = {
7572
fg = scale.yellow[4],
7673
emphasis = scale.yellow[6],
77-
muted = alpha(C.from_rgba(187, 128, 9, 1), 0.4),
78-
subtle = alpha(C.from_rgba(187, 128, 9, 1), 0.15),
74+
muted = BG:blend(C.from_rgba(187, 128, 9, 1), 0.4):to_css(),
75+
subtle = BG:blend(C.from_rgba(187, 128, 9, 1), 0.15):to_css(),
7976
},
8077

8178
severe = {
8279
fg = scale.orange[5],
8380
emphasis = scale.orange[6],
84-
muted = alpha(C.from_rgba(219, 109, 40, 1), 0.4),
85-
subtle = alpha(C.from_rgba(219, 109, 40, 1), 0.15),
81+
muted = BG:blend(C.from_rgba(219, 109, 40, 1), 0.4):to_css(),
82+
subtle = BG:blend(C.from_rgba(219, 109, 40, 1), 0.15):to_css(),
8683
},
8784

8885
danger = {
8986
fg = scale.red[5],
9087
emphasis = scale.red[6],
91-
muted = alpha(C.from_rgba(248, 81, 73, 1), 0.4),
92-
subtle = alpha(C.from_rgba(248, 81, 73, 1), 0.15),
88+
muted = BG:blend(C.from_rgba(248, 81, 73, 1), 0.4):to_css(),
89+
subtle = BG:blend(C.from_rgba(248, 81, 73, 1), 0.15):to_css(),
9390
},
9491

9592
open = {
9693
fg = scale.orange[4],
9794
emphasis = scale.orange[6],
98-
muted = alpha(C.from_hex(scale.orange[5]), 0.4),
99-
subtle = alpha(C.from_hex(scale.orange[5]), 0.15),
95+
muted = BG:blend(C.from_hex(scale.orange[5]), 0.4):to_css(),
96+
subtle = BG:blend(C.from_hex(scale.orange[5]), 0.15):to_css(),
10097
},
10198

10299
done = {
103100
fg = scale.purple[5],
104101
emphasis = scale.purple[6],
105-
muted = alpha(C.from_rgba(163, 113, 247, 1), 0.4),
106-
subtle = alpha(C.from_rgba(163, 113, 247, 1), 0.15),
102+
muted = BG:blend(C.from_rgba(163, 113, 247, 1), 0.4):to_css(),
103+
subtle = BG:blend(C.from_rgba(163, 113, 247, 1), 0.15):to_css(),
107104
},
108105

109106
closed = {
110107
fg = scale.gray[4],
111108
emphasis = scale.gray[5],
112-
muted = alpha(C.from_hex(scale.gray[5]), 0.4),
113-
subtle = alpha(C.from_hex(scale.gray[5]), 0.10),
109+
muted = BG:blend(C.from_hex(scale.gray[5]), 0.4):to_css(),
110+
subtle = BG:blend(C.from_hex(scale.gray[5]), 0.10):to_css(),
114111
},
115112

116113
sponsors = {
117114
fg = scale.pink[5],
118115
emphasis = scale.pink[6],
119-
muted = alpha(C.from_rgba(219, 97, 162, 1), 0.4),
120-
subtle = alpha(C.from_rgba(219, 97, 162, 1), 0.15),
116+
muted = BG:blend(C.from_rgba(219, 97, 162, 1), 0.4):to_css(),
117+
subtle = BG:blend(C.from_rgba(219, 97, 162, 1), 0.15):to_css(),
121118
},
122119
}
123120

124121
local function generate_spec(pal)
125122
-- stylua: ignore start
126123
local spec = {
127-
bg0 = alpha(C(pal.canvas.inset), 0.75), -- Dark bg (status line, popup and float)
124+
bg0 = BG:blend(C(pal.canvas.inset), 0.75):to_css(), -- Dark bg (status line, popup and float)
128125
bg1 = pal.canvas.default, -- Default bg
129-
bg2 = alpha(C(pal.neutral.emphasis), 0.1), -- Lighter bg (colorcolumn Folds)
126+
bg2 = BG:blend(C(pal.neutral.emphasis), 0.1):to_css(), -- Lighter bg (colorcolumn Folds)
130127
bg3 = pal.scale.gray[9], -- Lighter bg (cursor line)
131128
bg4 = pal.scale.gray[4], -- Conceal
132129

@@ -135,9 +132,9 @@ local function generate_spec(pal)
135132
fg2 = pal.fg.muted, -- Darker fg (status line)
136133
fg3 = pal.scale.gray[5], -- Darker fg (line numbers, fold columns)
137134

138-
sel0 = alpha(C(pal.accent.fg), 0.45), -- Visual selection bg
139-
sel1 = alpha(C(pal.accent.muted), 0.90), -- Popup sel bg
140-
sel2 = alpha(C(pal.scale.yellow[3]), 0.60), -- Search bg
135+
sel0 = BG:blend(C(pal.accent.fg), 0.45):to_css(), -- Visual selection bg
136+
sel1 = BG:blend(C(pal.accent.muted), 0.90):to_css(), -- Popup sel bg
137+
sel2 = BG:blend(C(pal.scale.yellow[3]), 0.60):to_css(), -- Search bg
141138
}
142139

143140
spec.syntax = {
@@ -173,16 +170,16 @@ local function generate_spec(pal)
173170
}
174171

175172
spec.diag_bg = {
176-
error = C(spec.bg1):blend(C(spec.diag.error), 0.15):to_css(),
177-
warn = C(spec.bg1):blend(C(spec.diag.warn), 0.15):to_css(),
178-
info = C(spec.bg1):blend(C(spec.diag.info), 0.15):to_css(),
179-
hint = C(spec.bg1):blend(C(spec.diag.hint), 0.15):to_css(),
173+
error = BG:blend(C(spec.diag.error), 0.15):to_css(),
174+
warn = BG:blend(C(spec.diag.warn), 0.15):to_css(),
175+
info = BG:blend(C(spec.diag.info), 0.15):to_css(),
176+
hint = BG:blend(C(spec.diag.hint), 0.15):to_css(),
180177
}
181178

182179
spec.diff = {
183-
add = alpha(C(pal.scale.green[6]), 0.15),
184-
delete = alpha(C(pal.scale.red[6]), 0.15),
185-
change = alpha(C(pal.scale.yellow[6]), 0.15),
180+
add = BG:blend(C(pal.scale.green[6]), 0.15):to_css(),
181+
delete = BG:blend(C(pal.scale.red[6]), 0.15):to_css(),
182+
change = BG:blend(C(pal.scale.yellow[6]), 0.15):to_css(),
186183
text = spec.fg0
187184
}
188185

0 commit comments

Comments
 (0)