feat: cleanup

This commit is contained in:
Folke Lemaitre 2024-03-10 09:43:40 +01:00
parent 9d3101784c
commit ca13b88418
No known key found for this signature in database
GPG key ID: 41F8B1FBACAE2040

View file

@ -48,7 +48,7 @@ end
---@param hl_group? string ---@param hl_group? string
---@return string ---@return string
function M.format(component, text, hl_group) function M.format(component, text, hl_group)
if not hl_group then if not hl_group or hl_group == "" then
return text return text
end end
---@type table<string, string> ---@type table<string, string>
@ -56,36 +56,30 @@ function M.format(component, text, hl_group)
local lualine_hl_group = component.hl_cache[hl_group] local lualine_hl_group = component.hl_cache[hl_group]
if not lualine_hl_group then if not lualine_hl_group then
local utils = require("lualine.utils.utils") local utils = require("lualine.utils.utils")
local mygui = function() ---@type string[]
local mybold = utils.extract_highlight_colors(hl_group, "bold") and "bold" local gui = vim.tbl_filter(function(x)
local myitalic = utils.extract_highlight_colors(hl_group, "italic") and "italic" return x
if mybold and myitalic then end, {
return mybold .. "," .. myitalic utils.extract_highlight_colors(hl_group, "bold") and "bold",
elseif mybold then utils.extract_highlight_colors(hl_group, "italic") and "italic",
return mybold })
elseif myitalic then
return myitalic
else
return ""
end
end
lualine_hl_group = component:create_hl({ lualine_hl_group = component:create_hl({
fg = utils.extract_highlight_colors(hl_group, "fg"), fg = utils.extract_highlight_colors(hl_group, "fg"),
gui = mygui(), gui = #gui > 0 and table.concat(gui, ",") or nil,
}, "LV_" .. hl_group) }, "LV_" .. hl_group) --[[@as string]]
component.hl_cache[hl_group] = lualine_hl_group component.hl_cache[hl_group] = lualine_hl_group
end end
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?, dirpath_hl: string?, filename_hl: string?} ---@param opts? {relative: "cwd"|"root", modified_hl: string?, directory_hl: string?, filename_hl: string?}
function M.pretty_path(opts) function M.pretty_path(opts)
opts = vim.tbl_extend("force", { opts = vim.tbl_extend("force", {
relative = "cwd", relative = "cwd",
modified_hl = "Constant", modified_hl = "MatchParen",
dirpath_hl = "", directory_hl = "",
filename_hl = "", filename_hl = "Bold",
}, opts or {}) }, opts or {})
return function(self) return function(self)
@ -117,12 +111,12 @@ function M.pretty_path(opts)
parts[#parts] = M.format(self, parts[#parts], opts.filename_hl) parts[#parts] = M.format(self, parts[#parts], opts.filename_hl)
end end
local dirpath = "" local dir = ""
if #parts > 1 then if #parts > 1 then
dirpath = table.concat({ unpack(parts, 1, #parts - 1) }, sep) dir = table.concat({ unpack(parts, 1, #parts - 1) }, sep)
dirpath = M.format(self, dirpath .. sep, opts.dirpath_hl) dir = M.format(self, dir .. sep, opts.directory_hl)
end end
return dirpath .. parts[#parts] return dir .. parts[#parts]
end end
end end