fixup: fix padding, fmt options in tabs and buffers
Previously these options were applied to entire tabs/buffers components. Now they are applied to specific buffer/tab. Note: Now icon, color options are no longer applicable to buffers & tabs component. I can't see how they make sense here. Also cond stil applies to entire component. fixes #414
This commit is contained in:
parent
7b608cb573
commit
93c934a641
|
@ -47,19 +47,23 @@ end
|
|||
---returns rendered buffer
|
||||
---@return string
|
||||
function Buffer:render()
|
||||
local name
|
||||
local name = self:name()
|
||||
if self.options.fmt then
|
||||
name = self.options.fmt(name or '')
|
||||
end
|
||||
|
||||
if self.ellipse then -- show elipsis
|
||||
name = '...'
|
||||
else
|
||||
if self.options.mode == 0 then
|
||||
name = string.format(' %s%s%s ', self.icon, self:name(), self.modified_icon)
|
||||
name = string.format('%s%s%s', self.icon, name, self.modified_icon)
|
||||
elseif self.options.mode == 1 then
|
||||
name = string.format(' %s %s%s ', self.bufnr, self.icon, self.modified_icon)
|
||||
name = string.format('%s %s%s', self.bufnr, self.icon, self.modified_icon)
|
||||
else
|
||||
name = string.format(' %s %s%s%s ', self.bufnr, self.icon, self:name(), self.modified_icon)
|
||||
name = string.format('%s %s%s%s', self.bufnr, self.icon, name, self.modified_icon)
|
||||
end
|
||||
end
|
||||
name = Buffer.apply_padding(name, self.options.padding)
|
||||
self.len = vim.fn.strchars(name)
|
||||
|
||||
-- setup for mouse clicks
|
||||
|
@ -119,4 +123,15 @@ function Buffer:name()
|
|||
or vim.fn.pathshorten(vim.fn.fnamemodify(self.file, ':p:.'))
|
||||
end
|
||||
|
||||
---adds spaces to left and right
|
||||
function Buffer.apply_padding(str, padding)
|
||||
local l_padding, r_padding = 1, 1
|
||||
if type(padding) == 'number' then
|
||||
l_padding, r_padding = padding, padding
|
||||
elseif type(padding) == 'table' then
|
||||
l_padding, r_padding = padding.left or 0, padding.right or 0
|
||||
end
|
||||
return string.rep(' ', l_padding) .. str .. string.rep(' ', r_padding)
|
||||
end
|
||||
|
||||
return Buffer
|
||||
|
|
|
@ -177,6 +177,22 @@ function M:update_status()
|
|||
return table.concat(data)
|
||||
end
|
||||
|
||||
function M:draw()
|
||||
self.status = ''
|
||||
self.applied_separator = ''
|
||||
|
||||
if self.options.cond ~= nil and self.options.cond() ~= true then
|
||||
return self.status
|
||||
end
|
||||
local status = self:update_status()
|
||||
if type(status) == 'string' and #status > 0 then
|
||||
self.status = status
|
||||
self:apply_section_separators()
|
||||
self:apply_separator()
|
||||
end
|
||||
return self.status
|
||||
end
|
||||
|
||||
vim.cmd [[
|
||||
function! LualineSwitchBuffer(bufnr, mouseclicks, mousebutton, modifiers)
|
||||
execute ":buffer " . a:bufnr
|
||||
|
|
|
@ -147,6 +147,22 @@ function M:update_status()
|
|||
return table.concat(data)
|
||||
end
|
||||
|
||||
function M:draw()
|
||||
self.status = ''
|
||||
self.applied_separator = ''
|
||||
|
||||
if self.options.cond ~= nil and self.options.cond() ~= true then
|
||||
return self.status
|
||||
end
|
||||
local status = self:update_status()
|
||||
if type(status) == 'string' and #status > 0 then
|
||||
self.status = status
|
||||
self:apply_section_separators()
|
||||
self:apply_separator()
|
||||
end
|
||||
return self.status
|
||||
end
|
||||
|
||||
vim.cmd [[
|
||||
function! LualineSwitchTab(tabnr, mouseclicks, mousebutton, modifiers)
|
||||
execute a:tabnr . "tabnext"
|
||||
|
|
|
@ -35,19 +35,23 @@ end
|
|||
---returns rendered tab
|
||||
---@return string
|
||||
function Tab:render()
|
||||
local name
|
||||
local name = self:label()
|
||||
if self.options.fmt then
|
||||
name = self.options.fmt(name or '')
|
||||
end
|
||||
if self.ellipse then -- show elipsis
|
||||
name = '...'
|
||||
else
|
||||
-- different formats for different modes
|
||||
if self.options.mode == 0 then
|
||||
name = string.format('%s%s ', (self.last or not self.first) and ' ' or '', tostring(self.tabnr))
|
||||
name = tostring(self.tabnr)
|
||||
elseif self.options.mode == 1 then
|
||||
name = string.format('%s%s ', (self.last or not self.first) and ' ' or '', self:label())
|
||||
name = name
|
||||
else
|
||||
name = string.format('%s%s %s ', (self.last or not self.first) and ' ' or '', tostring(self.tabnr), self:label())
|
||||
name = string.format('%s %s', tostring(self.tabnr), name)
|
||||
end
|
||||
end
|
||||
name = Tab.apply_padding(name, self.options.padding)
|
||||
self.len = vim.fn.strchars(name)
|
||||
|
||||
-- setup for mouse clicks
|
||||
|
@ -88,4 +92,15 @@ function Tab:separator_after()
|
|||
end
|
||||
end
|
||||
|
||||
---adds spaces to left and right
|
||||
function Tab.apply_padding(str, padding)
|
||||
local l_padding, r_padding = 1, 1
|
||||
if type(padding) == 'number' then
|
||||
l_padding, r_padding = padding, padding
|
||||
elseif type(padding) == 'table' then
|
||||
l_padding, r_padding = padding.left or 0, padding.right or 0
|
||||
end
|
||||
return string.rep(' ', l_padding) .. str .. string.rep(' ', r_padding)
|
||||
end
|
||||
|
||||
return Tab
|
||||
|
|
Loading…
Reference in New Issue