···88 insert = { link = "MiniIconsGrey" },
99}
10101111+---@param cfg? lylla.config
1212+function M.setup(cfg)
1313+ cfg = cfg or {}
1414+ local config = require("lylla.config")
1515+ config.set(config.override(cfg))
1616+end
1717+1118function M.inithls()
1219 local utils = require("lylla.utils")
1320 vim.iter(pairs(default_hls)):each(function(mode, defaulthl)
+70
lua/lylla/log.lua
···11+---@module 'lylla.log'
22+33+local log = {}
44+55+log.stack = {}
66+77+local function getdebuginfo()
88+ local i = 3
99+ local info = debug.getinfo(i, "nSf")
1010+ local nextinfo = debug.getinfo(i + 1, "n")
1111+ while nextinfo and info.name == nil do
1212+ info = nextinfo
1313+ i = i + 1
1414+ nextinfo = debug.getinfo(i + 1, "n")
1515+ end
1616+ return info
1717+end
1818+1919+--- any message will not be displayed unless `'debug'` is set to `msg`.
2020+--- this is a purposeful design decisison made to avoid flooding the user with errors.
2121+--- this design decision also means that modules can silently fail.
2222+---@param msg string
2323+---@param level integer
2424+function log.notify(msg, level, debuginfo)
2525+ debuginfo = debuginfo or getdebuginfo()
2626+ local info = string.format(
2727+ "%s %s at %s",
2828+ #debuginfo.namewhat > 0 and debuginfo.namewhat or "chunk",
2929+ debuginfo.name or "main",
3030+ debuginfo.short_src or "main loop"
3131+ )
3232+ log.stack[#log.stack + 1] = { level, info, msg }
3333+ msg = string.format("in %s:\n\t%s", info, msg)
3434+ if vim.o.debug == "" then
3535+ return
3636+ end
3737+ if vim.o.debug == "throw" and level >= vim.log.levels.ERROR then
3838+ error(msg, level)
3939+ return
4040+ end
4141+ vim.notify_once(msg, level)
4242+ return level
4343+end
4444+4545+---@param msg string
4646+function log.trace(msg)
4747+ return log.notify(msg, vim.log.levels.TRACE, getdebuginfo())
4848+end
4949+5050+---@param msg string
5151+function log.debug(msg)
5252+ return log.notify(msg, vim.log.levels.DEBUG, getdebuginfo())
5353+end
5454+5555+---@param msg string
5656+function log.info(msg)
5757+ return log.notify(msg, vim.log.levels.INFO, getdebuginfo())
5858+end
5959+6060+---@param msg string
6161+function log.warn(msg)
6262+ return log.notify(msg, vim.log.levels.WARN, getdebuginfo())
6363+end
6464+6565+---@param msg string
6666+function log.error(msg)
6767+ return log.notify(msg, vim.log.levels.ERROR, getdebuginfo())
6868+end
6969+7070+return log
+40-13
lua/lylla/statusline.lua
···11+local log = require("lylla.log")
12local utils = require("lylla.utils")
2334---@class lylla.proto
···5960 statusline.wins[self.win] = nil
6061end
61626363+local function refreshcomponent(self, fn, ev)
6464+ do
6565+ local ok, result = pcall(fn, self, ev)
6666+ if not ok then
6767+ log.error("[lylla] error occured on refresh:\n\t" .. result)
6868+ end
6969+ end
7070+end
7171+6272---@class lylla.proto
6373---@field refresh fun(self, ev?: vim.api.keyset.create_autocmd.callback_args)
6474function statusline:refresh(ev)
···6777 return
6878 end
69797070- self:set(ev)
7171- self:setwinbar(ev)
8080+ refreshcomponent(self, statusline.set, ev)
8181+ refreshcomponent(self, statusline.setwinbar, ev)
7282 end)
7383end
74847585---@class lylla.proto
7686---@field fold fun(self, ev?: vim.api.keyset.create_autocmd.callback_args, modules: any[]): string
7787function statusline:fold(ev, modules)
8888+ if type(modules) ~= "table" or modules == nil then
8989+ return ""
9090+ end
9191+7892 local lst = vim
7993 .iter(ipairs(modules))
8094 :map(function(_, module)
8181- if type(module) == "table" and module._type == "component" then
9595+ if type(module) == "table" and module.fn and type(module.fn) == "function" then
8296 if module.opts and module.opts.events then
8397 -- refresh from timer
8498 if not ev and module.prev then
···89103 return module.prev
90104 end
91105 end
9292- module.prev = module.fn()
106106+ do
107107+ local ok, result = pcall(module.fn)
108108+ if not ok then
109109+ error(result)
110110+ end
111111+ module.prev = result
112112+ end
93113 return module.prev
94114 end
95115 if type(module) == "function" then
9696- module = module()
116116+ local ok, result = pcall(module)
117117+ if not ok then
118118+ error(result)
119119+ end
120120+ return result
97121 end
98122 return module
99123 end)
100124 :totable()
101125 lst = utils.flatten(lst, 1)
102126 return vim.iter(lst):fold("", function(str, module)
127127+ if type(module) == "string" and #module > 0 then
128128+ return str .. module
129129+ end
103130 if type(module) ~= "table" or #module == 0 then
104131 return str
105132 end
106133 local text = module[1]
107107- if #module > 1 then
108108- return str .. "%#" .. module[2] .. "#" .. text .. "%*"
134134+ if text == nil or type(text) ~= "string" or #text == 0 then
135135+ return str
136136+ end
137137+ local hl = module[2]
138138+ if hl and type(hl) == "string" and #hl > 0 then
139139+ return str .. "%#" .. hl .. "#" .. text .. "%*"
109140 end
110141 return str .. "%*" .. text
111142 end)
···134165 local ok, result = pcall(vim.api.nvim_win_call, self.win, function()
135166 return self:getwinbar(ev)
136167 end)
137137- if not ok then
138138- return
139139- end
168168+ assert(ok, string.format("error occured while trying to evaluate winbar:\n\t%s", result))
140169141170 vim.wo[self.win].winbar = result
142171end
···147176 local ok, result = pcall(vim.api.nvim_win_call, self.win, function()
148177 return self:get(ev)
149178 end)
150150- if not ok then
151151- return
152152- end
179179+ assert(ok, string.format("error occured while trying to evaluate statusline:\n\t%s", result))
153180154181 vim.wo[self.win].statusline = result
155182end