Skip to content

Background gets stuck after switching it once #1

@Slotos

Description

@Slotos

When switching background, the option gets stuck, overriding even explicit light or dark theme selection afterwards. I've done some tweaking and the following diff results in the colorscheme initializing correctly, presenting explicit non-sticky dark and light variants, and following vim.o.background regardless of which explicit version was selected, unless configuration enforces one.

diff --git a/colors/litepal.vim b/colors/litepal.vim
deleted file mode 100644
index 519bbdb..0000000
--- a/colors/litepal.vim
+++ /dev/null
@@ -1 +0,0 @@
-lua require('nitepal').colorscheme('light') 
diff --git a/colors/nitepal-dark.lua b/colors/nitepal-dark.lua
new file mode 100644
index 0000000..5cec80c
--- /dev/null
+++ b/colors/nitepal-dark.lua
@@ -0,0 +1 @@
+require('nitepal').colorscheme('dark')
diff --git a/colors/nitepal-light.lua b/colors/nitepal-light.lua
new file mode 100644
index 0000000..2ff593b
--- /dev/null
+++ b/colors/nitepal-light.lua
@@ -0,0 +1 @@
+require('nitepal').colorscheme('light')
diff --git a/colors/nitepal.lua b/colors/nitepal.lua
new file mode 100644
index 0000000..9b9fcb4
--- /dev/null
+++ b/colors/nitepal.lua
@@ -0,0 +1 @@
+require('nitepal').colorscheme()
diff --git a/colors/nitepal.vim b/colors/nitepal.vim
deleted file mode 100644
index dba74c2..0000000
--- a/colors/nitepal.vim
+++ /dev/null
@@ -1 +0,0 @@
-lua require('nitepal').colorscheme()
diff --git a/lua/lualine/themes/litepal.lua b/lua/lualine/themes/litepal.lua
deleted file mode 100644
index 24f7681..0000000
--- a/lua/lualine/themes/litepal.lua
+++ /dev/null
@@ -1 +0,0 @@
-return require('nitepal.theme').generate_lualine('light')
diff --git a/lua/lualine/themes/nitepal.lua b/lua/lualine/themes/nitepal.lua
index 9dd1790..da8a002 100644
--- a/lua/lualine/themes/nitepal.lua
+++ b/lua/lualine/themes/nitepal.lua
@@ -1 +1 @@
-return require('nitepal.theme').generate_lualine('dark')
+return require('nitepal.theme').generate_lualine(vim.o.bg)
diff --git a/lua/nitepal/init.lua b/lua/nitepal/init.lua
index 1e5708e..f44a61d 100644
--- a/lua/nitepal/init.lua
+++ b/lua/nitepal/init.lua
@@ -1,32 +1,26 @@
 local nitepal = {}
 
 function nitepal.colorscheme(style)
-    if require('nitepal.config').options.style == false then
-        style = style or vim.o.background
+  style = style or require('nitepal.config').options.style or vim.o.bg
 
-        require('nitepal.config').options.style = style
-    else
-        style = require('nitepal.config').options.style
-    end
+  if style ~= 'dark' and style ~= 'light' then
+    error('Invalid style: ' .. style)
+  end
 
-    if style ~= 'dark' and style ~= 'light' then
-        error('Invalid style: ' .. style)
-    end
+  vim.cmd([[hi clear]])
 
-    vim.cmd([[hi clear]])
+  if vim.fn.exists([[syntax_on]]) then
+    vim.cmd([[syntax reset]])
+  end
 
-    if vim.fn.exists([[syntax_on]]) then
-        vim.cmd([[syntax reset]])
-    end
+  if vim.o.background ~= style then
+    vim.o.background = style
+  end
 
-    if vim.o.background ~= style then
-        vim.o.background = style
-    end
+  vim.o.termguicolors = true
+  vim.g.colors_name = 'nitepal'
 
-    vim.o.termguicolors = true
-    vim.g.colors_name = style == 'dark' and 'nitepal' or 'litepal'
-
-    require('nitepal.theme').init()
+  require('nitepal.theme').init()
 end
 
 return nitepal

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions