-
Notifications
You must be signed in to change notification settings - Fork 47
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow for dep injection into lush spec function #36
Comments
|
spec into
Get lake as parsed spec, ocean extends lake and just fiddles which groups it needs to.
Palettes should conform to some agreed shape, probably have three specs
Define palettes -- norm and comment are different colors but are applied the same
-- no matter which spec
-- light_palette.lua -- dark_palette.lua
light = { dark = {
norm = hsl(blue), norm = hsl(dark_blue),
comment = hsl(red) comment = hsl(dark_red),
light_tone = hsl(green) dark_tone = hsl(orange)
} } Define base -- base.lua
return function(palette)
Normal { fg = palette.norm },
Comment { fg = palett.comment }
end Define light -- light.lua
-- get palette
palette = require("lush_theme.ld.light_palette")
-- get base generator
base_fn = require("lush_theme.ld.base")
-- apply palette to base
base_spec = lush.inject(palette).with(base_fn)
-- extend base for light specifics
return lush.extends(base_spec).with(function()
CursorLine { bg = palette.light_tone },
Search { base.Normal, fg = base.Normal.fg.lighten(20) }
end) Define dark -- dark.lua
-- get palette
palette = require("lush_theme.ld.dark_palette")
-- get base generator
base_fn = require("lush_theme.ld.base")
-- apply palette to base
base_spec = lush.inject(palette).with(base_fn)
-- extend base for light specifics
return lush.extends(base_spec).with(function()
CursorLine { bg = palette.dark_tone },
Search { base.Normal, fg = base.Normal.fg.darken(20) }
end) Important, both light.lua and dark.lua return valid specs, so they can be used with extends by an end user. A lush spec file should always return a lush spec, fully formed. Now either colors.vim checks some config val " colors.vim
if g:ld_style == "light" then
lua require("lush")(require("lush_theme.ld.light")
else
lua require("lush")(require("lush_theme.ld.light")
end OR, there is a third "spec" that does the same thing in lua and returns the real spec. -- light_or_dark.lua
return require("lush_theme.ld."..vim.g.ld_style) -- colors.vim
lua require("lush")(require("lush_theme.ld.light_or_dark") |
The split files starts to break |
This is an interesting feature for me. I'm building some spin-offs to zenbones but my solution so far is "monkey-patching" the palette module used in generating the specs. It technically works but it's ugly and probably a maintenance hell. It can probably be worked around by wrapping things into functions that can generate palettes or specs. local function generate_specs(palette)
return lush(function()
return {
Normal { fg = palette.fg }
}
end)
end
lush(generate_specs({ fg = lush.hsl(0, 0, 0) })) |
My idea for backwards compatibility: in addition to colors that can be stringified, we can have a function that accepts a dependency table. local function InjectableColors()
return setmetatable({}, {
__index = function(_, key)
return function(deps) return deps[key] end
end,
})
end
local colors = InjectableColors()
local parsed = lush(function()
return {
HighlightA = colors.blue, -- function that can accept a dependency later on
HighlightB = hsl("#dadada"), -- can be stringified directly
}
end)
lush(parsed) -- errors, because dependency is still missing
parsed.inject { blue = hsl("#3238a8") } -- associate this table as a dependency for this spec
lush(parsed) -- injectable color objects will now be resolved here using the table above
parsed.inject { blue = hsl("#16c4f7") } -- re-injection is possible
lush(parsed) What do you think of this workflow? |
This is just a "work with the shed door open" kind of issue, subject to change.
This should allow for a scheme to handle light and dark modes without having to maintain two specs.
How to do this:
Is the chaining all "too smart", maintain old chains but move to a
function or table
inference and promote more complicated to build the config in parts? Can probably show deprecation warnings when running Lushify.The text was updated successfully, but these errors were encountered: