馃 a tiny, customizable statusline for neovim
3
fork

Configure Feed

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

at 75f9916d54ede9c853586cfa9da99ab6ff597ffd 110 lines 2.5 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 54M.initialized = false 55 56function M.init() 57 if M.initialized then 58 return 59 end 60 61 M.initialized = true 62 63 vim.api.nvim_create_autocmd({ "UIEnter", "WinNew", "WinEnter" }, { 64 group = vim.api.nvim_create_augroup("lylla:win", { clear = true }), 65 callback = function() 66 local win = vim.api.nvim_get_current_win() 67 if not require("lylla.statusline").wins[win] then 68 require("lylla.statusline"):new(win):init() 69 end 70 end, 71 }) 72 73 vim.api.nvim_create_autocmd("WinClosed", { 74 group = vim.api.nvim_create_augroup("lylla:close", { clear = true }), 75 callback = function(ev) 76 local stl = require("lylla.statusline").wins[ev.match] 77 if stl then 78 stl:close() 79 end 80 end, 81 }) 82 83 vim.api.nvim_create_autocmd("ColorSchemePre", { 84 group = vim.api.nvim_create_augroup("lylla:resethl", { clear = true }), 85 callback = function() 86 M.resethl() 87 end, 88 }) 89 vim.api.nvim_create_autocmd("ColorScheme", { 90 group = vim.api.nvim_create_augroup("lylla:inithls", { clear = true }), 91 callback = function() 92 M.inithls() 93 end, 94 }) 95 M.inithls() 96end 97 98-- helpers 99 100---@param fn fun(): string|any[] 101---@param opts? { events: string[] } 102---@return table 103function M.component(fn, opts) 104 local t = {} 105 t.fn = fn 106 t.opts = opts 107 return t 108end 109 110return M