diff --git a/lua/alpha/themes/dashboard.lua b/lua/alpha/themes/dashboard.lua index c4f3407..fbd9dfd 100644 --- a/lua/alpha/themes/dashboard.lua +++ b/lua/alpha/themes/dashboard.lua @@ -37,14 +37,16 @@ local footer = { }, } -local leader = "SPC" +local M = {} + +M.leader = "SPC" --- @param sc string --- @param txt string --- @param keybind string? optional --- @param keybind_opts table? optional -local function button(sc, txt, keybind, keybind_opts) - local sc_ = sc:gsub("%s", ""):gsub(leader, "") +function M.button(sc, txt, keybind, keybind_opts) + local sc_ = sc:gsub("%s", ""):gsub(M.leader, "") local opts = { position = "center", @@ -75,45 +77,40 @@ end local buttons = { type = "group", val = { - button("e", " New file", "ene "), - button("SPC f f", "󰈞 Find file"), - button("SPC f h", "󰊄 Recently opened files"), - button("SPC f r", " Frecency/MRU"), - button("SPC f g", "󰈬 Find word"), - button("SPC f m", " Jump to bookmarks"), - button("SPC s l", " Open last session"), + M.button("e", " New file", "ene "), + M.button("SPC f f", "󰈞 Find file"), + M.button("SPC f h", "󰊄 Recently opened files"), + M.button("SPC f r", " Frecency/MRU"), + M.button("SPC f g", "󰈬 Find word"), + M.button("SPC f m", " Jump to bookmarks"), + M.button("SPC s l", " Open last session"), }, opts = { spacing = 1, }, } -local section = { +M.section = { terminal = default_terminal, header = default_header, buttons = buttons, footer = footer, } -local config = { +M.config = { layout = { { type = "padding", val = 2 }, - section.header, + M.section.header, { type = "padding", val = 2 }, - section.buttons, - section.footer, + M.section.buttons, + M.section.footer, }, opts = { margin = 5, }, } -return { - button = button, - section = section, - config = config, - -- theme config - leader = leader, - -- deprecated - opts = config, -} +--deprecated +M.opts = M.config + +return M diff --git a/lua/alpha/themes/startify.lua b/lua/alpha/themes/startify.lua index 5748414..96a24d7 100644 --- a/lua/alpha/themes/startify.lua +++ b/lua/alpha/themes/startify.lua @@ -19,14 +19,16 @@ local default_header = { }, } -local leader = "SPC" +local M = {} + +M.leader = "SPC" --- @param sc string --- @param txt string --- @param keybind string? optional --- @param keybind_opts table? optional -local function button(sc, txt, keybind, keybind_opts) - local sc_ = sc:gsub("%s", ""):gsub(leader, "") +function M.button(sc, txt, keybind, keybind_opts) + local sc_ = sc:gsub("%s", ""):gsub(M.leader, "") local opts = { position = "left", @@ -55,7 +57,7 @@ local function button(sc, txt, keybind, keybind_opts) } end -local nvim_web_devicons = { +M.nvim_web_devicons = { enabled = true, highlight = true, } @@ -69,18 +71,19 @@ local function get_extension(fn) return ext end -local function icon(fn) +function M.icon(fn) local nwd = require("nvim-web-devicons") local ext = get_extension(fn) return nwd.get_icon(fn, ext, { default = true }) end -local function file_button(fn, sc, short_fn, autocd) +function M.file_button(fn, sc, short_fn, autocd) short_fn = if_nil(short_fn, fn) local ico_txt local fb_hl = {} + local nvim_web_devicons = M.nvim_web_devicons if nvim_web_devicons.enabled then - local ico, hl = icon(fn) + local ico, hl = M.icon(fn) local hl_option_type = type(nvim_web_devicons.highlight) if hl_option_type == "boolean" then if hl and nvim_web_devicons.highlight then @@ -95,7 +98,7 @@ local function file_button(fn, sc, short_fn, autocd) ico_txt = "" end local cd_cmd = (autocd and " | cd %:p:h" or "") - local file_button_el = button(sc, ico_txt .. short_fn, "e " .. vim.fn.fnameescape(fn) .. cd_cmd .." ") + local file_button_el = M.button(sc, ico_txt .. short_fn, "e " .. vim.fn.fnameescape(fn) .. cd_cmd .. " ") local fn_start = short_fn:match(".*[/\\]") if fn_start ~= nil then table.insert(fb_hl, { "Comment", #ico_txt, #fn_start + #ico_txt }) @@ -106,18 +109,18 @@ end local default_mru_ignore = { "gitcommit" } -local mru_opts = { +M.mru_opts = { ignore = function(path, ext) return (string.find(path, "COMMIT_EDITMSG")) or (vim.tbl_contains(default_mru_ignore, ext)) end, - autocd = false + autocd = false, } --- @param start number --- @param cwd string? optional --- @param items_number number? optional number of items to generate, default = 10 -local function mru(start, cwd, items_number, opts) - opts = opts or mru_opts +function M.mru(start, cwd, items_number, opts) + opts = opts or M.mru_opts items_number = if_nil(items_number, 10) local oldfiles = {} for _, v in pairs(vim.v.oldfiles) do @@ -144,7 +147,7 @@ local function mru(start, cwd, items_number, opts) else short_fn = fnamemodify(fn, ":~") end - local file_button_el = file_button(fn, tostring(i + start - 1), short_fn,opts.autocd) + local file_button_el = M.file_button(fn, tostring(i + start - 1), short_fn, opts.autocd) tbl[i] = file_button_el end return { @@ -158,12 +161,12 @@ local function mru_title() return "MRU " .. vim.fn.getcwd() end -local section = { +M.section = { header = default_header, top_buttons = { type = "group", val = { - button("e", "New file", "ene "), + M.button("e", "New file", "ene "), }, }, -- note about MRU: currently this is a function, @@ -182,7 +185,7 @@ local section = { { type = "group", val = function() - return { mru(10) } + return { M.mru(10) } end, }, }, @@ -196,7 +199,7 @@ local section = { { type = "group", val = function() - return { mru(0, vim.fn.getcwd()) } + return { M.mru(0, vim.fn.getcwd()) } end, opts = { shrink_margin = false }, }, @@ -205,7 +208,7 @@ local section = { bottom_buttons = { type = "group", val = { - button("q", "Quit", "q "), + M.button("q", "Quit", "q "), }, }, footer = { @@ -214,45 +217,32 @@ local section = { }, } -local config = { +M.config = { layout = { { type = "padding", val = 1 }, - section.header, + M.section.header, { type = "padding", val = 2 }, - section.top_buttons, - section.mru_cwd, - section.mru, + M.section.top_buttons, + M.section.mru_cwd, + M.section.mru, { type = "padding", val = 1 }, - section.bottom_buttons, - section.footer, + M.section.bottom_buttons, + M.section.footer, }, opts = { margin = 3, redraw_on_resize = false, setup = function() - vim.api.nvim_create_autocmd('DirChanged', { - pattern = '*', + vim.api.nvim_create_autocmd("DirChanged", { + pattern = "*", group = "alpha_temp", - callback = function () - require('alpha').redraw() - vim.cmd('AlphaRemap') + callback = function() + require("alpha").redraw() + vim.cmd("AlphaRemap") end, }) end, }, } -return { - icon = icon, - button = button, - file_button = file_button, - mru = mru, - mru_opts = mru_opts, - section = section, - config = config, - -- theme config - nvim_web_devicons = nvim_web_devicons, - leader = leader, - -- deprecated - opts = config, -} +return M diff --git a/lua/alpha/themes/theta.lua b/lua/alpha/themes/theta.lua index 41ef0d0..7ae50de 100644 --- a/lua/alpha/themes/theta.lua +++ b/lua/alpha/themes/theta.lua @@ -9,7 +9,11 @@ local dashboard = require("alpha.themes.dashboard") local cdir = vim.fn.getcwd() local if_nil = vim.F.if_nil -local nvim_web_devicons = { +local M = {} + +M.leader = dashboard.leader + +M.nvim_web_devicons = { enabled = true, highlight = true, } @@ -29,10 +33,11 @@ local function icon(fn) return nwd.get_icon(fn, ext, { default = true }) end -local function file_button(fn, sc, short_fn,autocd) +local function file_button(fn, sc, short_fn, autocd) short_fn = short_fn or fn local ico_txt local fb_hl = {} + local nvim_web_devicons = M.nvim_web_devicons if nvim_web_devicons.enabled then local ico, hl = icon(fn) @@ -50,7 +55,8 @@ local function file_button(fn, sc, short_fn,autocd) ico_txt = "" end local cd_cmd = (autocd and " | cd %:p:h" or "") - local file_button_el = dashboard.button(sc, ico_txt .. short_fn, "e " .. vim.fn.fnameescape(fn) .. cd_cmd .." ") + local file_button_el = + dashboard.button(sc, ico_txt .. short_fn, "e " .. vim.fn.fnameescape(fn) .. cd_cmd .. " ") local fn_start = short_fn:match(".*[/\\]") if fn_start ~= nil then table.insert(fb_hl, { "Comment", #ico_txt - 2, #fn_start + #ico_txt }) @@ -61,18 +67,18 @@ end local default_mru_ignore = { "gitcommit" } -local mru_opts = { +M.mru_opts = { ignore = function(path, ext) return (string.find(path, "COMMIT_EDITMSG")) or (vim.tbl_contains(default_mru_ignore, ext)) end, - autocd = false + autocd = false, } --- @param start number --- @param cwd string? optional --- @param items_number number? optional number of items to generate, default = 10 -local function mru(start, cwd, items_number, opts) - opts = opts or mru_opts +function M.mru(start, cwd, items_number, opts) + opts = opts or M.mru_opts items_number = if_nil(items_number, 10) local oldfiles = {} @@ -111,7 +117,7 @@ local function mru(start, cwd, items_number, opts) local shortcut = tostring(i + start - 1) - local file_button_el = file_button(fn, shortcut, short_fn,opts.autocd) + local file_button_el = file_button(fn, shortcut, short_fn, opts.autocd) tbl[i] = file_button_el end return { @@ -121,7 +127,7 @@ local function mru(start, cwd, items_number, opts) } end -local header = { +M.header = { type = "text", val = { [[ __]], @@ -154,14 +160,14 @@ local section_mru = { { type = "group", val = function() - return { mru(0, cdir) } + return { M.mru(0, cdir) } end, opts = { shrink_margin = false }, }, }, } -local buttons = { +M.buttons = { type = "group", val = { { type = "text", val = "Quick links", opts = { hl = "SpecialComment", position = "center" } }, @@ -176,37 +182,28 @@ local buttons = { position = "center", } -local config = { +M.config = { layout = { { type = "padding", val = 2 }, - header, + M.header, { type = "padding", val = 2 }, section_mru, { type = "padding", val = 2 }, - buttons, + M.buttons, }, opts = { margin = 5, setup = function() - vim.api.nvim_create_autocmd('DirChanged', { - pattern = '*', + vim.api.nvim_create_autocmd("DirChanged", { + pattern = "*", group = "alpha_temp", - callback = function () - require('alpha').redraw() - vim.cmd('AlphaRemap') + callback = function() + require("alpha").redraw() + vim.cmd("AlphaRemap") end, }) end, }, } -return { - header = header, - buttons = buttons, - mru = mru, - config = config, - -- theme specific config - mru_opts = mru_opts, - leader = dashboard.leader, - nvim_web_devicons = nvim_web_devicons, -} +return M