2021-04-11 08:20:41 +00:00
|
|
|
local EvalFuncComponent = require('lualine.component'):new()
|
|
|
|
|
|
|
|
EvalFuncComponent.update_status = function(self)
|
|
|
|
local component = self.options[1]
|
2021-04-12 06:14:43 +00:00
|
|
|
local ok, status = pcall(EvalFuncComponent.eval_lua, component)
|
2021-04-11 08:20:41 +00:00
|
|
|
if not ok then status = EvalFuncComponent.vim_function(component) end
|
|
|
|
return status
|
|
|
|
end
|
|
|
|
|
2021-04-12 06:14:43 +00:00
|
|
|
EvalFuncComponent.eval_lua = function(code)
|
2021-04-13 12:36:51 +00:00
|
|
|
return tostring(loadstring('return ' .. code)())
|
2021-04-11 08:20:41 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
EvalFuncComponent.vim_function = function(name)
|
|
|
|
-- vim function component
|
|
|
|
local ok, return_val = pcall(vim.fn[name])
|
|
|
|
if not ok then return '' end -- function call failed
|
|
|
|
ok, return_val = pcall(tostring, return_val)
|
|
|
|
if ok then
|
|
|
|
return return_val
|
|
|
|
else
|
|
|
|
return ''
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
return EvalFuncComponent
|