Files
neovim-config/lua/taken/utils/themes.lua

66 lines
2.3 KiB
Lua

local M = {}
function M.themeselector(opts)
local themefuncs = require("taken.utils.themefuncs")
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 ivytheme = require("telescope.themes").get_ivy()
local themes = themefuncs.get_all_themes()
local change_theme = themefuncs.change_theme
local current_theme = vim.g.colors_name
opts = opts or {}
local combined = vim.tbl_extend("force", ivytheme, {
layout_config = {
height = 10,
},
}, opts)
vim.cmd("SunglassesDisable")
pickers
.new(combined, {
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()
change_theme(selection.value)
vim.cmd("SunglassesEnable")
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
vim.cmd("colorscheme " .. current_theme)
vim.cmd("SunglassesEnable")
end,
})
return true
end,
})
:find()
end
return M