Updated theme switchers

This commit is contained in:
2024-10-15 19:09:57 +02:00
parent d27fa532dc
commit 0d5eb1e82c
3 changed files with 30 additions and 8 deletions

View File

@@ -1,5 +1,9 @@
local oldstring = 'M.colorscheme = .*"'
local configDir = vim.fn.stdpath("config")
local prefsFile = configDir .. "/lua/taken/prefs.lua"
--- themes
--- @return table
local getAllThemes = function()
vim.api.nvim_exec_autocmds("User", { pattern = "ThemeSwitcher", modeline = false })
@@ -26,7 +30,10 @@ local getAllThemes = function()
return themes
end
local change_theme = function(old, new, prefsFile)
--- change theme
--- @param old string
--- @param new string
local change_theme = function(old, new)
-- function from nvchad
local file = io.open(prefsFile, "r")
local added_pattern = string.gsub(old, "-", "%%-")
@@ -37,7 +44,9 @@ local change_theme = function(old, new, prefsFile)
file:close()
end
local applytofile = function(choice, prefsFile)
--- applytofile
--- @param choice string
local applytofile = function(choice)
if choice == nil then
vim.notify("No theme selected!", 4)
return
@@ -45,7 +54,7 @@ local applytofile = function(choice, prefsFile)
vim.cmd("colorscheme " .. choice)
local newstring = 'M.colorscheme = "' .. choice .. '"'
change_theme(oldstring, newstring, prefsFile)
change_theme(oldstring, newstring)
local cursorcolumncolor = vim.fn.synIDattr(vim.fn.hlID("CursorColumn"), "bg")
if cursorcolumncolor ~= "" then

View File

@@ -9,9 +9,6 @@ function M.themeselector(opts)
local action_state = require("telescope.actions.state")
-- local action_set = require("telescope.actions.set")
local configDir = vim.fn.stdpath("config")
local prefsFile = configDir .. "/lua/taken/prefs.lua"
local themes = themefuncs.getAllThemes()
local applytofile = themefuncs.applytofile