2021-09-20 17:46:38 +06:00
|
|
|
-- Copyright (c) 2020-2021 shadmansaleh
|
|
|
|
-- MIT license, see LICENSE for more details.
|
2021-09-25 23:15:42 +06:00
|
|
|
local M = require('lualine.component'):extend()
|
|
|
|
|
|
|
|
function M:update_status()
|
2021-04-11 14:20:41 +06:00
|
|
|
local component = self.options[1]
|
|
|
|
-- vim veriable component
|
|
|
|
-- accepts g:, v:, t:, w:, b:, o, go:, vo:, to:, wo:, bo:
|
|
|
|
-- filters g portion from g:var
|
2022-01-02 17:38:39 +06:00
|
|
|
local scope = component:match('[gvtwb]?o?')
|
2021-04-11 14:20:41 +06:00
|
|
|
-- filters var portion from g:var
|
|
|
|
local var_name = component:sub(#scope + 2, #component)
|
|
|
|
-- Displays nothing when veriable aren't present
|
2021-09-04 00:28:20 +06:00
|
|
|
if not (scope and var_name) then
|
|
|
|
return ''
|
|
|
|
end
|
2021-08-28 00:32:44 +06:00
|
|
|
-- Support accessing keys within dictionary
|
2021-10-22 10:57:04 +06:00
|
|
|
-- https://github.com/nvim-lualine/lualine.nvim/issues/25#issuecomment-907374548
|
2021-08-28 00:32:44 +06:00
|
|
|
local name_chunks = vim.split(var_name, '%.')
|
|
|
|
local return_val = vim[scope][name_chunks[1]]
|
2021-09-04 00:28:20 +06:00
|
|
|
for i = 2, #name_chunks do
|
|
|
|
if return_val == nil then
|
|
|
|
break
|
|
|
|
end
|
2021-08-28 00:32:44 +06:00
|
|
|
return_val = return_val[name_chunks[i]]
|
|
|
|
end
|
2021-09-04 00:28:20 +06:00
|
|
|
if return_val == nil then
|
|
|
|
return ''
|
|
|
|
end
|
2021-04-11 14:20:41 +06:00
|
|
|
local ok
|
|
|
|
ok, return_val = pcall(tostring, return_val)
|
2021-08-20 18:32:56 +06:00
|
|
|
return ok and return_val or ''
|
2021-04-11 14:20:41 +06:00
|
|
|
end
|
|
|
|
|
2021-09-25 23:15:42 +06:00
|
|
|
return M
|