robin/lylla.nvim
a tiny, customizable statusline for neovim
git clone https://git.robinwobin.dev/robin/lylla.nvim
56cb261
main
1if vim . g . loaded_lylla then 2return 3end 4 5vim . g . loaded_lylla =true 6 7local lzrq =function ( modname ) 8return vim . defaulttable ( function ( k ) 9return require ( modname )[ k ] 10end ) 11end 12 13local config =lzrq ( "lylla.config" ) 14local utils =lzrq ( "lylla.utils" ) 15 16-- highlights ================================================================= 17 18---@type table<'normal'|'visual'|'command'|'insert'|'replace'|'operator', vim.api.keyset.highlight> 19local default_hls ={ 20normal ={ link ="@property" } , 21visual ={ link ="@constant" } , 22command ={ link ="@function" } , 23insert ={ link ="@variable" } , 24replace ={ link ="@type" } , 25operator ={ link ="NonText" } , 26} 27 28local function set_hl ( name , hl ) 29hl . default =true 30vim . api . nvim_set_hl ( 0 , name , hl ) 31end 32 33local function inithls () 34vim . iter ( pairs ( default_hls )): each ( function ( mode , defaulthl ) 35local hl =config . get (). hls [ mode ] 36local name , revname =utils . get_modehl_name ( mode ) 37if hl then 38set_hl ( name , hl ) 39elseif vim . tbl_isempty ( vim . api . nvim_get_hl ( 0 , { name =name } )) then 40set_hl ( name , defaulthl ) 41end 42set_hl ( revname , utils . reverse_hl ( name )) 43end ) 44end 45 46-- init ======================================================================= 47 48local group =vim . api . nvim_create_augroup ( "@lylla" , { clear =true } ) 49 50vim . api . nvim_create_autocmd ( { "WinNew" , "WinEnter" } , { 51group =group , 52callback =function () 53require ( "lylla.statusline" ). try_new () 54end , 55} ) 56 57vim . api . nvim_create_autocmd ( "WinClosed" , { 58group =group , 59callback =function ( ev ) 60---@cast ev +{match: integer} 61local stl =require ( "lylla.statusline" ). wins [ ev . match ] 62if stl then 63stl : close () 64end 65end , 66} ) 67 68vim . api . nvim_create_autocmd ( { "UIEnter" , "ColorScheme" } , { 69group =group , 70callback =function () 71inithls () 72 73require ( "lylla" ). refresh ( true ) 74end , 75} ) 76 77local function init () 78require ( "lylla" ). init () 79 80local wins =vim . api . nvim_list_wins () 81for _ , win in ipairs ( wins ) do 82if vim . api . nvim_win_is_valid ( win ) then 83require ( "lylla.statusline" ). try_new ( win ) 84end 85end 86 87if config . get (). tabline ~= vim . NIL then 88---@diagnostic disable-next-line: undefined-field 89require ( "lylla.tabline" ). init () 90end 91end 92 93if vim . v . vim_did_enter > 0 then 94init () 95else 96vim . api . nvim_create_autocmd ( "VimEnter" , { 97group =vim . api . nvim_create_augroup ( "@lylla.init" , { clear =true } ), 98callback =function () 99init () 100end , 101} ) 102end