fix: lualine crashing because of keyboard interrupt. (#534)
* fix: lualine crashing because of keyboard interrupt. If keyboard interrupt occurs while lualine is evaluating statusline lualine crashes completely. Since keyboard interrupt isn't something we can handle try to mitigate the issue by retrying to evaluate the statusline on error.Now lualine will retry 3 times before giving up on an runtime error. * Make last retry unprotected call
This commit is contained in:
parent
9208bae98f
commit
e6e75f5e92
|
@ -141,7 +141,7 @@ end
|
|||
--- component objects
|
||||
---@param is_focused boolean : whether being evsluated for focused window or not
|
||||
---@return string statusline string
|
||||
local function statusline(sections, is_focused)
|
||||
local statusline = modules.utils.retry_call_wrap(function(sections, is_focused)
|
||||
-- The sequence sections should maintain [SECTION_SEQUENCE]
|
||||
local section_sequence = { 'a', 'b', 'c', 'x', 'y', 'z' }
|
||||
local status = {}
|
||||
|
@ -173,7 +173,7 @@ local function statusline(sections, is_focused)
|
|||
table.insert(status, modules.highlight.format_highlight('lualine_c') .. '%=')
|
||||
end
|
||||
return apply_transitional_separators(table.concat(status))
|
||||
end
|
||||
end)
|
||||
|
||||
--- check if any extension matches the filetype and return proper sections
|
||||
---@param current_ft string : filetype name of current file
|
||||
|
|
|
@ -143,4 +143,31 @@ function M.is_component(comp)
|
|||
return mt and mt.__is_lualine_component == true
|
||||
end
|
||||
|
||||
--- Call function with args and return it's result.
|
||||
--- If error occurs during fn retry times times.
|
||||
---@param fn function Function to call.
|
||||
---@param args table List of arguments used for calling function.
|
||||
---@param times number Number of times to retry on error.
|
||||
---@return any Result of fn.
|
||||
function M.retry_call(fn, args, times)
|
||||
times = times or 3
|
||||
for _=0,times-1 do
|
||||
local result = {pcall(fn, unpack(args))}
|
||||
if result[1] == true then
|
||||
return unpack(result, 2)
|
||||
end
|
||||
end
|
||||
return fn(unpack(args))
|
||||
end
|
||||
|
||||
--- Wrap a function in retry_call
|
||||
---@param fn function Function to call.
|
||||
---@param times number Number of times to retry on error.
|
||||
---@return function retry call wraped function
|
||||
function M.retry_call_wrap(fn, times)
|
||||
return function(...)
|
||||
return M.retry_call(fn, {...}, times)
|
||||
end
|
||||
end
|
||||
|
||||
return M
|
||||
|
|
Loading…
Reference in New Issue