Updated theme swithcher

This commit is contained in:
2024-10-04 12:52:30 +02:00
parent 5b9c611145
commit ab5470adc8

View File

@@ -1,12 +1,19 @@
local M = {} local M = {}
function M.themeselector() function M.themeselector(opts)
vim.api.nvim_exec_autocmds("User", { pattern = "ThemeSwitcher", modeline = false }) local pickers = require("telescope.pickers")
local finders = require("telescope.finders")
local conf = require("telescope.config").values
local actions = require("telescope.actions")
local action_state = require("telescope.actions.state")
local action_set = require("telescope.actions.set")
local configDir = vim.fn.stdpath("config") local configDir = vim.fn.stdpath("config")
local prefsFile = configDir .. "/lua/taken/prefs.lua" local prefsFile = configDir .. "/lua/taken/prefs.lua"
local oldstring = 'M.colorscheme = .*"' local oldstring = 'M.colorscheme = .*"'
vim.api.nvim_exec_autocmds("User", { pattern = "ThemeSwitcher", modeline = false })
local colors = vim.fn.globpath(vim.o.rtp, "colors/*", 1, 1) local colors = vim.fn.globpath(vim.o.rtp, "colors/*", 1, 1)
local dataDir = vim.fn.stdpath("data") local dataDir = vim.fn.stdpath("data")
local newpath = string.gsub(dataDir, "%-", "%%-") local newpath = string.gsub(dataDir, "%-", "%%-")
@@ -27,10 +34,6 @@ function M.themeselector()
end end
end end
local opts = {
prompt = "Select a theme",
}
local function change_theme(old, new) local function change_theme(old, new)
-- function from nvchad -- function from nvchad
local file = io.open(prefsFile, "r") local file = io.open(prefsFile, "r")
@@ -58,7 +61,42 @@ function M.themeselector()
end end
end end
vim.ui.select(themes, opts, exec) opts = opts or {}
pickers
.new(opts, {
prompt_title = "Colorscheme",
finder = finders.new_table({
results = themes,
}),
sorter = conf.generic_sorter(opts),
attach_mappings = function(prompt_bufnr)
actions.select_default:replace(function()
actions.close(prompt_bufnr)
local selection = action_state.get_selected_entry()
exec(selection.value)
end)
action_set.shift_selection:enhance({
post = function()
local selection = action_state.get_selected_entry()
if selection == nil then
vim.notify("Error while selecting theme", vim.log.levels.ERROR)
end
vim.cmd("colorscheme " .. selection.value)
end,
})
actions.close:enhance({
post = function()
local selection = action_state.get_selected_entry()
if selection == nil then
vim.notify("Error while selecting theme", vim.log.levels.ERROR)
end
exec(selection.value)
end,
})
return true
end,
})
:find()
end end
return M return M