馃 a tiny, customizable statusline for neovim
3
fork

Configure Feed

Select the types of activity you want to include in your feed.

at c26b3acb0fce67daac123e4f2db5a7e78d7f3224 102 lines 2.4 kB view raw
1local M = {} 2 3local lzrq = function(modname) 4 return setmetatable({ 5 modname = modname, 6 }, { 7 __index = function(t, k) 8 local m = rawget(t, "modname") 9 return m and require(m)[k] or nil 10 end, 11 }) 12end 13 14local config = lzrq("lylla.config") 15local utils = lzrq("lylla.utils") 16 17---@type table<'normal'|'visual'|'command'|'insert', vim.api.keyset.highlight> 18local default_hls = { 19 normal = { link = "@property" }, 20 visual = { link = "@constant" }, 21 command = { link = "@function" }, 22 insert = { link = "@variable" }, 23} 24 25---@param cfg? lylla.config 26function M.setup(cfg) 27 cfg = cfg or {} 28 config.set(config.override(cfg)) 29end 30 31function M.inithls() 32 vim.iter(pairs(default_hls)):each(function(mode, defaulthl) 33 local name = utils.get_modehl_name(mode) 34 35 local hl = config.get().hls[mode] 36 if hl then 37 vim.api.nvim_set_hl(0, name, hl) 38 return 39 end 40 41 if vim.tbl_isempty(vim.api.nvim_get_hl(0, { name = name })) then 42 vim.api.nvim_set_hl(0, name, defaulthl) 43 end 44 end) 45end 46 47function M.resethl() 48 vim.iter(pairs(default_hls)):each(function(mode, _) 49 local name = utils.get_modehl_name(mode) 50 vim.api.nvim_set_hl(0, name, {}) 51 end) 52end 53 54function M.init() 55 vim.api.nvim_create_autocmd({ "UIEnter", "WinNew", "WinEnter" }, { 56 group = vim.api.nvim_create_augroup("lylla:win", { clear = true }), 57 callback = function() 58 local win = vim.api.nvim_get_current_win() 59 if not require("lylla.statusline").wins[win] then 60 require("lylla.statusline"):new(win):init() 61 end 62 end, 63 }) 64 65 vim.api.nvim_create_autocmd("WinClosed", { 66 group = vim.api.nvim_create_augroup("lylla:close", { clear = true }), 67 callback = function(ev) 68 local stl = require("lylla.statusline").wins[ev.match] 69 if stl then 70 stl:close() 71 end 72 end, 73 }) 74 75 vim.api.nvim_create_autocmd("ColorSchemePre", { 76 group = vim.api.nvim_create_augroup("lylla:resethl", { clear = true }), 77 callback = function() 78 M.resethl() 79 end, 80 }) 81 vim.api.nvim_create_autocmd("ColorScheme", { 82 group = vim.api.nvim_create_augroup("lylla:inithls", { clear = true }), 83 callback = function() 84 M.inithls() 85 end, 86 }) 87 M.inithls() 88end 89 90-- helpers 91 92---@param fn fun(): string|any[] 93---@param opts? { events: string[] } 94---@return table 95function M.component(fn, opts) 96 local t = {} 97 t.fn = fn 98 t.opts = opts 99 return t 100end 101 102return M