Updated theme func
This commit is contained in:
@@ -3,7 +3,7 @@ local configDir = vim.fn.stdpath("config")
|
||||
local prefsFile = configDir .. "/lua/taken/prefs.lua"
|
||||
|
||||
--- @return Themes
|
||||
local getAllThemes = function()
|
||||
local get_all_themes = function()
|
||||
vim.api.nvim_exec_autocmds("User", { pattern = "ThemeSwitcher", modeline = false })
|
||||
|
||||
local colors = vim.fn.globpath(vim.o.rtp, "colors/*", true, true)
|
||||
@@ -33,7 +33,7 @@ end
|
||||
--- change theme
|
||||
--- @param old string
|
||||
--- @param new string
|
||||
local change_theme = function(old, new)
|
||||
local write_to_file = function(old, new)
|
||||
-- function from nvchad
|
||||
local file = io.open(prefsFile, "r")
|
||||
|
||||
@@ -58,7 +58,7 @@ end
|
||||
|
||||
--- applytofile
|
||||
--- @param choice string
|
||||
local applytofile = function(choice)
|
||||
local change_theme = function(choice)
|
||||
if choice == nil then
|
||||
vim.notify("No theme selected!", 4)
|
||||
return
|
||||
@@ -66,7 +66,7 @@ local applytofile = function(choice)
|
||||
|
||||
vim.cmd("colorscheme " .. choice)
|
||||
local newstring = 'M.colorscheme = "' .. choice .. '"'
|
||||
change_theme(oldstring, newstring)
|
||||
write_to_file(oldstring, newstring)
|
||||
|
||||
local cursorcolumncolor = vim.fn.synIDattr(vim.fn.hlID("CursorColumn"), "bg")
|
||||
if cursorcolumncolor ~= "" then
|
||||
@@ -75,7 +75,6 @@ local applytofile = function(choice)
|
||||
end
|
||||
|
||||
return {
|
||||
getAllThemes = getAllThemes,
|
||||
get_all_themes = get_all_themes,
|
||||
change_theme = change_theme,
|
||||
applytofile = applytofile,
|
||||
}
|
||||
|
||||
@@ -7,14 +7,23 @@ function M.themeselector(opts)
|
||||
local conf = require("telescope.config").values
|
||||
local actions = require("telescope.actions")
|
||||
local action_state = require("telescope.actions.state")
|
||||
-- local action_set = require("telescope.actions.set")
|
||||
local action_set = require("telescope.actions.set")
|
||||
local ivytheme = require("telescope.themes").get_ivy()
|
||||
|
||||
local themes = themefuncs.getAllThemes()
|
||||
local applytofile = themefuncs.applytofile
|
||||
local themes = themefuncs.get_all_themes()
|
||||
local change_theme = themefuncs.change_theme
|
||||
|
||||
local current_theme = vim.g.colors_name
|
||||
|
||||
opts = opts or {}
|
||||
local combined = vim.tbl_extend("force", ivytheme, {
|
||||
layout_config = {
|
||||
height = 10,
|
||||
},
|
||||
}, opts)
|
||||
|
||||
pickers
|
||||
.new(opts, {
|
||||
.new(combined, {
|
||||
prompt_title = "Colorscheme",
|
||||
finder = finders.new_table({
|
||||
results = themes,
|
||||
@@ -24,26 +33,26 @@ function M.themeselector(opts)
|
||||
actions.select_default:replace(function()
|
||||
actions.close(prompt_bufnr)
|
||||
local selection = action_state.get_selected_entry()
|
||||
applytofile(selection.value)
|
||||
change_theme(selection.value)
|
||||
end)
|
||||
-- action_set.shift_selection:enhance({
|
||||
-- post = function()
|
||||
-- local selection = action_state.get_selected_entry()
|
||||
-- if selection == nil then
|
||||
-- vim.notify("Error while selecting theme", vim.log.levels.ERROR)
|
||||
-- end
|
||||
-- vim.cmd("colorscheme " .. selection.value)
|
||||
-- end,
|
||||
-- })
|
||||
-- actions.close:enhance({
|
||||
-- post = function()
|
||||
-- local selection = action_state.get_selected_entry()
|
||||
-- if selection == nil then
|
||||
-- vim.notify("Error while selecting theme", vim.log.levels.ERROR)
|
||||
-- end
|
||||
-- exec(selection.value)
|
||||
-- end,
|
||||
-- })
|
||||
action_set.shift_selection:enhance({
|
||||
post = function()
|
||||
local selection = action_state.get_selected_entry()
|
||||
if selection == nil then
|
||||
vim.notify("Error while selecting theme", vim.log.levels.ERROR)
|
||||
end
|
||||
vim.cmd("colorscheme " .. selection.value)
|
||||
end,
|
||||
})
|
||||
actions.close:enhance({
|
||||
post = function()
|
||||
local selection = action_state.get_selected_entry()
|
||||
if selection == nil then
|
||||
vim.notify("Error while selecting theme", vim.log.levels.ERROR)
|
||||
end
|
||||
vim.cmd("colorscheme " .. current_theme)
|
||||
end,
|
||||
})
|
||||
return true
|
||||
end,
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user