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