robin/lylla.nvim
a tiny, customizable statusline for neovim
git clone https://git.robinwobin.dev/robin/lylla.nvim
c7b169c
main
1---@module 'lylla.config' 2 3---@class lylla.item 4---@field fn fun(): any 5---@field opts? { events?: string[] } 6 7---@alias lylla.item.tuple {[1]: string, [2]?: string} 8 9---@class lylla.config 10---@field refresh_rate integer|boolean 11---@field hls table<'normal'|'visual'|'command'|'insert'|'replace'|'operator', vim.api.keyset.highlight> 12---@field modules (lylla.item|lylla.item.tuple|string)[] 13---@field winbar any[] 14---@field tabline (fun(): (lylla.item|lylla.item.tuple|string)[])|vim.NIL 15 16local M , H ={} , {} 17 18---@type lylla.config 19---@eval return MiniDoc.afterlines_to_code(MiniDoc.current.eval_section) 20---@text # Default ~ 21M . default ={ 22refresh_rate =300 , 23hls ={} , 24modules ={ 25"meow" , 26"%<%f %h%w%m%r" , 27"%=" , 28{ 29fn =function () 30if vim . o . showcmdloc == "statusline" then 31return "%-10.S" 32end 33return "" 34end , 35} , 36{ " " } , 37{ 38fn =function () 39if not vim . b . keymap_name then 40return "" 41end 42return "<" .. vim . b . keymap_name .. ">" 43end , 44} , 45{ " " } , 46{ 47fn =function () 48if vim . bo . busy > 0 then 49return "◐ " 50end 51return "" 52end , 53} , 54{ " " } , 55{ 56fn =function () 57if not package . loaded [ "vim.diagnostic" ] then 58return "" 59end 60return vim . diagnostic . status () 61end , 62opts ={ 63events ={ "DiagnosticChanged" } , 64} , 65} , 66{ " " } , 67{ 68fn =function () 69if not vim . o . ruler then 70return "" 71end 72if vim . o . rulerformat == "" then 73return "%-14.(%l,%c%V%) %P" 74end 75return vim . o . rulerformat 76end , 77} , 78} , 79winbar ={} , 80tabline =vim . NIL , 81} 82 83---@type lylla.config 84---@diagnostic disable-next-line: missing-fields 85M . config ={} 86 87---@return lylla.config 88function M . get () 89return H . merge ( M . default , M . config ) 90end 91 92---@param cfg lylla.config 93---@return lylla.config 94function M . override ( cfg ) 95return H . merge ( M . default , cfg ) 96end 97 98---@param cfg lylla.config 99function M . set ( cfg ) 100M . config =cfg 101end 102 103-- helpers ==================================================================== 104 105---@param tdefault lylla.config 106---@param toverride lylla.config 107---@return lylla.config 108function H . merge ( tdefault , toverride ) 109return H . tmerge ( tdefault , toverride ) 110end 111 112---@private 113---@generic T: table|any[] 114---@param tdefault T 115---@param toverride T 116---@return T 117H . tmerge =function ( tdefault , toverride ) 118if toverride == nil then 119return tdefault 120end 121 122-- do not merge lists 123if H . islist ( tdefault ) then 124return toverride 125end 126if vim . tbl_isempty ( tdefault ) then 127return toverride 128end 129 130return vim . iter ( pairs ( tdefault )): fold ( {} , function ( tnew , k , v ) 131if toverride [ k ] == nil then 132tnew [ k ] =v 133return tnew 134end 135if type ( v ) ~= type ( toverride [ k ]) then 136tnew [ k ] =toverride [ k ] 137return tnew 138end 139if type ( v ) == "table" then 140tnew [ k ] =H . tmerge ( v , toverride [ k ]) 141return tnew 142end 143 144tnew [ k ] =toverride [ k ] 145return tnew 146end ) 147end 148 149---@param t table 150---@return boolean 151H . islist =function ( t ) 152if type ( t ) ~= "table" then 153return false 154end 155 156for k , _ in ipairs ( t ) do 157return type ( k ) == "number" 158end 159 160-- non-numeric keys 161for _ , _ in pairs ( t ) do 162return false 163end 164 165-- empty table 166return true 167end 168 169return M , H