Skip to content

Commit

Permalink
fix(Color): don't use shared global state
Browse files Browse the repository at this point in the history
Fixes: #362
  • Loading branch information
tmillr committed Aug 8, 2024
1 parent 43b6536 commit 03a8853
Show file tree
Hide file tree
Showing 13 changed files with 26 additions and 15 deletions.
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
3 changes: 2 additions & 1 deletion lua/github-theme/palette/github_dark.lua
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@ local scale = primitives.scale
C.WHITE = C(scale.white)
C.BLACK = C(scale.black)
C.BG = C(scale.gray[7])
local BG = C(scale.gray[7])

local function alpha(color, a)
return color:alpha_blend(a):to_css()
return BG:blend(color, a):to_css()
end

local palette = {
Expand Down
3 changes: 2 additions & 1 deletion lua/github-theme/palette/github_dark_colorblind.lua
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@ local scale = primitives.scale
C.WHITE = C(scale.white)
C.BLACK = C(scale.black)
C.BG = C(assert(primitives.canvas.default))
local BG = C(assert(primitives.canvas.default))

local function alpha(color, a)
return color:alpha_blend(a):to_css()
return BG:blend(color, a):to_css()
end

local palette = {
Expand Down
3 changes: 2 additions & 1 deletion lua/github-theme/palette/github_dark_default.lua
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@ local scale = primitives.scale
C.WHITE = C(scale.white)
C.BLACK = C(scale.black)
C.BG = C(assert(primitives.canvas.default))
local BG = C(assert(primitives.canvas.default))

local function alpha(color, a)
return color:alpha_blend(a):to_css()
return BG:blend(color, a):to_css()
end

local palette = {
Expand Down
3 changes: 2 additions & 1 deletion lua/github-theme/palette/github_dark_dimmed.lua
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@ local scale = primitives.scale
C.WHITE = C(scale.white)
C.BLACK = C(scale.black)
C.BG = C(assert(primitives.canvas.default))
local BG = C(assert(primitives.canvas.default))

local function alpha(color, a)
return color:alpha_blend(a):to_css()
return BG:blend(color, a):to_css()
end

local palette = {
Expand Down
3 changes: 2 additions & 1 deletion lua/github-theme/palette/github_dark_high_contrast.lua
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@ local scale = primitives.scale
C.WHITE = C(scale.white)
C.BLACK = C(scale.black)
C.BG = C(assert(primitives.canvas.default))
local BG = C(assert(primitives.canvas.default))

local function alpha(color, a)
return color:alpha_blend(a):to_css()
return BG:blend(color, a):to_css()
end

local palette = {
Expand Down
3 changes: 2 additions & 1 deletion lua/github-theme/palette/github_dark_tritanopia.lua
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@ local scale = primitives.scale
C.WHITE = C(scale.white)
C.BLACK = C(scale.black)
C.BG = C(assert(primitives.canvas.default))
local BG = C(assert(primitives.canvas.default))

local function alpha(color, a)
return color:alpha_blend(a):to_css()
return BG:blend(color, a):to_css()
end

local palette = {
Expand Down
3 changes: 2 additions & 1 deletion lua/github-theme/palette/github_light.lua
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@ local scale = primitives.scale
C.WHITE = C(scale.white)
C.BLACK = C(scale.black)
C.BG = C(scale.white)
local BG = C(scale.white)

local function alpha(color, a)
return color:alpha_blend(a):to_css()
return BG:blend(color, a):to_css()
end

-- Temp override until Primitives are updated
Expand Down
3 changes: 2 additions & 1 deletion lua/github-theme/palette/github_light_colorblind.lua
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@ local scale = primitives.scale
C.WHITE = C(scale.white)
C.BLACK = C(scale.black)
C.BG = C(assert(primitives.canvas.default))
local BG = C(assert(primitives.canvas.default))

local function alpha(color, a)
return color:alpha_blend(a):to_css()
return BG:blend(color, a):to_css()
end

-- Temp override until Primitives are updated
Expand Down
3 changes: 2 additions & 1 deletion lua/github-theme/palette/github_light_default.lua
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@ local scale = primitives.scale
C.WHITE = C(scale.white)
C.BLACK = C(scale.black)
C.BG = C(assert(primitives.canvas.default))
local BG = C(assert(primitives.canvas.default))

local function alpha(color, a)
return color:alpha_blend(a):to_css()
return BG:blend(color, a):to_css()
end

-- Temp override until Primitives are updated
Expand Down
3 changes: 2 additions & 1 deletion lua/github-theme/palette/github_light_high_contrast.lua
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@ local scale = primitives.scale
C.WHITE = C(scale.white)
C.BLACK = C(scale.black)
C.BG = C(assert(primitives.canvas.default))
local BG = C(assert(primitives.canvas.default))

local function alpha(color, a)
return color:alpha_blend(a):to_css()
return BG:blend(color, a):to_css()
end

-- Temp override until Primitives are updated
Expand Down
3 changes: 2 additions & 1 deletion lua/github-theme/palette/github_light_tritanopia.lua
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@ local scale = primitives.scale
C.WHITE = C(scale.white)
C.BLACK = C(scale.black)
C.BG = C(assert(primitives.canvas.default))
local BG = C(assert(primitives.canvas.default))

local function alpha(color, a)
return color:alpha_blend(a):to_css()
return BG:blend(color, a):to_css()
end

-- Temp override until Primitives are updated
Expand Down
6 changes: 3 additions & 3 deletions test/github-theme/color_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -224,15 +224,15 @@ describe('Color', function()
end)
end)

describe('global state `Color.{WHITE,BLACK,BG}`', function()
describe('global fields/state `Color.{WHITE,BLACK,BG}`', function()
local theme = 'github_dark_dimmed'
before_each(function()
require('github-theme.util.reload')(true)
vim.g.github_theme_force_compile = true
end)

-- See #362
it('should not disrupt palette/spec', function()
it('should not disrupt colors in palette/spec/groups', function()
local groups_expected = require('github-theme.group').load(theme)
require('github-theme.util.reload')(true)

Expand All @@ -256,7 +256,7 @@ describe('Color', function()

local function index(_, k)
if k == 'BG' or k == 'WHITE' or k == 'BLACK' then
error(debug.traceback('Color.' .. k .. ' was accessed internally'))
error('Color.' .. k .. ' was accessed internally', 2)
end
return rawget(C --[[@as table]], k)
end
Expand Down

0 comments on commit 03a8853

Please sign in to comment.