fix: % not properly escaped in other components too.
Now following components escapes results of external souces - buffers - tabs - hostname - branch - filetype fixes #579
This commit is contained in:
parent
a69251d52b
commit
40849728b6
|
@ -1,8 +1,11 @@
|
|||
-- Copyright (c) 2020-2021 shadmansaleh
|
||||
-- MIT license, see LICENSE for more details.
|
||||
local M = require('lualine.component'):extend()
|
||||
local require = require('lualine_require').require
|
||||
local git_branch = require('lualine.components.branch.git_branch')
|
||||
local modules = require('lualine_require').lazy_require {
|
||||
git_branch = 'lualine.components.branch.git_branch',
|
||||
highlight = 'lualine.highlight',
|
||||
utils = 'lualine.utils.utils',
|
||||
}
|
||||
|
||||
-- Initilizer
|
||||
M.init = function(self, options)
|
||||
|
@ -10,11 +13,13 @@ M.init = function(self, options)
|
|||
if not self.options.icon then
|
||||
self.options.icon = '' -- e0a0
|
||||
end
|
||||
git_branch.init()
|
||||
modules.git_branch.init()
|
||||
end
|
||||
|
||||
M.update_status = function(_, is_focused)
|
||||
return git_branch.get_branch((not is_focused and vim.api.nvim_get_current_buf()))
|
||||
local buf = (not is_focused and vim.api.nvim_get_current_buf())
|
||||
local branch = modules.git_branch.get_branch(buf)
|
||||
return modules.utils.stl_escape(branch)
|
||||
end
|
||||
|
||||
return M
|
||||
|
|
|
@ -1,6 +1,10 @@
|
|||
local highlight = require('lualine.highlight')
|
||||
local Buffer = require('lualine.utils.class'):extend()
|
||||
|
||||
local modules = require('lualine_require').lazy_require {
|
||||
highlight = 'lualine.highlight',
|
||||
utils = 'lualine.utils.utils',
|
||||
}
|
||||
|
||||
---intialize a new buffer from opts
|
||||
---@param opts table
|
||||
function Buffer:init(opts)
|
||||
|
@ -13,7 +17,7 @@ end
|
|||
|
||||
---setup icons, modified status for buffer
|
||||
function Buffer:get_props()
|
||||
self.file = vim.api.nvim_buf_get_name(self.bufnr)
|
||||
self.file = modules.utils.stl_escape(vim.api.nvim_buf_get_name(self.bufnr))
|
||||
self.buftype = vim.api.nvim_buf_get_option(self.bufnr, 'buftype')
|
||||
self.filetype = vim.api.nvim_buf_get_option(self.bufnr, 'filetype')
|
||||
local modified = self.options.show_modified_status and vim.api.nvim_buf_get_option(self.bufnr, 'modified')
|
||||
|
@ -69,7 +73,8 @@ function Buffer:render()
|
|||
-- setup for mouse clicks
|
||||
local line = string.format('%%%s@LualineSwitchBuffer@%s%%T', self.bufnr, name)
|
||||
-- apply highlight
|
||||
line = highlight.component_format_highlight(self.highlights[(self.current and 'active' or 'inactive')]) .. line
|
||||
line = modules.highlight.component_format_highlight(self.highlights[(self.current and 'active' or 'inactive')])
|
||||
.. line
|
||||
|
||||
-- apply separators
|
||||
if self.options.self.section < 'lualine_x' and not self.first then
|
||||
|
|
|
@ -18,7 +18,8 @@ function M:init(options)
|
|||
end
|
||||
|
||||
function M.update_status()
|
||||
return vim.bo.filetype or ''
|
||||
local ft = vim.bo.filetype or ''
|
||||
return modules.utils.stl_escape(ft)
|
||||
end
|
||||
|
||||
function M:apply_icon()
|
||||
|
|
|
@ -1,7 +1,11 @@
|
|||
-- Copyright (c) 2020-2021 hoob3rt
|
||||
-- MIT license, see LICENSE for more details.
|
||||
local modules = require('lualine_require').lazy_require {
|
||||
utils = 'lualine.utils.utils',
|
||||
}
|
||||
|
||||
local function hostname()
|
||||
return vim.loop.os_gethostname()
|
||||
return modules.utils.stl_escape(vim.loop.os_gethostname())
|
||||
end
|
||||
|
||||
return hostname
|
||||
|
|
|
@ -1,6 +1,10 @@
|
|||
local highlight = require('lualine.highlight')
|
||||
local Tab = require('lualine.utils.class'):extend()
|
||||
|
||||
local modules = require('lualine_require').lazy_require {
|
||||
highlight = 'lualine.highlight',
|
||||
utils = 'lualine.utils.utils',
|
||||
}
|
||||
|
||||
---intialize a new tab from opts
|
||||
---@param opts table
|
||||
function Tab:init(opts)
|
||||
|
@ -17,12 +21,12 @@ end
|
|||
function Tab:label()
|
||||
local custom_tabname = vim.t[self.tabId].tabname
|
||||
if custom_tabname and custom_tabname ~= '' then
|
||||
return custom_tabname
|
||||
return modules.utils.stl_escape(custom_tabname)
|
||||
end
|
||||
local buflist = vim.fn.tabpagebuflist(self.tabnr)
|
||||
local winnr = vim.fn.tabpagewinnr(self.tabnr)
|
||||
local bufnr = buflist[winnr]
|
||||
local file = vim.api.nvim_buf_get_name(bufnr)
|
||||
local file = modules.utils.stl_escape(vim.api.nvim_buf_get_name(bufnr))
|
||||
local buftype = vim.fn.getbufvar(bufnr, '&buftype')
|
||||
if buftype == 'help' then
|
||||
return 'help:' .. vim.fn.fnamemodify(file, ':t:r')
|
||||
|
@ -62,7 +66,8 @@ function Tab:render()
|
|||
-- setup for mouse clicks
|
||||
local line = string.format('%%%s@LualineSwitchTab@%s%%T', self.tabnr, name)
|
||||
-- apply highlight
|
||||
line = highlight.component_format_highlight(self.highlights[(self.current and 'active' or 'inactive')]) .. line
|
||||
line = modules.highlight.component_format_highlight(self.highlights[(self.current and 'active' or 'inactive')])
|
||||
.. line
|
||||
|
||||
-- apply separators
|
||||
if self.options.self.section < 'lualine_x' and not self.first then
|
||||
|
|
|
@ -174,6 +174,9 @@ end
|
|||
---@param str string
|
||||
---@return string
|
||||
function M.stl_escape(str)
|
||||
if type(str) ~= 'string' then
|
||||
return str
|
||||
end
|
||||
return str:gsub('%%', '%%%%')
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in New Issue