From 9dfa5c33ed5ec7da6ffdc4b7cf8ba91c66745d26 Mon Sep 17 00:00:00 2001 From: Alexander van Zyl Date: Sun, 14 Jan 2024 12:46:39 +0000 Subject: [PATCH] Fixes and utilities (#107) * 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 --- lua/nordic/colors/init.lua | 12 +++++++++++- lua/nordic/utils.lua | 10 +++++++++- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/lua/nordic/colors/init.lua b/lua/nordic/colors/init.lua index db5bc302..0ebd3910 100644 --- a/lua/nordic/colors/init.lua +++ b/lua/nordic/colors/init.lua @@ -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) @@ -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 @@ -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 diff --git a/lua/nordic/utils.lua b/lua/nordic/utils.lua index ef9fd68c..26de7902 100644 --- a/lua/nordic/utils.lua +++ b/lua/nordic/utils.lua @@ -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 @@ -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) }