61ac665774
- includes modified class implementation from https://github.com/rxi/classic/blob/master/classic.lua - now base component class is created from classic. - change to how component classes are created. - Don't overwrite new method to initialize a component. Overwrite the init method. new is responsible for creating class object and calling init on it. Unlike previous new overwrite you don't need to create the class (table) and return it. Instead you will recive the object as self and do required manipulation on that just like any most other oop langs. Also don't need to return anything from init. init's job is to initialize. remember to call classes init before running your operations unfortunately lua isn't full fledged oop lang and I don't how to automate this. - changes how super classes are accesed. - rename Component._parent -> Component.super - methods on super classes now ran through super class instead of objects _parent self._parent as that can lead to recursive inf loop. See branch, diff, tabs, buffer classes call to init for example on pattern. - All components updated to reflect current logic - component loader updated to use new initialization procedure. - updated tests - updated BREAKING_CHANGES.md - plus quite a bit of formatting changes in the components - comp.method = function(self, ...) -> function M:method(...) BREAKING_CHANGE
36 lines
1.0 KiB
Lua
36 lines
1.0 KiB
Lua
-- Copyright (c) 2020-2021 shadmansaleh
|
|
-- MIT license, see LICENSE for more details.
|
|
local M = require('lualine.component'):extend()
|
|
|
|
function M:update_status()
|
|
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
|
|
local scope = component:match '[gvtwb]?o?'
|
|
-- filters var portion from g:var
|
|
local var_name = component:sub(#scope + 2, #component)
|
|
-- Displays nothing when veriable aren't present
|
|
if not (scope and var_name) then
|
|
return ''
|
|
end
|
|
-- Support accessing keys within dictionary
|
|
-- https://github.com/shadmansaleh/lualine.nvim/issues/25#issuecomment-907374548
|
|
local name_chunks = vim.split(var_name, '%.')
|
|
local return_val = vim[scope][name_chunks[1]]
|
|
for i = 2, #name_chunks do
|
|
if return_val == nil then
|
|
break
|
|
end
|
|
return_val = return_val[name_chunks[i]]
|
|
end
|
|
if return_val == nil then
|
|
return ''
|
|
end
|
|
local ok
|
|
ok, return_val = pcall(tostring, return_val)
|
|
return ok and return_val or ''
|
|
end
|
|
|
|
return M
|