Skip to content

Commit

Permalink
fix(build_palette): fix broken reload in stateless palette; (#137)
Browse files Browse the repository at this point in the history
  • Loading branch information
5-pebbles authored May 29, 2024
1 parent 80c65ab commit adc8b8c
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 19 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ Nordic will use the default values, unless `setup` is called. Below is the defau
```lua
require 'nordic' .setup {
-- This callback can be used to override the colors used in the palette.
on_palette = function(palette) return palette end,
on_palette = function(palette) end,
-- Enable bold keywords.
bold_keywords = false,
-- Enable italic comments.
Expand Down
16 changes: 4 additions & 12 deletions lua/nordic/colors/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,9 @@ local P = require 'nordic.colors.nordic'

local C = {}

local function build_palette()
-- Make a new palette.
-- Copy the original palette this overrides C.
C = vim.deepcopy(P)
-- Because of the override we need to re-add the build_palette to the C table.
C.build_palette = build_palette
-- If we had attached build_palette to C we would lost it after the override.
function C.build_palette()
-- override all values from the base palette
U.merge_inplace(C, P)

local options = require('nordic.config').options

Expand All @@ -18,7 +14,7 @@ local function build_palette()
C.white0 = (options.reduced_blue and C.white0_reduce_blue) or C.white0_normal

-- Modify the palette before generating colors.
C = options.on_palette(C)
options.on_palette(C)

-- Add these for international convenience :)
C.grey0 = C.gray0
Expand Down Expand Up @@ -100,8 +96,4 @@ local function build_palette()
C.comment = C.gray4
end

-- build the first palette
build_palette()
-- after this we can call it with C.build_palette()

return C
10 changes: 4 additions & 6 deletions lua/nordic/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@ local M = {}

local defaults = {
-- This callback can be used to override the colors used in the palette.
on_palette = function(palette)
return palette
end,
on_palette = function(palette) end,
-- Enable bold keywords.
bold_keywords = false,
-- Enable italic comments.
Expand All @@ -18,9 +16,9 @@ local defaults = {
},
-- Enable brighter float border.
bright_border = false,
-- Adjusts some colors to make the theme a bit nicer (imo).
-- Reduce the overall amount of blue in the theme (diverges from base Nord).
reduced_blue = true,
-- Swop the dark background with the normal one.
-- Swap the dark background with the normal one.
swap_backgrounds = false,
-- Override the styling of any highlight group.
override = {},
Expand Down Expand Up @@ -58,7 +56,7 @@ M.options = defaults
-- called automatically by load
function M.setup(options)
-- backwards compatibility
options = require 'nordic.compatibility'(options)
options = require 'nordic.compatibility' (options)

-- set defaults
M.options = vim.tbl_deep_extend('force', M.options or defaults, options or {})
Expand Down
13 changes: 13 additions & 0 deletions lua/nordic/utils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,19 @@ function M.merge(table1, table2)
return vim.tbl_deep_extend('force', table1, table2)
end

function M.merge_inplace(table1, table2)
for k, v in pairs(table2) do
if type(v) == "table" then
if type(table1[k]) ~= "table" then
table1[k] = {}
end
M.merge_inplace(table1[k], v)
else
table1[k] = v
end
end
end

function M.hex_to_rgb(str)
str = string.lower(str)
return tonumber(str:sub(2, 3), 16), tonumber(str:sub(4, 5), 16), tonumber(str:sub(6, 7), 16)
Expand Down

0 comments on commit adc8b8c

Please sign in to comment.