feat(ui): made all highlight groups and icons configurable

This commit is contained in:
Folke Lemaitre 2022-12-26 10:24:47 +01:00
parent 3d22c496da
commit 0ea771bd70
No known key found for this signature in database
GPG Key ID: 41F8B1FBACAE2040
5 changed files with 108 additions and 78 deletions

View File

@ -315,6 +315,8 @@ return {
-- The border to use for the UI window. Accepts same border values as |nvim_open_win()|. -- The border to use for the UI window. Accepts same border values as |nvim_open_win()|.
border = "none", border = "none",
icons = { icons = {
loaded = "●",
not_loaded = "○",
cmd = " ", cmd = " ",
config = "", config = "",
event = "", event = "",
@ -327,6 +329,12 @@ return {
start = "", start = "",
task = "✔ ", task = "✔ ",
lazy = "鈴 ", lazy = "鈴 ",
list = {
"●",
"➜",
"★",
"",
},
}, },
throttle = 20, -- how frequently should the ui process render events throttle = 20, -- how frequently should the ui process render events
custom_keys = { custom_keys = {
@ -667,28 +675,35 @@ To uninstall **lazy.nvim**, you need to remove the following files and directori
<!-- colors:start --> <!-- colors:start -->
| Highlight Group | Default Group | Description | | Highlight Group | Default Group | Description |
| ---------------------- | -------------------------- | ----------------- | | --------------------- | -------------------------- | --------------------------------------------------- |
| **LazyButton** | **_CursorLine_** | | | **LazyButton** | **_CursorLine_** | |
| **LazyButtonActive** | **_Visual_** | | | **LazyButtonActive** | **_Visual_** | |
| **LazyCommit** | **_@variable.builtin_** | | | **LazyComment** | **_Comment_** | |
| **LazyError** | **_ErrorMsg_** | task errors | | **LazyCommit** | **_@variable.builtin_** | commit ref |
| **LazyH1** | **_IncSearch_** | | | **LazyCommitIssue** | **_Number_** | |
| **LazyH2** | **_Bold_** | | | **LazyCommitScope** | **_Italic_** | conventional commit scope |
| **LazyHandlerCmd** | **_Operator_** | | | **LazyCommitType** | **_Title_** | conventional commit type |
| **LazyHandlerEvent** | **_Constant_** | | | **LazyDir** | **_@text.reference_** | directory |
| **LazyHandlerFt** | **_Character_** | | | **LazyH1** | **_IncSearch_** | home button |
| **LazyHandlerKeys** | **_Statement_** | | | **LazyH2** | **_Bold_** | titles |
| **LazyHandlerPlugin** | **_Special_** | | | **LazyNoCond** | **_DiagnosticWarn_** | unloaded icon for a plugin where `cond()` was false |
| **LazyHandlerRuntime** | **_@macro_** | |
| **LazyHandlerSource** | **_Character_** | |
| **LazyHandlerStart** | **_@field_** | |
| **LazyKey** | **_Conceal_** | |
| **LazyMuted** | **_Comment_** | |
| **LazyNormal** | **_NormalFloat_** | | | **LazyNormal** | **_NormalFloat_** | |
| **LazyProgressDone** | **_Constant_** | progress bar done | | **LazyProgressDone** | **_Constant_** | progress bar done |
| **LazyProgressTodo** | **_LineNr_** | progress bar todo | | **LazyProgressTodo** | **_LineNr_** | progress bar todo |
| **LazyProp** | **_Conceal_** | property |
| **LazyReasonCmd** | **_Operator_** | |
| **LazyReasonEvent** | **_Constant_** | |
| **LazyReasonFt** | **_Character_** | |
| **LazyReasonKeys** | **_Statement_** | |
| **LazyReasonPlugin** | **_Special_** | |
| **LazyReasonRuntime** | **_@macro_** | |
| **LazyReasonSource** | **_Character_** | |
| **LazyReasonStart** | **_@field_** | |
| **LazySpecial** | **_@punctuation.special_** | | | **LazySpecial** | **_@punctuation.special_** | |
| **LazyValue** | **_@string_** | | | **LazyTaskError** | **_ErrorMsg_** | task errors |
| **LazyTaskOutput** | **_MsgArea_** | task output |
| **LazyUrl** | **_@text.reference_** | url |
| **LazyValue** | **_@string_** | value of a property |
<!-- colors:end --> <!-- colors:end -->

View File

@ -37,6 +37,8 @@ M.defaults = {
-- The border to use for the UI window. Accepts same border values as |nvim_open_win()|. -- The border to use for the UI window. Accepts same border values as |nvim_open_win()|.
border = "none", border = "none",
icons = { icons = {
loaded = "",
not_loaded = "",
cmd = "", cmd = "",
config = "", config = "",
event = "", event = "",
@ -49,6 +51,12 @@ M.defaults = {
start = "", start = "",
task = "", task = "",
lazy = "", lazy = "",
list = {
"",
"",
"",
"",
},
}, },
throttle = 20, -- how frequently should the ui process render events throttle = 20, -- how frequently should the ui process render events
custom_keys = { custom_keys = {

View File

@ -1,28 +1,34 @@
local M = {} local M = {}
M.colors = { M.colors = {
Error = "ErrorMsg", -- task errors H1 = "IncSearch", -- home button
H1 = "IncSearch", H2 = "Bold", -- titles
H2 = "Bold", Comment = "Comment",
Muted = "Comment",
Normal = "NormalFloat", Normal = "NormalFloat",
Commit = "@variable.builtin", Commit = "@variable.builtin", -- commit ref
Key = "Conceal", CommitIssue = "Number",
Value = "@string", CommitType = "Title", -- conventional commit type
NoCond = "DiagnosticError", CommitScope = "Italic", -- conventional commit scope
Prop = "Conceal", -- property
Value = "@string", -- value of a property
NoCond = "DiagnosticWarn", -- unloaded icon for a plugin where `cond()` was false
ProgressDone = "Constant", -- progress bar done ProgressDone = "Constant", -- progress bar done
ProgressTodo = "LineNr", -- progress bar todo ProgressTodo = "LineNr", -- progress bar todo
Special = "@punctuation.special", Special = "@punctuation.special",
HandlerRuntime = "@macro", ReasonRuntime = "@macro",
HandlerPlugin = "Special", ReasonPlugin = "Special",
HandlerEvent = "Constant", ReasonEvent = "Constant",
HandlerKeys = "Statement", ReasonKeys = "Statement",
HandlerStart = "@field", ReasonStart = "@field",
HandlerSource = "Character", ReasonSource = "Character",
HandlerFt = "Character", ReasonFt = "Character",
HandlerCmd = "Operator", ReasonCmd = "Operator",
Button = "CursorLine", Button = "CursorLine",
ButtonActive = "Visual", ButtonActive = "Visual",
TaskOutput = "MsgArea", -- task output
TaskError = "ErrorMsg", -- task errors
Dir = "@text.reference", -- directory
Url = "@text.reference", -- url
} }
M.did_setup = false M.did_setup = false

View File

@ -77,6 +77,10 @@ function M:mount()
end end
---@class LazyViewWinOpts ---@class LazyViewWinOpts
---@field width number
---@field height number
---@field row number
---@field col number
local win_opts = { local win_opts = {
relative = "editor", relative = "editor",
style = "minimal", style = "minimal",
@ -111,6 +115,7 @@ function M:mount()
self:layout() self:layout()
local config = {} local config = {}
for _, key in ipairs({ "relative", "width", "height", "col", "row" }) do for _, key in ipairs({ "relative", "width", "height", "col", "row" }) do
---@diagnostic disable-next-line: no-unknown
config[key] = self.opts.win_opts[key] config[key] = self.opts.win_opts[key]
end end
vim.api.nvim_win_set_config(self.win, config) vim.api.nvim_win_set_config(self.win, config)

View File

@ -141,10 +141,10 @@ function M:title()
if self.view.state.mode ~= "help" and self.view.state.mode ~= "profile" and self.view.state.mode ~= "debug" then if self.view.state.mode ~= "help" and self.view.state.mode ~= "profile" and self.view.state.mode ~= "debug" then
if self.progress.done < self.progress.total then if self.progress.done < self.progress.total then
self:append("Tasks: ", "LazyH2") self:append("Tasks: ", "LazyH2")
self:append(self.progress.done .. "/" .. self.progress.total, "LazyMuted") self:append(self.progress.done .. "/" .. self.progress.total, "LazyComment")
else else
self:append("Total: ", "LazyH2") self:append("Total: ", "LazyH2")
self:append(#self.plugins .. " plugins", "LazyMuted") self:append(#self.plugins .. " plugins", "LazyComment")
end end
self:nl():nl() self:nl():nl()
end end
@ -174,7 +174,7 @@ function M:help()
self:append("- ", "LazySpecial", { indent = 2 }) self:append("- ", "LazySpecial", { indent = 2 })
self:append(title, "Title") self:append(title, "Title")
if mode.key then if mode.key then
self:append(" <" .. mode.key .. ">", "LazyKey") self:append(" <" .. mode.key .. ">", "LazyProp")
end end
self:append(" " .. (mode.desc or "")):nl() self:append(" " .. (mode.desc or "")):nl()
end end
@ -187,7 +187,7 @@ function M:help()
self:append("- ", "LazySpecial", { indent = 2 }) self:append("- ", "LazySpecial", { indent = 2 })
self:append(title, "Title") self:append(title, "Title")
if mode.key_plugin then if mode.key_plugin then
self:append(" <" .. mode.key_plugin .. ">", "LazyKey") self:append(" <" .. mode.key_plugin .. ">", "LazyProp")
end end
self:append(" " .. (mode.desc_plugin or mode.desc)):nl() self:append(" " .. (mode.desc_plugin or mode.desc)):nl()
end end
@ -225,7 +225,7 @@ function M:section(section)
local count = #section_plugins local count = #section_plugins
if count > 0 then if count > 0 then
self:append(section.title, "LazyH2"):append(" (" .. count .. ")", "LazyMuted"):nl() self:append(section.title, "LazyH2"):append(" (" .. count .. ")", "LazyComment"):nl()
for _, plugin in ipairs(section_plugins) do for _, plugin in ipairs(section_plugins) do
self:plugin(plugin) self:plugin(plugin)
end end
@ -306,13 +306,13 @@ function M:reason(reason, opts)
if key == "keys" then if key == "keys" then
value = type(value) == "string" and value or value[1] value = type(value) == "string" and value or value[1]
end end
local hl = "LazyHandler" .. key:sub(1, 1):upper() .. key:sub(2) local hl = "LazyReason" .. key:sub(1, 1):upper() .. key:sub(2)
local icon = Config.options.ui.icons[key] local icon = Config.options.ui.icons[key]
if icon then if icon then
self:append(icon .. " ", hl) self:append(icon .. " ", hl)
self:append(value, hl) self:append(value, hl)
else else
self:append(key .. " ", "@field") self:append(key .. " ", hl)
self:append(value, hl) self:append(value, hl)
end end
end end
@ -320,7 +320,6 @@ function M:reason(reason, opts)
if time and opts.time_right then if time and opts.time_right then
self:append(time, "Bold") self:append(time, "Bold")
end end
-- self:append(")", "Conceal")
end end
---@param plugin LazyPlugin ---@param plugin LazyPlugin
@ -358,11 +357,11 @@ end
---@param plugin LazyPlugin ---@param plugin LazyPlugin
function M:plugin(plugin) function M:plugin(plugin)
if plugin._.loaded then if plugin._.loaded then
self:append(" ", "LazySpecial"):append(plugin.name) self:append(" " .. Config.options.ui.icons.loaded .. " ", "LazySpecial"):append(plugin.name)
elseif plugin._.cond == false then elseif plugin._.cond == false then
self:append(" ", "LazyNoCond"):append(plugin.name) self:append(" " .. Config.options.ui.icons.not_loaded .. " ", "LazyNoCond"):append(plugin.name)
else else
self:append(" ", "LazySpecial"):append(plugin.name) self:append(" " .. Config.options.ui.icons.not_loaded .. " ", "LazySpecial"):append(plugin.name)
end end
local plugin_start = self:row() local plugin_start = self:row()
if plugin._.loaded then if plugin._.loaded then
@ -382,24 +381,21 @@ end
---@param plugin LazyPlugin ---@param plugin LazyPlugin
function M:tasks(plugin) function M:tasks(plugin)
for _, task in ipairs(plugin._.tasks or {}) do for _, task in ipairs(plugin._.tasks or {}) do
if self.view.state.plugin == plugin.name then if self.view:is_selected(plugin) then
self:append("[task] ", "Title", { indent = 4 }):append(task.name) self:append(Config.options.ui.icons.task .. "[task] ", "Title", { indent = 4 }):append(task.name)
self:append(" " .. math.floor((task:time()) * 100) / 100 .. "ms", "Bold") self:append(" " .. math.floor((task:time()) * 100) / 100 .. "ms", "Bold")
self:nl() self:nl()
end end
if task.name == "log" and not task.error then
self:log(task)
elseif task.error or self.view:is_selected(plugin) then
if task.error then if task.error then
self:append(vim.trim(task.error), "LazyError", { indent = 4, prefix = "" }) self:append(vim.trim(task.error), "LazyTaskError", { indent = 6 })
self:nl() self:nl()
end elseif task.name == "log" then
if task.output ~= "" and task.output ~= task.error then self:log(task)
self:append(vim.trim(task.output), "MsgArea", { indent = 4, prefix = "" }) elseif self.view:is_selected(plugin) and task.output ~= "" and task.output ~= task.error then
self:append(vim.trim(task.output), "LazyTaskOutput", { indent = 6 })
self:nl() self:nl()
end end
end end
end
end end
---@param task LazyTask ---@param task LazyTask
@ -414,15 +410,15 @@ function M:log(task)
end end
self:append(ref:sub(1, 7) .. " ", "LazyCommit", { indent = 6 }) self:append(ref:sub(1, 7) .. " ", "LazyCommit", { indent = 6 })
self:append(vim.trim(msg)):highlight({ self:append(vim.trim(msg)):highlight({
["#%d+"] = "Number", ["#%d+"] = "LazyCommitIssue",
["^%S+:"] = "Title", ["^%S+:"] = "LazyCommitType",
["^%S+(%(.*%)):"] = "Italic", ["^%S+(%(.*%)):"] = "LazyCommitScope",
["`.-`"] = "@text.literal.markdown_inline", ["`.-`"] = "@text.literal.markdown_inline",
["%*.-%*"] = "Italic", ["%*.-%*"] = "Italic",
["%*%*.-%*%*"] = "Bold", ["%*%*.-%*%*"] = "Bold",
}) })
-- string.gsub -- string.gsub
self:append(" " .. time, "Comment") self:append(" " .. time, "LazyComment")
self:nl() self:nl()
end end
self:nl() self:nl()
@ -433,9 +429,9 @@ end
function M:details(plugin) function M:details(plugin)
---@type string[][] ---@type string[][]
local props = {} local props = {}
table.insert(props, { "dir", plugin.dir, "@text.reference" }) table.insert(props, { "dir", plugin.dir, "LazyDir" })
if plugin.url then if plugin.url then
table.insert(props, { "url", (plugin.url:gsub("%.git$", "")), "@text.reference" }) table.insert(props, { "url", (plugin.url:gsub("%.git$", "")), "LazyUrl" })
end end
local git = Git.info(plugin.dir, true) local git = Git.info(plugin.dir, true)
if git then if git then
@ -483,7 +479,7 @@ function M:details(plugin)
width = math.max(width, #prop[1]) width = math.max(width, #prop[1])
end end
for _, prop in ipairs(props) do for _, prop in ipairs(props) do
self:append(prop[1] .. string.rep(" ", width - #prop[1] + 1), "LazyKey", { indent = 6 }) self:append(prop[1] .. string.rep(" ", width - #prop[1] + 1), "LazyProp", { indent = 6 })
if type(prop[2]) == "function" then if type(prop[2]) == "function" then
prop[2]() prop[2]()
else else
@ -508,12 +504,6 @@ function M:profile()
:nl() :nl()
self:nl() self:nl()
local symbols = {
"",
"",
"",
"",
}
---@param a LazyProfile ---@param a LazyProfile
---@param b LazyProfile ---@param b LazyProfile
@ -543,7 +533,7 @@ function M:profile()
end end
local data = type(entry.data) == "string" and { source = entry.data } or entry.data local data = type(entry.data) == "string" and { source = entry.data } or entry.data
data.time = entry.time data.time = entry.time
local symbol = symbols[depth] or symbols[#symbols] local symbol = M.list_icon(depth)
self:append((" "):rep(depth)):append(symbol, "LazySpecial"):append(" ") self:append((" "):rep(depth)):append(symbol, "LazySpecial"):append(" ")
self:reason(data, { time_right = true }) self:reason(data, { time_right = true })
self:nl() self:nl()
@ -557,12 +547,17 @@ function M:profile()
end end
end end
function M.list_icon(depth)
local symbols = Config.options.ui.icons.list
return symbols[(depth - 1) % #symbols + 1]
end
function M:debug() function M:debug()
self:append("Active Handlers", "LazyH2"):nl() self:append("Active Handlers", "LazyH2"):nl()
self self
:append( :append(
"This shows only the lazy handlers that are still active. When a plugin loads, its handlers are removed", "This shows only the lazy handlers that are still active. When a plugin loads, its handlers are removed",
"Comment", "LazyComment",
{ indent = 2 } { indent = 2 }
) )
:nl() :nl()
@ -571,6 +566,7 @@ function M:debug()
Util.foreach(handler.active, function(value, plugins) Util.foreach(handler.active, function(value, plugins)
value = type(value) == "table" and value[1] or value value = type(value) == "table" and value[1] or value
if not vim.tbl_isempty(plugins) then if not vim.tbl_isempty(plugins) then
---@type string[]
plugins = vim.tbl_values(plugins) plugins = vim.tbl_values(plugins)
table.sort(plugins) table.sort(plugins)
self:append("", "LazySpecial", { indent = 2 }) self:append("", "LazySpecial", { indent = 2 })
@ -590,7 +586,7 @@ function M:debug()
local kb = math.floor(#entry.chunk / 10.24) / 100 local kb = math.floor(#entry.chunk / 10.24) / 100
self:append("", "LazySpecial", { indent = 2 }):append(modname):append(" " .. kb .. "Kb", "Bold") self:append("", "LazySpecial", { indent = 2 }):append(modname):append(" " .. kb .. "Kb", "Bold")
if entry.modpath ~= modname then if entry.modpath ~= modname then
self:append(" " .. vim.fn.fnamemodify(entry.modpath, ":p:~:."), "Comment") self:append(" " .. vim.fn.fnamemodify(entry.modpath, ":p:~:."), "LazyComment")
end end
self:nl() self:nl()
end) end)