feat(lualine): show readonly icon (#3567)

Adds a configurable lock icon when a file is opened as read only. Mimics
`vi -R <file>` status line.
This commit is contained in:
dotfrag 2024-06-10 23:06:09 +03:00 committed by GitHub
parent f5dc867ac2
commit 21617a9d60
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -72,7 +72,7 @@ function M.format(component, text, hl_group)
return component:format_hl(lualine_hl_group) .. text .. component:get_default_hl() return component:format_hl(lualine_hl_group) .. text .. component:get_default_hl()
end end
---@param opts? {relative: "cwd"|"root", modified_hl: string?, directory_hl: string?, filename_hl: string?} ---@param opts? {relative: "cwd"|"root", modified_hl: string?, directory_hl: string?, filename_hl: string?, modified_sign: string?, readonly_icon: string?, length: number?}
function M.pretty_path(opts) function M.pretty_path(opts)
opts = vim.tbl_extend("force", { opts = vim.tbl_extend("force", {
relative = "cwd", relative = "cwd",
@ -80,6 +80,7 @@ function M.pretty_path(opts)
directory_hl = "", directory_hl = "",
filename_hl = "Bold", filename_hl = "Bold",
modified_sign = "", modified_sign = "",
readonly_icon = " 󰌾 ",
length = 3, length = 3,
}, opts or {}) }, opts or {})
@ -120,7 +121,12 @@ function M.pretty_path(opts)
dir = table.concat({ unpack(parts, 1, #parts - 1) }, sep) dir = table.concat({ unpack(parts, 1, #parts - 1) }, sep)
dir = M.format(self, dir .. sep, opts.directory_hl) dir = M.format(self, dir .. sep, opts.directory_hl)
end end
return dir .. parts[#parts]
local readonly = ""
if vim.bo.readonly then
readonly = M.format(self, opts.readonly_icon, opts.modified_hl)
end
return dir .. parts[#parts] .. readonly
end end
end end