Skip to content

Commit

Permalink
Fixes and utilities (#107)
Browse files Browse the repository at this point in the history
* Fix(palette): Extend if required before theme is loaded

* Ref(utils): Reduce reliance on strings

Squash me

* Fix: Transparent background for floating border

See #48
  • Loading branch information
AlexvZyl authored Jan 14, 2024
1 parent 5e8d79c commit 9dfa5c3
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
12 changes: 11 additions & 1 deletion lua/nordic/colors/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@ local U = require 'nordic.utils'
local O = require('nordic.config').options
local C = require 'nordic.colors.nordic'

C.extended = false

function C.extend_palette()
C.extended = true

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

Expand Down Expand Up @@ -56,7 +60,7 @@ function C.extend_palette()
C.fg_popup_border = C.border_fg

-- Floating windows
C.bg_float = C.black1
C.bg_float = (O.transparent_bg and C.none) or C.black1
C.fg_float = C.fg
C.bg_float_border = C.bg_float
C.fg_float_border = C.border_fg
Expand Down Expand Up @@ -90,4 +94,10 @@ function C.extend_palette()
end
end

-- Sometimes the palette is required before the theme has been loaded,
-- so we need to extend the palette in those cases.
if not C.extended then
C.extend_palette()
end

return C
10 changes: 9 additions & 1 deletion lua/nordic/utils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,14 @@ function M.highlight(table)
end
end

function M.is_none(string)
return string == 'NONE' or string == 'none'
end

function M.none()
return 'NONE'
end

function M.merge(table1, table2)
if table1 == table2 == nil then return {} end
if table1 == nil then
Expand Down Expand Up @@ -107,7 +115,7 @@ end

-- Adapted from @folke/tokyonight.nvim.
function M.blend(foreground, background, alpha)
if foreground == 'NONE' or background == 'NONE' then return 'NONE' end
if M.is_none(foreground) or M.is_none(background) then return M.none() end

local fg = { M.hex_to_rgb(foreground) }
local bg = { M.hex_to_rgb(background) }
Expand Down

0 comments on commit 9dfa5c3

Please sign in to comment.