Skip to content

Commit cd1c055

Browse files
committed
added functionality to choose using a dropdown
1 parent 81c5dbd commit cd1c055

File tree

5 files changed

+61
-73
lines changed

5 files changed

+61
-73
lines changed

lua/switchscheme.lua

Lines changed: 0 additions & 73 deletions
This file was deleted.

lua/switchscheme/commands.lua

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
local telescope_ui = require("switchscheme.telescope_ui")
2+
3+
local function register()
4+
vim.api.nvim_create_user_command("SwitchColorscheme", telescope_ui.colorscheme_picker, {})
5+
end
6+
7+
return {
8+
register = register,
9+
}

lua/switchscheme/init.lua

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
local M = {}
2+
3+
M.setup = function()
4+
require("switchscheme.commands").register()
5+
end
6+
7+
return M

lua/switchscheme/telescope_ui.lua

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
local actions = require("telescope.actions")
2+
local action_state = require("telescope.actions.state")
3+
local pickers = require("telescope.pickers")
4+
local finders = require("telescope.finders")
5+
local conf = require("telescope.config").values
6+
7+
local M = {}
8+
9+
function M.colorscheme_picker()
10+
local colors = vim.fn.getcompletion('', 'color')
11+
12+
pickers.new({}, {
13+
prompt_title = "Select Colorscheme",
14+
finder = finders.new_table({ results = colors }),
15+
sorter = conf.generic_sorter({}),
16+
attach_mappings = function(prompt_bufnr, map)
17+
local function apply_colorscheme()
18+
local selection = action_state.get_selected_entry()
19+
if selection then
20+
vim.cmd("colorscheme " .. selection[1])
21+
end
22+
end
23+
24+
map("i", "<CR>", function()
25+
apply_colorscheme()
26+
actions.close(prompt_bufnr)
27+
end)
28+
29+
map("i", "<Down>", function()
30+
actions.move_selection_next(prompt_bufnr)
31+
apply_colorscheme()
32+
end)
33+
34+
map("i", "<Up>", function()
35+
actions.move_selection_previous(prompt_bufnr)
36+
apply_colorscheme()
37+
end)
38+
39+
return true
40+
end,
41+
}):find()
42+
end
43+
44+
return M

plugin/switchscheme.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
require("switchscheme").setup()

0 commit comments

Comments
 (0)