diff --git a/lua/taken/utils/themes.lua b/lua/taken/utils/themes.lua index c455d95..808ed92 100644 --- a/lua/taken/utils/themes.lua +++ b/lua/taken/utils/themes.lua @@ -1,12 +1,19 @@ local M = {} -function M.themeselector() - vim.api.nvim_exec_autocmds("User", { pattern = "ThemeSwitcher", modeline = false }) +function M.themeselector(opts) + 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 prefsFile = configDir .. "/lua/taken/prefs.lua" 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 dataDir = vim.fn.stdpath("data") local newpath = string.gsub(dataDir, "%-", "%%-") @@ -27,10 +34,6 @@ function M.themeselector() end end - local opts = { - prompt = "Select a theme", - } - local function change_theme(old, new) -- function from nvchad local file = io.open(prefsFile, "r") @@ -58,7 +61,42 @@ function M.themeselector() 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 return M