Skip to content

Commit

Permalink
feat(colorschemes): explore colorschemes from Awesome Neovim
Browse files Browse the repository at this point in the history
  • Loading branch information
ibhagwan committed Mar 9, 2024
1 parent 1422822 commit 3ada77b
Show file tree
Hide file tree
Showing 8 changed files with 882 additions and 106 deletions.
72 changes: 48 additions & 24 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -316,27 +316,28 @@ Alternatively, resuming work on a specific provider:
### Misc
| Command | List |
| ---------------- | ------------------------------------------ |
| `resume` | resume last command/query |
| `builtin` | fzf-lua builtin commands |
| `profiles` | fzf-lua configuration profiles |
| `help_tags` | help tags |
| `man_pages` | man pages |
| `colorschemes` | color schemes |
| `highlights` | highlight groups |
| `commands` | neovim commands |
| `command_history` | command history |
| `search_history` | search history |
| `marks` | :marks |
| `jumps` | :jumps |
| `changes` | :changes |
| `registers` | :registers |
| `tagstack` | :tags |
| `autocmds` | :autocmd |
| `keymaps` | key mappings |
| `filetypes` | filetypes |
| `menus` | menus |
| `spell_suggest` | spelling suggestions |
| `packadd` | :packadd <package> |
| `resume` | resume last command/query |
| `builtin` | fzf-lua builtin commands |
| `profiles` | fzf-lua configuration profiles |
| `help_tags` | help tags |
| `man_pages` | man pages |
| `colorschemes` | color schemes |
| `awesome_colorschemes` | Awesome Neovim color schemes |
| `highlights` | highlight groups |
| `commands` | neovim commands |
| `command_history` | command history |
| `search_history` | search history |
| `marks` | :marks |
| `jumps` | :jumps |
| `changes` | :changes |
| `registers` | :registers |
| `tagstack` | :tags |
| `autocmds` | :autocmd |
| `keymaps` | key mappings |
| `filetypes` | filetypes |
| `menus` | menus |
| `spell_suggest` | spelling suggestions |
| `packadd` | :packadd <package> |

### Neovim API

Expand Down Expand Up @@ -1092,13 +1093,36 @@ require'fzf-lua'.setup {
colorschemes = {
prompt = 'Colorschemes❯ ',
live_preview = true, -- apply the colorscheme on preview?
actions = { ["default"] = actions.colorscheme, },
actions = { ["default"] = actions.colorscheme },
winopts = { height = 0.55, width = 0.30, },
-- uncomment to ignore colorschemes names (lua patterns)
-- ignore_patterns = { "^delek$", "^blue$" },
-- uncomment to execute a callback after interface is closed
-- uncomment to execute a callback on preview|close
-- e.g. a call to reset statusline highlights
-- post_reset_cb = function() ... end,
-- cb_preview = function() ... end,
-- cb_exit = function() ... end,
},
awesome_colorschemes = {
prompt = 'Colorschemes❯ ',
live_preview = true, -- apply the colorscheme on preview?
max_threads = 5, -- max download/update threads
winopts = { row = 0, col = 0.99, width = 0.50 },
fzf_opts = {
["--info"] = "default",
["--multi"] = true,
["--delimiter"] = "[:]",
["--with-nth"] = "3..",
["--tiebreak"] = "index",
},
actions = {
["default"] = actions.colorscheme,
["ctrl-g"] = { fn = actions.toggle_bg, exec_silent = true },
["ctrl-r"] = { fn = actions.cs_update, reload = true },
["ctrl-x"] = { fn = actions.cs_delete, reload = true },
},
-- uncomment to execute a callback on preview|close
-- cb_preview = function() ... end,
-- cb_exit = function() ... end,
},
keymaps = {
prompt = "Keymaps> ",
Expand Down
43 changes: 39 additions & 4 deletions lua/fzf-lua/actions.lua
Original file line number Diff line number Diff line change
Expand Up @@ -388,11 +388,46 @@ M.buf_edit_or_qf = function(selected, opts)
end
end

M.colorscheme = function(selected)
local colorscheme = selected[1]
vim.cmd("colorscheme " .. colorscheme)
-- setup fzf-lua's own highlight groups
M.colorscheme = function(selected, opts)
local dbkey, idx = selected[1]:match("^(.-):(%d+):")
if dbkey then
local info = opts._adm:get(dbkey)
local cs = info.variants[tonumber(idx)]
if cs.vim then
pcall(vim.cmd, cs.vim)
elseif cs.lua then
pcall(function() loadstring(cs.lua)() end)
else
pcall(vim.cmd.colorscheme, cs.name)
end
else
local colorscheme = selected[1]:match("^[^:]+")
pcall(vim.cmd.colorscheme, colorscheme)
end
end

M.cs_delete = function(selected, opts)
for _, s in ipairs(selected) do
local dbkey = s:match("^(.-):%d+:")
opts._adm:delete(dbkey)
end
end

M.cs_update = function(selected, opts)
local dedup = {}
for _, s in ipairs(selected) do
local dbkey = s:match("^(.-):%d+:")
if dbkey then dedup[dbkey] = true end
end
for k, _ in pairs(dedup) do
opts._adm:update(k)
end
end

M.toggle_bg = function(_, _)
vim.o.background = vim.o.background == "dark" and "light" or "dark"
utils.setup_highlights()
utils.info(string.format([[background set to "%s"]], vim.o.background))
end

M.ensure_insert_mode = function()
Expand Down
5 changes: 4 additions & 1 deletion lua/fzf-lua/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -574,7 +574,6 @@ M._action_to_helpstr = {
[actions.buf_del] = "buffer-delete",
[actions.buf_switch] = "buffer-switch",
[actions.buf_switch_or_edit] = "buffer-switch-or-edit",
[actions.colorscheme] = "set-colorscheme",
[actions.run_builtin] = "run-builtin",
[actions.ex_run] = "edit-cmd",
[actions.ex_run_cr] = "exec-cmd",
Expand Down Expand Up @@ -622,6 +621,10 @@ M._action_to_helpstr = {
[actions.apply_profile] = "apply-profile",
[actions.complete] = "complete",
[actions.dap_bp_del] = "dap-bp-delete",
[actions.colorscheme] = "colorscheme-apply",
[actions.cs_delete] = "colorscheme-delete",
[actions.cs_update] = "colorscheme-update",
[actions.toggle_bg] = "toggle-background",
}

return M
8 changes: 8 additions & 0 deletions lua/fzf-lua/core.lua
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,17 @@ M.ACTION_DEFINITIONS = {
end
end,
},
[actions.toggle_bg] = {
function(_)
-- return string.format("set bg=%s", vim.o.background == "dark" and "light" or "dark")
return "toggle bg"
end,
},
[actions.buf_del] = { "close" },
[actions.arg_del] = { "delete" },
[actions.dap_bp_del] = { "delete" },
[actions.cs_delete] = { "uninstall" },
[actions.cs_update] = { "[down|re]-load" },
[actions.git_reset] = { "reset" },
[actions.git_stage] = { "stage", pos = 1 },
[actions.git_unstage] = { "unstage", pos = 2 },
Expand Down
Loading

0 comments on commit 3ada77b

Please sign in to comment.