Skip to content

Commit

Permalink
fix(Color): don't use shared global state (Color.BG etc.)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
tmillr committed Aug 9, 2024
1 parent 43b6536 commit d3e28a2
Show file tree
Hide file tree
Showing 14 changed files with 326 additions and 358 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ The format is based on [Keep a Changelog], and this project adheres to [Semantic
### Issues Fix

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

## [v1.1.2] - 05 August 2024

Expand Down
2 changes: 1 addition & 1 deletion lua/github-theme/group/modules/treesitter.lua
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ function M.get(spec, config, _opts)
-- being integrated.
local primitives = require(
'github-theme.palette.primitives.'
.. require('github-theme.config').theme
.. spec.palette.meta.name
:gsub('^github_(.-)_default$', '%1')
:gsub('^github_(.-)$', '%1')
)
Expand Down
71 changes: 34 additions & 37 deletions lua/github-theme/palette/github_dark.lua
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,7 @@ local scale = primitives.scale
C.WHITE = C(scale.white)
C.BLACK = C(scale.black)
C.BG = C(scale.gray[7])

local function alpha(color, a)
return color:alpha_blend(a):to_css()
end
local BG = C(scale.gray[7])

local palette = {
scale = scale,
Expand Down Expand Up @@ -52,86 +49,86 @@ local palette = {
border = {
default = scale.gray[9],
muted = scale.gray[8],
subtle = alpha(C.from_rgba(240, 246, 252, 1), 0.1),
subtle = BG:blend(C.from_rgba(240, 246, 252, 1), 0.1):to_css(),
},

neutral = {
emphasis_plus = scale.gray[5],
emphasis = scale.gray[5],
muted = alpha(C.from_rgba(110, 118, 129, 1), 0.4),
subtle = alpha(C.from_rgba(110, 118, 129, 1), 0.1),
muted = BG:blend(C.from_rgba(110, 118, 129, 1), 0.4):to_css(),
subtle = BG:blend(C.from_rgba(110, 118, 129, 1), 0.1):to_css(),
},

accent = {
fg = '#2f81f7',
emphasis = scale.blue[6],
muted = alpha(C.from_rgba(56, 139, 253, 1), 0.4),
subtle = alpha(C.from_rgba(56, 139, 253, 1), 0.15),
muted = BG:blend(C.from_rgba(56, 139, 253, 1), 0.4):to_css(),
subtle = BG:blend(C.from_rgba(56, 139, 253, 1), 0.15):to_css(),
},

success = {
fg = scale.green[4],
emphasis = scale.green[6],
muted = alpha(C.from_rgba(46, 160, 67, 1), 0.4),
subtle = alpha(C.from_rgba(46, 160, 67, 1), 0.15),
muted = BG:blend(C.from_rgba(46, 160, 67, 1), 0.4):to_css(),
subtle = BG:blend(C.from_rgba(46, 160, 67, 1), 0.15):to_css(),
},

attention = {
fg = scale.yellow[4],
emphasis = scale.yellow[6],
muted = alpha(C.from_rgba(187, 128, 9, 1), 0.4),
subtle = alpha(C.from_rgba(187, 128, 9, 1), 0.15),
muted = BG:blend(C.from_rgba(187, 128, 9, 1), 0.4):to_css(),
subtle = BG:blend(C.from_rgba(187, 128, 9, 1), 0.15):to_css(),
},

severe = {
fg = scale.orange[5],
emphasis = scale.orange[6],
muted = alpha(C.from_rgba(219, 109, 40, 1), 0.4),
subtle = alpha(C.from_rgba(219, 109, 40, 1), 0.1),
muted = BG:blend(C.from_rgba(219, 109, 40, 1), 0.4):to_css(),
subtle = BG:blend(C.from_rgba(219, 109, 40, 1), 0.1):to_css(),
},

danger = {
fg = scale.red[5],
emphasis = scale.red[6],
muted = alpha(C.from_rgba(248, 81, 73, 1), 0.4),
subtle = alpha(C.from_rgba(248, 81, 73, 1), 0.1),
muted = BG:blend(C.from_rgba(248, 81, 73, 1), 0.4):to_css(),
subtle = BG:blend(C.from_rgba(248, 81, 73, 1), 0.1):to_css(),
},

open = {
fg = scale.green[4],
emphasis = scale.green[6],
muted = alpha(C.from_rgba(46, 160, 67, 1), 0.4),
subtle = alpha(C.from_rgba(46, 160, 67, 1), 0.15),
muted = BG:blend(C.from_rgba(46, 160, 67, 1), 0.4):to_css(),
subtle = BG:blend(C.from_rgba(46, 160, 67, 1), 0.15):to_css(),
},

done = {
fg = scale.purple[5],
emphasis = scale.purple[6],
muted = alpha(C.from_rgba(163, 113, 247, 1), 0.4),
subtle = alpha(C.from_rgba(163, 113, 247, 1), 0.1),
muted = BG:blend(C.from_rgba(163, 113, 247, 1), 0.4):to_css(),
subtle = BG:blend(C.from_rgba(163, 113, 247, 1), 0.1):to_css(),
},

closed = {
fg = scale.red[5],
emphasis = scale.red[6],
muted = alpha(C.from_rgba(248, 81, 73, 1), 0.4),
subtle = alpha(C.from_rgba(248, 81, 73, 1), 0.15),
muted = BG:blend(C.from_rgba(248, 81, 73, 1), 0.4):to_css(),
subtle = BG:blend(C.from_rgba(248, 81, 73, 1), 0.15):to_css(),
},

sponsors = {
fg = scale.pink[5],
emphasis = scale.pink[6],
muted = alpha(C.from_rgba(219, 97, 162, 1), 0.4),
subtle = alpha(C.from_rgba(219, 97, 162, 1), 0.1),
muted = BG:blend(C.from_rgba(219, 97, 162, 1), 0.4):to_css(),
subtle = BG:blend(C.from_rgba(219, 97, 162, 1), 0.1):to_css(),
},
}

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

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

sel0 = alpha(C(pal.accent.fg), 0.30), -- Visual selection bg
sel1 = alpha(C(pal.accent.muted), 0.90), -- Popup sel bg
sel2 = alpha(C(pal.scale.yellow[1]), 0.20), -- Search bg
sel0 = BG:blend(C(pal.accent.fg), 0.30):to_css(), -- Visual selection bg
sel1 = BG:blend(C(pal.accent.muted), 0.90):to_css(), -- Popup sel bg
sel2 = BG:blend(C(pal.scale.yellow[1]), 0.20):to_css(), -- Search bg
}

spec.syntax = {
Expand Down Expand Up @@ -178,16 +175,16 @@ local function generate_spec(pal)
}

spec.diag_bg = {
error = C(spec.bg1):blend(C(spec.diag.error), 0.15):to_css(),
warn = C(spec.bg1):blend(C(spec.diag.warn), 0.15):to_css(),
info = C(spec.bg1):blend(C(spec.diag.info), 0.15):to_css(),
hint = C(spec.bg1):blend(C(spec.diag.hint), 0.15):to_css(),
error = BG:blend(C(spec.diag.error), 0.15):to_css(),
warn = BG:blend(C(spec.diag.warn), 0.15):to_css(),
info = BG:blend(C(spec.diag.info), 0.15):to_css(),
hint = BG:blend(C(spec.diag.hint), 0.15):to_css(),
}

spec.diff = {
add = alpha(C(pal.scale.green[6]), 0.15),
delete = alpha(C(pal.scale.red[6]), 0.15),
change = alpha(C(pal.scale.yellow[6]), 0.15),
add = BG:blend(C(pal.scale.green[6]), 0.15):to_css(),
delete = BG:blend(C(pal.scale.red[6]), 0.15):to_css(),
change = BG:blend(C(pal.scale.yellow[6]), 0.15):to_css(),
text = spec.fg0
}

Expand Down
71 changes: 34 additions & 37 deletions lua/github-theme/palette/github_dark_colorblind.lua
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,7 @@ local scale = primitives.scale
C.WHITE = C(scale.white)
C.BLACK = C(scale.black)
C.BG = C(assert(primitives.canvas.default))

local function alpha(color, a)
return color:alpha_blend(a):to_css()
end
local BG = C(assert(primitives.canvas.default))

local palette = {
scale = scale,
Expand Down Expand Up @@ -47,86 +44,86 @@ local palette = {
border = {
default = scale.gray[7],
muted = scale.gray[8],
subtle = alpha(C.from_rgba(240, 246, 252, 1), 0.1),
subtle = BG:blend(C.from_rgba(240, 246, 252, 1), 0.1):to_css(),
},

neutral = {
emphasis_plus = scale.gray[5],
emphasis = scale.gray[5],
muted = alpha(C.from_rgba(110, 118, 129, 1), 0.4),
subtle = alpha(C.from_rgba(110, 118, 129, 1), 0.1),
muted = BG:blend(C.from_rgba(110, 118, 129, 1), 0.4):to_css(),
subtle = BG:blend(C.from_rgba(110, 118, 129, 1), 0.1):to_css(),
},

accent = {
fg = scale.blue[4],
emphasis = scale.blue[6],
muted = alpha(C.from_rgba(56, 139, 253, 1), 0.4),
subtle = alpha(C.from_rgba(56, 139, 253, 1), 0.15),
muted = BG:blend(C.from_rgba(56, 139, 253, 1), 0.4):to_css(),
subtle = BG:blend(C.from_rgba(56, 139, 253, 1), 0.15):to_css(),
},

success = {
fg = scale.green[4],
emphasis = scale.green[6],
muted = alpha(C.from_rgba(46, 160, 67, 1), 0.4),
subtle = alpha(C.from_rgba(46, 160, 67, 1), 0.15),
muted = BG:blend(C.from_rgba(46, 160, 67, 1), 0.4):to_css(),
subtle = BG:blend(C.from_rgba(46, 160, 67, 1), 0.15):to_css(),
},

attention = {
fg = scale.yellow[4],
emphasis = scale.yellow[6],
muted = alpha(C.from_rgba(187, 128, 9, 1), 0.4),
subtle = alpha(C.from_rgba(187, 128, 9, 1), 0.15),
muted = BG:blend(C.from_rgba(187, 128, 9, 1), 0.4):to_css(),
subtle = BG:blend(C.from_rgba(187, 128, 9, 1), 0.15):to_css(),
},

severe = {
fg = scale.orange[5],
emphasis = scale.orange[6],
muted = alpha(C.from_rgba(219, 109, 40, 1), 0.4),
subtle = alpha(C.from_rgba(219, 109, 40, 1), 0.15),
muted = BG:blend(C.from_rgba(219, 109, 40, 1), 0.4):to_css(),
subtle = BG:blend(C.from_rgba(219, 109, 40, 1), 0.15):to_css(),
},

danger = {
fg = scale.red[5],
emphasis = scale.red[6],
muted = alpha(C.from_rgba(248, 81, 73, 1), 0.4),
subtle = alpha(C.from_rgba(248, 81, 73, 1), 0.15),
muted = BG:blend(C.from_rgba(248, 81, 73, 1), 0.4):to_css(),
subtle = BG:blend(C.from_rgba(248, 81, 73, 1), 0.15):to_css(),
},

open = {
fg = scale.orange[4],
emphasis = scale.orange[6],
muted = alpha(C.from_hex(scale.orange[5]), 0.4),
subtle = alpha(C.from_hex(scale.orange[5]), 0.15),
muted = BG:blend(C.from_hex(scale.orange[5]), 0.4):to_css(),
subtle = BG:blend(C.from_hex(scale.orange[5]), 0.15):to_css(),
},

done = {
fg = scale.purple[5],
emphasis = scale.purple[6],
muted = alpha(C.from_rgba(163, 113, 247, 1), 0.4),
subtle = alpha(C.from_rgba(163, 113, 247, 1), 0.15),
muted = BG:blend(C.from_rgba(163, 113, 247, 1), 0.4):to_css(),
subtle = BG:blend(C.from_rgba(163, 113, 247, 1), 0.15):to_css(),
},

closed = {
fg = scale.gray[4],
emphasis = scale.gray[5],
muted = alpha(C.from_hex(scale.gray[5]), 0.4),
subtle = alpha(C.from_hex(scale.gray[5]), 0.10),
muted = BG:blend(C.from_hex(scale.gray[5]), 0.4):to_css(),
subtle = BG:blend(C.from_hex(scale.gray[5]), 0.10):to_css(),
},

sponsors = {
fg = scale.pink[5],
emphasis = scale.pink[6],
muted = alpha(C.from_rgba(219, 97, 162, 1), 0.4),
subtle = alpha(C.from_rgba(219, 97, 162, 1), 0.15),
muted = BG:blend(C.from_rgba(219, 97, 162, 1), 0.4):to_css(),
subtle = BG:blend(C.from_rgba(219, 97, 162, 1), 0.15):to_css(),
},
}

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

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

sel0 = alpha(C(pal.accent.fg), 0.45), -- Visual selection bg
sel1 = alpha(C(pal.accent.muted), 0.90), -- Popup sel bg
sel2 = alpha(C(pal.scale.yellow[3]), 0.60), -- Search bg
sel0 = BG:blend(C(pal.accent.fg), 0.45):to_css(), -- Visual selection bg
sel1 = BG:blend(C(pal.accent.muted), 0.90):to_css(), -- Popup sel bg
sel2 = BG:blend(C(pal.scale.yellow[3]), 0.60):to_css(), -- Search bg
}

spec.syntax = {
Expand Down Expand Up @@ -173,16 +170,16 @@ local function generate_spec(pal)
}

spec.diag_bg = {
error = C(spec.bg1):blend(C(spec.diag.error), 0.15):to_css(),
warn = C(spec.bg1):blend(C(spec.diag.warn), 0.15):to_css(),
info = C(spec.bg1):blend(C(spec.diag.info), 0.15):to_css(),
hint = C(spec.bg1):blend(C(spec.diag.hint), 0.15):to_css(),
error = BG:blend(C(spec.diag.error), 0.15):to_css(),
warn = BG:blend(C(spec.diag.warn), 0.15):to_css(),
info = BG:blend(C(spec.diag.info), 0.15):to_css(),
hint = BG:blend(C(spec.diag.hint), 0.15):to_css(),
}

spec.diff = {
add = alpha(C(pal.scale.green[6]), 0.15),
delete = alpha(C(pal.scale.red[6]), 0.15),
change = alpha(C(pal.scale.yellow[6]), 0.15),
add = BG:blend(C(pal.scale.green[6]), 0.15):to_css(),
delete = BG:blend(C(pal.scale.red[6]), 0.15):to_css(),
change = BG:blend(C(pal.scale.yellow[6]), 0.15):to_css(),
text = spec.fg0
}

Expand Down
Loading

0 comments on commit d3e28a2

Please sign in to comment.