···149149 return module
150150 end)
151151 :totable()
152152- lst = utils.flatten(lst, 1)
153153- return vim.iter(lst):fold("", function(str, module)
154154- if type(module) == "string" and #module > 0 then
155155- return str .. module
156156- end
157157- if type(module) ~= "table" or #module == 0 then
158158- return str
159159- end
160160- local text = module[1]
161161- if text == nil or type(text) ~= "string" or #text == 0 then
162162- return str
163163- end
164164- local hl = module[2]
165165- if hl and type(hl) == "string" and #hl > 0 then
166166- return str .. "%#" .. hl .. "#" .. text .. "%*"
167167- end
168168- return str .. "%*" .. text
169169- end)
152152+ return utils.fold(lst)
170153end
171154172155---@class lylla.proto
+39-3
lua/lylla/utils.lua
···1818---@param lst table
1919---@param maxdepth integer
2020function utils.flatten(lst, maxdepth)
2121+ vim.validate("lst", lst, "table")
2222+ vim.validate("maxdepth", maxdepth, "number")
2323+2124 ---@param _t any[]
2225 ---@return integer
2326 local function _depth(_t)
2424- return vim.iter(_t):fold(1, function(maxd, v)
2525- if type(v) == "table" then
2727+ return vim.iter(ipairs(_t)):fold(1, function(maxd, _, v)
2828+ if type(v) == "table" and vim.islist(v) then
2629 local d = 1 + _depth(v)
2730 if d > maxd then
2831 return d
···3841 local n = #_t
3942 for i = 1, n do
4043 local v = _t[i]
4141- if type(v) ~= "table" or _depth(v) <= maxdepth then
4444+ if type(v) ~= "table" or (not vim.islist(v)) or _depth(v) <= maxdepth then
4245 table.insert(result, v)
4346 else
4447 _flatten(v)
···4750 end
4851 _flatten(lst)
4952 return result
5353+end
5454+5555+function utils.fold(lst)
5656+ vim.validate("lst", lst, "table")
5757+5858+ lst = utils.flatten(lst, 1)
5959+ return vim.iter(ipairs(lst)):fold("", function(str, _, module)
6060+ if type(module) == "string" and #module > 0 then
6161+ return str .. module
6262+ end
6363+ if type(module) ~= "table" or #module == 0 then
6464+ return str
6565+ end
6666+ local text = module[1]
6767+ if text == nil or type(text) ~= "string" or #text == 0 then
6868+ return str
6969+ end
7070+ local hl = module[2]
7171+ if not hl then
7272+ return string.format("%s%%*%s", str, text)
7373+ end
7474+ if type(hl) == "string" and #hl > 0 then
7575+ return string.format("%s%%#%s#%s%%*", str, hl, text)
7676+ elseif type(hl) == "table" and (hl.fg or hl.bg or hl.link) then
7777+ local hl_name = string.format("@lylla.%s", vim.fn.sha256(vim.inspect(hl)))
7878+ vim.schedule(function()
7979+ vim.api.nvim_set_hl(0, hl_name, hl)
8080+ end)
8181+ return string.format("%s%%#%s#%s%%*", str, hl_name, text)
8282+ end
8383+8484+ return string.format("%s%%*%s", str, text)
8585+ end)
5086end
51875288function utils.getfilename()