From b01d39380ea3b43544f1407e7e8f19054b6e9d44 Mon Sep 17 00:00:00 2001 From: max397574 Date: Tue, 16 Nov 2021 17:51:15 +0100 Subject: =?UTF-8?q?feat(utils):=20=E2=9C=A8added=20function=20to=20load=20?= =?UTF-8?q?theme?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lua/startup/utils.lua | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/lua/startup/utils.lua b/lua/startup/utils.lua index ddeb347..db7c5e0 100644 --- a/lua/startup/utils.lua +++ b/lua/startup/utils.lua @@ -17,6 +17,39 @@ local function set_cursor(cursor) vim.api.nvim_win_set_cursor(0, cursor) end +---load the theme specified +---@param theme_name string theme to load +---@return table settings +function U.load_theme(theme_name) + local path = "lua/startup/themes/"..theme_name..".lua" + local files = vim.api.nvim_get_runtime_file(path, true) + local settings + if #files ==0 then + path = "lua/startup/themes"..theme_name.."/init.lua" + files = vim.api.nvim_get_runtime_file(path, true) + end + if #files ==0 then + error("lua/startup/themes/"..theme_name..".lua".." not found") + elseif #files == 1 then + settings = dofile(files[1]) + else + local startup_pattern = "startup.nvim/lua/startup" + local valid_file = false + for _, file in ipairs(files) do + if not file:find(startup_pattern) then + settings = dofile(file) + valid_file = true + end + end + if not valid_file then + -- multiple files but in startup repo shouldn't happen so just use first one + settings = dofile(files[1]) + end + end + return settings +end + +---checks if cursor should be able to move on current line local function bad_line() for _, line in ipairs(require("startup").good_lines) do if line == vim.trim(vim.api.nvim_get_current_line()) and line ~= "" then -- cgit v1.2.3