81 lines
2.6 KiB
Lua
81 lines
2.6 KiB
Lua
local pickers = require("telescope.pickers")
|
|
local finders = require("telescope.finders")
|
|
local previewers = require("telescope.previewers")
|
|
local conf = require("telescope.config").values
|
|
local actions = require("telescope.actions")
|
|
local action_set = require("telescope.actions.set")
|
|
local action_state = require("telescope.actions.state")
|
|
local misc = require('core.misc')
|
|
|
|
local M = {}
|
|
|
|
function M.switcher()
|
|
local bufnr = vim.api.nvim_get_current_buf()
|
|
|
|
-- show current buffer content in previewer
|
|
local colors = vim.fn.getcompletion('', 'color')
|
|
for k, v in pairs(colors) do
|
|
if v.find(v, '.ext') then
|
|
table.remove(colors, k)
|
|
break
|
|
end
|
|
end
|
|
|
|
-- our picker function: colors
|
|
pickers.new({
|
|
prompt_title = "Set Nvim Colorscheme",
|
|
finder = finders.new_table { results = colors },
|
|
sorter = conf.generic_sorter(),
|
|
previewer = previewers.new_buffer_previewer {
|
|
define_preview = function(self, entry)
|
|
-- add content
|
|
local lines = vim.api.nvim_buf_get_lines(bufnr, 0, -1, false)
|
|
vim.api.nvim_buf_set_lines(self.state.bufnr, 0, -1, false, lines)
|
|
|
|
-- add syntax highlighting in previewer
|
|
local ft = (vim.filetype.match { buf = bufnr } or "diff"):match "%w+"
|
|
require("telescope.previewers.utils").highlighter(self.state.bufnr, ft)
|
|
end
|
|
},
|
|
|
|
attach_mappings = function(prompt_bufnr, map)
|
|
-- reload theme while typing
|
|
vim.schedule(function()
|
|
vim.api.nvim_create_autocmd("TextChangedI", {
|
|
buffer = prompt_bufnr,
|
|
callback = function()
|
|
if action_state.get_selected_entry() then
|
|
misc.colorscheme(action_state.get_selected_entry()[1])
|
|
end
|
|
end,
|
|
})
|
|
end)
|
|
|
|
-- reload theme on cycling
|
|
actions.move_selection_previous:replace(function()
|
|
action_set.shift_selection(prompt_bufnr, -1)
|
|
misc.colorscheme(action_state.get_selected_entry()[1])
|
|
end)
|
|
actions.move_selection_next:replace(function()
|
|
action_set.shift_selection(prompt_bufnr, 1)
|
|
misc.colorscheme(action_state.get_selected_entry()[1])
|
|
end)
|
|
|
|
-- reload theme on selection
|
|
actions.select_default:replace(function()
|
|
if action_state.get_selected_entry() then
|
|
actions.close(prompt_bufnr)
|
|
misc.colorscheme(action_state.get_selected_entry()[1])
|
|
|
|
-- make the colorscheme swap persistant
|
|
misc.replaceword("misc.colorscheme%(.+%)",
|
|
"misc.colorscheme('"..action_state.get_selected_entry()[1].."')")
|
|
end
|
|
end)
|
|
return true
|
|
end,
|
|
}):find()
|
|
end
|
|
|
|
return M
|