Skip to content

Commit

Permalink
fixup: showcmd not working with %s
Browse files Browse the repository at this point in the history
switch to using %z for internal separator representation
since %s is now used by neovim.

closes #949
  • Loading branch information
shadmansaleh committed Apr 9, 2023
1 parent c28a742 commit 84ffb80
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 18 deletions.
18 changes: 9 additions & 9 deletions lua/lualine.lua
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ local function fill_section_separator(status, is_focused, str_checked, last_hl,
end

--- processes statusline string
--- replaces %s/S{sep} with proper left/right separator highlight + sep
--- replaces %z/Z{sep} with proper left/right separator highlight + sep
---@param status string : unprocessed statusline string
---@return string : processed statusline string
local function apply_transitional_separators(status, is_focused)
Expand All @@ -93,7 +93,7 @@ local function apply_transitional_separators(status, is_focused)
local copied_pos = 1 -- Tracks how much we've copied over to status_applied
local str_checked = 1 -- Tracks where the searcher head is at

-- Process entire status replace the %s{sep} & %S{sep} placeholders
-- Process entire status replace the %z{sep} & %Z{sep} placeholders
-- with proper transitional separator.
while str_checked ~= nil do
str_checked = status:find('%%', str_checked)
Expand All @@ -108,9 +108,9 @@ local function apply_transitional_separators(status, is_focused)
-- %#hl_name# highlights
last_hl = status:match('^%%#(.-)#', str_checked)
str_checked = str_checked + #last_hl + 3
elseif next_char == 's' then
-- %s{sep} is marker for left separator and
local sep = status:match('^%%s{(.-)}', str_checked)
elseif next_char == 'z' then
-- %z{sep} is marker for left separator and
local sep = status:match('^%%z{(.-)}', str_checked)
str_checked = str_checked + #sep + 4 -- 4 = len(%{})
if not (last_hl == nil and last_hl_reseted) then
local trans_sep = fill_section_separator(status, is_focused, str_checked, last_hl, sep, false)
Expand All @@ -122,11 +122,11 @@ local function apply_transitional_separators(status, is_focused)
last_hl_reseted = false
end
copied_pos = str_checked
elseif next_char == 'S' then
-- %S{sep} is marker for right separator and
local sep = status:match('^%%S{(.-)}', str_checked)
elseif next_char == 'Z' then
-- %Z{sep} is marker for right separator and
local sep = status:match('^%%Z{(.-)}', str_checked)
str_checked = str_checked + #sep + 4 -- 4 = len(%{})
if status:find('^%%s', str_checked) or status:find('^%%<%%s', str_checked) then
if status:find('^%%z', str_checked) or status:find('^%%<%%Z', str_checked) then
-- When transitional right_sep and left_sep are right next to each other
-- and in this exact order skip the left sep as we can't draw both.
str_checked = status:find('}', str_checked) + 1
Expand Down
4 changes: 2 additions & 2 deletions lua/lualine/component.lua
Original file line number Diff line number Diff line change
Expand Up @@ -193,11 +193,11 @@ function M:apply_section_separators()
return
end
if self.options.separator.left ~= nil and self.options.separator.left ~= '' then
self.status = string.format('%%s{%s}%s', self.options.separator.left, self.status)
self.status = string.format('%%z{%s}%s', self.options.separator.left, self.status)
self.strip_previous_separator = true
end
if self.options.separator.right ~= nil and self.options.separator.right ~= '' then
self.status = string.format('%s%%S{%s}', self.status, self.options.separator.right)
self.status = string.format('%s%%Z{%s}', self.status, self.options.separator.right)
end
end

Expand Down
4 changes: 2 additions & 2 deletions lua/lualine/components/buffers/buffer.lua
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ end
---@return string
function Buffer:separator_before()
if self.current or self.aftercurrent then
return '%S{' .. self.options.section_separators.left .. '}'
return '%Z{' .. self.options.section_separators.left .. '}'
else
return self.options.component_separators.left
end
Expand All @@ -113,7 +113,7 @@ end
---@return string
function Buffer:separator_after()
if self.current or self.beforecurrent then
return '%s{' .. self.options.section_separators.right .. '}'
return '%z{' .. self.options.section_separators.right .. '}'
else
return self.options.component_separators.right
end
Expand Down
4 changes: 2 additions & 2 deletions lua/lualine/components/tabs/tab.lua
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ end
---@return string
function Tab:separator_before()
if self.current or self.aftercurrent then
return '%S{' .. self.options.section_separators.left .. '}'
return '%Z{' .. self.options.section_separators.left .. '}'
else
return self.options.component_separators.left
end
Expand All @@ -101,7 +101,7 @@ end
---@return string
function Tab:separator_after()
if self.current or self.beforecurrent then
return '%s{' .. self.options.section_separators.right .. '}'
return '%z{' .. self.options.section_separators.right .. '}'
else
return self.options.component_separators.right
end
Expand Down
6 changes: 3 additions & 3 deletions lua/lualine/utils/section.lua
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ function M.draw_section(section, section_name, is_focused)
and (section[1].options.section_separators.left ~= nil and section[1].options.section_separators.left ~= '')
then
status[component_no] =
string.format('%s%%S{%s}', status[component_no], section[1].options.section_separators.left)
string.format('%s%%Z{%s}', status[component_no], section[1].options.section_separators.left)
end
end
end
Expand Down Expand Up @@ -89,7 +89,7 @@ function M.draw_section(section, section_name, is_focused)
and (section[1].options.section_separators.right ~= nil and section[1].options.section_separators.right ~= '')
then
left_separator_string = string.format(
'%%s{%s}',
'%%z{%s}',
section[first_component_no].options.ls_separator or section[1].options.section_separators.right
)
end
Expand All @@ -104,7 +104,7 @@ function M.draw_section(section, section_name, is_focused)

local needs_hl

local find_start_trans_sep_start, find_start_trans_sep_end = status_str:find('^%%s{.-}')
local find_start_trans_sep_start, find_start_trans_sep_end = status_str:find('^%%z{.-}')
if find_start_trans_sep_start then
-- the section doesn't need to be prepended with default hl when sections
-- first component has transitional sep
Expand Down

0 comments on commit 84ffb80

Please sign in to comment.