From ea0b6704ec46733189e46456625caaa7e35223a9 Mon Sep 17 00:00:00 2001 From: Taken Date: Fri, 2 May 2025 00:15:07 +0200 Subject: [PATCH] Updated theme func --- lua/taken/utils/themefuncs.lua | 11 ++++--- lua/taken/utils/themes.lua | 55 ++++++++++++++++++++-------------- 2 files changed, 37 insertions(+), 29 deletions(-) diff --git a/lua/taken/utils/themefuncs.lua b/lua/taken/utils/themefuncs.lua index 00ed381..4501834 100644 --- a/lua/taken/utils/themefuncs.lua +++ b/lua/taken/utils/themefuncs.lua @@ -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, } diff --git a/lua/taken/utils/themes.lua b/lua/taken/utils/themes.lua index 29196ef..5ae9a83 100644 --- a/lua/taken/utils/themes.lua +++ b/lua/taken/utils/themes.lua @@ -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, })