summaryrefslogtreecommitdiffstats
path: root/lua/core/theme.lua
diff options
context:
space:
mode:
authorSquibid <me@zacharyscheiman.com>2023-11-24 21:38:31 -0500
committerSquibid <me@zacharyscheiman.com>2023-11-24 21:38:31 -0500
commitf35b13d669867209427449840ff0930a732591dc (patch)
tree3acb658ec5d01f456c49a097d56f736cbfbbfc7d /lua/core/theme.lua
parentebf9d2d1c4682068f5116f7efc1568ce5adf4f1b (diff)
downloadnvim-f35b13d669867209427449840ff0930a732591dc.tar.gz
nvim-f35b13d669867209427449840ff0930a732591dc.tar.bz2
nvim-f35b13d669867209427449840ff0930a732591dc.zip
more stuff too lazy to seperate
Diffstat (limited to '')
-rw-r--r--lua/core/theme.lua76
1 files changed, 76 insertions, 0 deletions
diff --git a/lua/core/theme.lua b/lua/core/theme.lua
new file mode 100644
index 0000000..9d508f2
--- /dev/null
+++ b/lua/core/theme.lua
@@ -0,0 +1,76 @@
+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])
+ end
+ end)
+ return true
+ end,
+ }):find()
+end
+
+return M