You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

67 lines
1.7 KiB
Lua

3 years ago
if not pcall(require, "fzf") then
return
end
local action = require("fzf.actions").action
3 years ago
local core = require "fzf-lua.core"
local utils = require "fzf-lua.utils"
local config = require "fzf-lua.config"
local actions = require "fzf-lua.actions"
local function get_current_colorscheme()
if vim.g.colors_name then
return vim.g.colors_name
else
return 'default'
end
end
local M = {}
M.colorschemes = function(opts)
opts = config.normalize_opts(opts, config.globals.colorschemes)
if not opts then return end
3 years ago
coroutine.wrap(function ()
local prev_act = action(function (args)
if opts.live_preview and args then
local colorscheme = args[1]
vim.cmd("colorscheme " .. colorscheme)
end
end)
local current_colorscheme = get_current_colorscheme()
local current_background = vim.o.background
local colors = vim.list_extend(opts.colors or {}, vim.fn.getcompletion('', 'color'))
-- must add ':nohidden' or fzf ignore the preview action
-- disabling our live preview of colorschemes
opts.preview = prev_act
opts.preview_window = opts.preview_window or 'nohidden:right:0'
opts.nomulti = utils._if(opts.nomulti~=nil, opts.nomulti, true)
local selected = core.fzf(opts, colors)
3 years ago
-- reset color scheme if live_preview is enabled
-- and nothing or non-default action was selected
if opts.live_preview and (not selected or #selected[1]>0) then
3 years ago
vim.o.background = current_background
vim.cmd("colorscheme " .. current_colorscheme)
vim.o.background = current_background
end
if selected then
actions.act(opts.actions, selected)
3 years ago
end
if opts.post_reset_cb then
opts.post_reset_cb()
end
end)()
end
return M