🪴 a tiny, customizable statusline for neovim
3
fork

Configure Feed

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

feat: add tabline support

robin 2161ad13 c8bed9e7

+121 -27
+52 -27
lua/lylla/config.lua
··· 11 11 ---@field hls table<'normal'|'visual'|'command'|'insert', vim.api.keyset.highlight> 12 12 ---@field modules (lylla.item|lylla.item.tuple|string)[] 13 13 ---@field winbar any[] 14 + ---@field tabline (fun(): (lylla.item|lylla.item.tuple|string)[])|vim.NIL 14 15 15 - local M = {} 16 + local M, H = {}, {} 16 17 17 18 ---@type lylla.config 18 19 ---@eval return MiniDoc.afterlines_to_code(MiniDoc.current.eval_section) ··· 75 76 }, 76 77 }, 77 78 winbar = {}, 79 + tabline = vim.NIL, 78 80 } 79 81 80 82 ---@type lylla.config 81 83 ---@diagnostic disable-next-line: missing-fields 82 84 M.config = {} 83 85 86 + ---@return lylla.config 87 + function M.get() 88 + return H.merge(M.default, M.config) 89 + end 90 + 91 + ---@param cfg lylla.config 92 + ---@return lylla.config 93 + function M.override(cfg) 94 + return H.merge(M.default, cfg) 95 + end 96 + 97 + ---@param cfg lylla.config 98 + function M.set(cfg) 99 + M.config = cfg 100 + end 101 + 102 + -- helpers ==================================================================== 103 + 104 + ---@param tdefault lylla.config 105 + ---@param toverride lylla.config 106 + ---@return lylla.config 107 + function H.merge(tdefault, toverride) 108 + return H.tmerge(tdefault, toverride) 109 + end 110 + 84 111 ---@private 85 112 ---@generic T: table|any[] 86 113 ---@param tdefault T 87 114 ---@param toverride T 88 115 ---@return T 89 - local function tmerge(tdefault, toverride) 116 + H.tmerge = function(tdefault, toverride) 90 117 if toverride == nil then 91 118 return tdefault 92 119 end 93 120 94 - if vim.islist(tdefault) then 121 + -- do not merge lists 122 + if H.islist(tdefault) then 95 123 return toverride 96 124 end 97 125 if vim.tbl_isempty(tdefault) then ··· 99 127 end 100 128 101 129 return vim.iter(pairs(tdefault)):fold({}, function(tnew, k, v) 102 - if toverride[k] == nil or type(v) ~= type(toverride[k]) then 130 + if toverride[k] == nil then 103 131 tnew[k] = v 132 + return tnew 133 + end 134 + if type(v) ~= type(toverride[k]) then 135 + tnew[k] = toverride[k] 104 136 return tnew 105 137 end 106 138 if type(v) == "table" then 107 - tnew[k] = tmerge(v, toverride[k]) 139 + tnew[k] = H.tmerge(v, toverride[k]) 108 140 return tnew 109 141 end 110 142 ··· 113 145 end) 114 146 end 115 147 116 - ---@param tdefault lylla.config 117 - ---@param toverride lylla.config 118 - ---@return lylla.config 119 - function M.merge(tdefault, toverride) 120 - if vim.fn.has("nvim-0.11.0") == 1 then 121 - toverride = 122 - vim.tbl_deep_extend("keep", toverride, { editor = { float = { solid_border = vim.o.winborder == "solid" } } }) 148 + ---@param t table 149 + ---@return boolean 150 + H.islist = function(t) 151 + if type(t) ~= "table" then 152 + return false 123 153 end 124 - return tmerge(tdefault, toverride) 125 - end 126 154 127 - ---@return lylla.config 128 - function M.get() 129 - return M.merge(M.default, M.config) 130 - end 155 + for k, _ in ipairs(t) do 156 + return type(k) == "number" 157 + end 131 158 132 - ---@param cfg lylla.config 133 - ---@return lylla.config 134 - function M.override(cfg) 135 - return M.merge(M.default, cfg) 136 - end 159 + -- non-numeric keys 160 + for _, _ in pairs(t) do 161 + return false 162 + end 137 163 138 - ---@param cfg lylla.config 139 - function M.set(cfg) 140 - M.config = cfg 164 + -- empty table 165 + return true 141 166 end 142 167 143 - return M 168 + return M, H
+4
lua/lylla/init.lua
··· 80 80 end, 81 81 }) 82 82 83 + if config.get().tabline ~= vim.NIL then 84 + require("lylla.tabline").setup() 85 + end 86 + 83 87 vim.api.nvim_create_autocmd("ColorSchemePre", { 84 88 group = vim.api.nvim_create_augroup("lylla:resethl", { clear = true }), 85 89 callback = function()
+65
lua/lylla/tabline.lua
··· 1 + vim.g.tablinefn = function() 2 + local tabfn = require("lylla.config").get().tabline 3 + if tabfn == vim.NIL or type(tabfn) ~= "function" then 4 + return 5 + end 6 + 7 + local utils = require("lylla.utils") 8 + 9 + return utils.fold(tabfn()) 10 + end 11 + 12 + local M, H = {}, {} 13 + 14 + M.setup = function() 15 + vim.o.tabline = "%!v:lua.vim.g.tablinefn()" 16 + end 17 + 18 + -- helpers ==================================================================== 19 + 20 + function H.fortabwins(tabn, f) 21 + local buflist = vim.fn.tabpagebuflist(tabn) 22 + 23 + return vim 24 + .iter(setmetatable({ 25 + idx = 0, 26 + }, { 27 + __call = function(t) 28 + local i = t.idx + 1 29 + if i > vim.fn.tabpagewinnr(tabn, "$") then 30 + return 31 + end 32 + t.idx = i 33 + return t.idx 34 + end, 35 + })) 36 + :fold({}, function(t, i) 37 + local buf = buflist[i] 38 + table.insert(t, { f(i, i == vim.fn.tabpagewinnr(tabn), buf) }) 39 + return t 40 + end) 41 + end 42 + 43 + function H.fortabs(f) 44 + return vim 45 + .iter(setmetatable({ 46 + idx = 0, 47 + }, { 48 + __call = function(t) 49 + local i = t.idx + 1 50 + if i > vim.fn.tabpagenr("$") then 51 + return 52 + end 53 + t.idx = i 54 + return t.idx 55 + end, 56 + })) 57 + :fold({}, function(t, i) 58 + table.insert(t, { f(i, i == vim.fn.tabpagenr()) }) 59 + return t 60 + end) 61 + end 62 + 63 + return vim.defaulttable(function(k) 64 + return M[k] or H[k] 65 + end)