fix: left sections taking over entire stl when xyz is absent

- now %= applied even when x,y,z is absent
- newly added always_divide_middle option cal be set to false to avood %=
This commit is contained in:
shadmansaleh 2021-10-08 04:18:14 +06:00
parent 6faaa05ae5
commit 98b43ba3a1
4 changed files with 16 additions and 3 deletions

View File

@ -131,6 +131,7 @@ require'lualine'.setup {
component_separators = { left = '', right = ''}, component_separators = { left = '', right = ''},
section_separators = { left = '', right = ''}, section_separators = { left = '', right = ''},
disabled_filetypes = {} disabled_filetypes = {}
always_divide_middle = true,
}, },
sections = { sections = {
lualine_a = {'mode'}, lualine_a = {'mode'},
@ -349,6 +350,9 @@ options = {
component_separators = {left = '', right = ''}, component_separators = {left = '', right = ''},
section_separators = {left = '', right = ''}, section_separators = {left = '', right = ''},
disabled_filetypes = {}, -- filetypes to diable lualine on disabled_filetypes = {}, -- filetypes to diable lualine on
always_divide_middle = true, -- When true left_sections (a,b,c) can't
-- take over entiee statusline even
-- when none of section x, y, z is present.
} }
``` ```

View File

@ -106,6 +106,7 @@ Default config
component_separators = { left = '', right = ''}, component_separators = { left = '', right = ''},
section_separators = { left = '', right = ''}, section_separators = { left = '', right = ''},
disabled_filetypes = {} disabled_filetypes = {}
always_divide_middle = true,
}, },
sections = { sections = {
lualine_a = {'mode'}, lualine_a = {'mode'},
@ -332,6 +333,9 @@ in component.
component_separators = {left = '', right = ''}, component_separators = {left = '', right = ''},
section_separators = {left = '', right = ''}, section_separators = {left = '', right = ''},
disabled_filetypes = {}, -- filetypes to diable lualine on disabled_filetypes = {}, -- filetypes to diable lualine on
always_divide_middle = true, -- When true left_sections (a,b,c) can't
-- take over entiee statusline even
-- when none of section x, y, z is present.
} }
< <

View File

@ -126,7 +126,7 @@ local function statusline(sections, is_focused)
-- The sequence sections should maintain [SECTION_SEQUENCE] -- The sequence sections should maintain [SECTION_SEQUENCE]
local section_sequence = { 'a', 'b', 'c', 'x', 'y', 'z' } local section_sequence = { 'a', 'b', 'c', 'x', 'y', 'z' }
local status = {} local status = {}
local applied_midsection_devider = false local applied_midsection_divider = false
local applied_trunc = false local applied_trunc = false
for _, section_name in ipairs(section_sequence) do for _, section_name in ipairs(section_sequence) do
if sections['lualine_' .. section_name] then if sections['lualine_' .. section_name] then
@ -137,8 +137,8 @@ local function statusline(sections, is_focused)
is_focused is_focused
) )
if #section_data > 0 then if #section_data > 0 then
if not applied_midsection_devider and section_name > 'c' then if not applied_midsection_divider and section_name > 'c' then
applied_midsection_devider = true applied_midsection_divider = true
section_data = modules.highlight.format_highlight 'lualine_c' .. '%=' .. section_data section_data = modules.highlight.format_highlight 'lualine_c' .. '%=' .. section_data
end end
if not applied_trunc and section_name > 'b' then if not applied_trunc and section_name > 'b' then
@ -149,6 +149,10 @@ local function statusline(sections, is_focused)
end end
end end
end end
if applied_midsection_divider == false and config.options.always_divide_middle ~= false then
-- When non of section x,y,z is present
table.insert(status, modules.highlight.format_highlight 'lualine_c' .. '%=')
end
return apply_transitional_separators(table.concat(status)) return apply_transitional_separators(table.concat(status))
end end

View File

@ -7,6 +7,7 @@ local config = {
component_separators = { left = '', right = '' }, component_separators = { left = '', right = '' },
section_separators = { left = '', right = '' }, section_separators = { left = '', right = '' },
disabled_filetypes = {}, disabled_filetypes = {},
always_divide_middle = true,
}, },
sections = { sections = {
lualine_a = { 'mode' }, lualine_a = { 'mode' },