fixup: showcmd not working with %s

switch to using %z for internal separator representation
since %s is now used by neovim.

closes #949
This commit is contained in:
shadmansaleh 2023-04-09 15:48:56 +06:00
parent c28a7427c3
commit 84ffb80e45
5 changed files with 18 additions and 18 deletions

View File

@ -82,7 +82,7 @@ local function fill_section_separator(status, is_focused, str_checked, last_hl,
end end
--- processes statusline string --- 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 ---@param status string : unprocessed statusline string
---@return string : processed statusline string ---@return string : processed statusline string
local function apply_transitional_separators(status, is_focused) local function apply_transitional_separators(status, is_focused)
@ -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 copied_pos = 1 -- Tracks how much we've copied over to status_applied
local str_checked = 1 -- Tracks where the searcher head is at 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. -- with proper transitional separator.
while str_checked ~= nil do while str_checked ~= nil do
str_checked = status:find('%%', str_checked) str_checked = status:find('%%', str_checked)
@ -108,9 +108,9 @@ local function apply_transitional_separators(status, is_focused)
-- %#hl_name# highlights -- %#hl_name# highlights
last_hl = status:match('^%%#(.-)#', str_checked) last_hl = status:match('^%%#(.-)#', str_checked)
str_checked = str_checked + #last_hl + 3 str_checked = str_checked + #last_hl + 3
elseif next_char == 's' then elseif next_char == 'z' then
-- %s{sep} is marker for left separator and -- %z{sep} is marker for left separator and
local sep = status:match('^%%s{(.-)}', str_checked) local sep = status:match('^%%z{(.-)}', str_checked)
str_checked = str_checked + #sep + 4 -- 4 = len(%{}) str_checked = str_checked + #sep + 4 -- 4 = len(%{})
if not (last_hl == nil and last_hl_reseted) then 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) local trans_sep = fill_section_separator(status, is_focused, str_checked, last_hl, sep, false)
@ -122,11 +122,11 @@ local function apply_transitional_separators(status, is_focused)
last_hl_reseted = false last_hl_reseted = false
end end
copied_pos = str_checked copied_pos = str_checked
elseif next_char == 'S' then elseif next_char == 'Z' then
-- %S{sep} is marker for right separator and -- %Z{sep} is marker for right separator and
local sep = status:match('^%%S{(.-)}', str_checked) local sep = status:match('^%%Z{(.-)}', str_checked)
str_checked = str_checked + #sep + 4 -- 4 = len(%{}) 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 -- 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. -- and in this exact order skip the left sep as we can't draw both.
str_checked = status:find('}', str_checked) + 1 str_checked = status:find('}', str_checked) + 1

View File

@ -193,11 +193,11 @@ function M:apply_section_separators()
return return
end end
if self.options.separator.left ~= nil and self.options.separator.left ~= '' then 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 self.strip_previous_separator = true
end end
if self.options.separator.right ~= nil and self.options.separator.right ~= '' then 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
end end

View File

@ -103,7 +103,7 @@ end
---@return string ---@return string
function Buffer:separator_before() function Buffer:separator_before()
if self.current or self.aftercurrent then if self.current or self.aftercurrent then
return '%S{' .. self.options.section_separators.left .. '}' return '%Z{' .. self.options.section_separators.left .. '}'
else else
return self.options.component_separators.left return self.options.component_separators.left
end end
@ -113,7 +113,7 @@ end
---@return string ---@return string
function Buffer:separator_after() function Buffer:separator_after()
if self.current or self.beforecurrent then if self.current or self.beforecurrent then
return '%s{' .. self.options.section_separators.right .. '}' return '%z{' .. self.options.section_separators.right .. '}'
else else
return self.options.component_separators.right return self.options.component_separators.right
end end

View File

@ -91,7 +91,7 @@ end
---@return string ---@return string
function Tab:separator_before() function Tab:separator_before()
if self.current or self.aftercurrent then if self.current or self.aftercurrent then
return '%S{' .. self.options.section_separators.left .. '}' return '%Z{' .. self.options.section_separators.left .. '}'
else else
return self.options.component_separators.left return self.options.component_separators.left
end end
@ -101,7 +101,7 @@ end
---@return string ---@return string
function Tab:separator_after() function Tab:separator_after()
if self.current or self.beforecurrent then if self.current or self.beforecurrent then
return '%s{' .. self.options.section_separators.right .. '}' return '%z{' .. self.options.section_separators.right .. '}'
else else
return self.options.component_separators.right return self.options.component_separators.right
end end

View File

@ -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 ~= '') and (section[1].options.section_separators.left ~= nil and section[1].options.section_separators.left ~= '')
then then
status[component_no] = 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 end
end end
@ -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 ~= '') and (section[1].options.section_separators.right ~= nil and section[1].options.section_separators.right ~= '')
then then
left_separator_string = string.format( left_separator_string = string.format(
'%%s{%s}', '%%z{%s}',
section[first_component_no].options.ls_separator or section[1].options.section_separators.right section[first_component_no].options.ls_separator or section[1].options.section_separators.right
) )
end end
@ -104,7 +104,7 @@ function M.draw_section(section, section_name, is_focused)
local needs_hl 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 if find_start_trans_sep_start then
-- the section doesn't need to be prepended with default hl when sections -- the section doesn't need to be prepended with default hl when sections
-- first component has transitional sep -- first component has transitional sep