mirror of https://github.com/folke/lazy.nvim.git
feat(view): modes and help
This commit is contained in:
parent
88869e67d2
commit
0db98bf053
|
@ -8,6 +8,7 @@ local M = {}
|
|||
---@field wait? boolean
|
||||
---@field clear? boolean
|
||||
---@field interactive? boolean
|
||||
---@field mode? string
|
||||
|
||||
---@param ropts RunnerOpts
|
||||
---@param opts? ManagerOpts
|
||||
|
@ -23,7 +24,7 @@ function M.run(ropts, opts)
|
|||
|
||||
if opts.interactive then
|
||||
vim.schedule(function()
|
||||
require("lazy.view").show()
|
||||
require("lazy.view").show(opts.mode)
|
||||
end)
|
||||
end
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@ local M = {}
|
|||
|
||||
M.colors = {
|
||||
Error = "ErrorMsg",
|
||||
H1 = "Title",
|
||||
H1 = "IncSearch",
|
||||
H2 = "Bold",
|
||||
Muted = "Comment",
|
||||
Normal = "NormalFloat",
|
||||
|
@ -21,7 +21,9 @@ M.colors = {
|
|||
LoaderKeys = "Statement",
|
||||
LoaderStart = "@field",
|
||||
LoaderSource = "Character",
|
||||
LoaderCmd = "Operator"
|
||||
LoaderCmd = "Operator",
|
||||
Button = "CursorLine",
|
||||
ButtonActive = "Visual",
|
||||
}
|
||||
|
||||
M.did_setup = false
|
||||
|
|
|
@ -17,34 +17,37 @@ end
|
|||
|
||||
M.commands = {
|
||||
clean = function()
|
||||
Manage.clean({ clear = true, interactive = true })
|
||||
Manage.clean({ clear = true, interactive = true, mode = "clean" })
|
||||
end,
|
||||
clear = function()
|
||||
Manage.clear()
|
||||
View.show()
|
||||
end,
|
||||
install = function()
|
||||
Manage.install({ clear = true, interactive = true })
|
||||
Manage.install({ clear = true, interactive = true, mode = "install" })
|
||||
end,
|
||||
log = function()
|
||||
Manage.log({ clear = true, interactive = true })
|
||||
Manage.log({ clear = true, interactive = true, mode = "log" })
|
||||
end,
|
||||
show = function()
|
||||
View.show()
|
||||
end,
|
||||
help = function()
|
||||
View.show("help")
|
||||
end,
|
||||
sync = function()
|
||||
Manage.clean({ interactive = true, clear = true, wait = true })
|
||||
Manage.clean({ interactive = true, clear = true, wait = true, mode = "sync" })
|
||||
Manage.update({ interactive = true })
|
||||
Manage.install({ interactive = true })
|
||||
end,
|
||||
update = function()
|
||||
Manage.update({ clear = true, interactive = true })
|
||||
Manage.update({ clear = true, interactive = true, mode = "update" })
|
||||
end,
|
||||
check = function()
|
||||
Manage.check({ clear = true, interactive = true })
|
||||
Manage.check({ clear = true, interactive = true, mode = "check" })
|
||||
end,
|
||||
restore = function()
|
||||
Manage.update({ clear = true, interactive = true, lockfile = true })
|
||||
Manage.update({ clear = true, interactive = true, lockfile = true, mode = "restore" })
|
||||
end,
|
||||
}
|
||||
|
||||
|
|
|
@ -4,16 +4,36 @@ local Config = require("lazy.core.config")
|
|||
|
||||
local M = {}
|
||||
|
||||
M.modes = {
|
||||
{ name = "install", key = "I", desc = "Install missing plugins" },
|
||||
{ name = "update", key = "U", desc = "Update all plugins. This will also update the lockfile" },
|
||||
{ name = "sync", key = "S", desc = "Run install, clean and update" },
|
||||
{ name = "clean", key = "X", desc = "Clean plugins that are no longer needed" },
|
||||
{ name = "check", key = "C", desc = "Check for updates and show the log (git fetch)" },
|
||||
{ name = "log", key = "L", desc = "Show recent updates for all plugins" },
|
||||
{ name = "restore", key = "R", desc = "Updates all plugins to the state in the lockfile" },
|
||||
{ name = "help", key = "g?", hide = true, desc = "Toggle this help page" },
|
||||
}
|
||||
|
||||
---@type string?
|
||||
M.mode = nil
|
||||
|
||||
function M.setup()
|
||||
require("lazy.view.commands").setup()
|
||||
require("lazy.view.colors").setup()
|
||||
end
|
||||
|
||||
function M.show()
|
||||
function M.show(mode)
|
||||
if mode == "help" and M.mode == "help" then
|
||||
M.mode = nil
|
||||
else
|
||||
M.mode = mode or M.mode
|
||||
end
|
||||
require("lazy.view.colors").setup()
|
||||
|
||||
if M._buf and vim.api.nvim_buf_is_valid(M._buf) then
|
||||
vim.api.nvim_win_set_cursor(M._win, { 1, 0 })
|
||||
vim.cmd([[do User LazyRender]])
|
||||
return
|
||||
end
|
||||
|
||||
|
@ -24,8 +44,8 @@ function M.show()
|
|||
local opts = {
|
||||
relative = "editor",
|
||||
style = "minimal",
|
||||
width = math.min(vim.o.columns - hpad * 2, 150),
|
||||
height = math.min(vim.o.lines - vpad * 2, 50),
|
||||
width = math.min(vim.o.columns - hpad * 2, 200),
|
||||
height = math.min(vim.o.lines - vpad * 2, 70),
|
||||
}
|
||||
opts.row = (vim.o.lines - opts.height) / 2
|
||||
opts.col = (vim.o.columns - opts.width) / 2
|
||||
|
@ -130,6 +150,13 @@ function M.show()
|
|||
end,
|
||||
})
|
||||
|
||||
for _, m in ipairs(M.modes) do
|
||||
vim.keymap.set("n", m.key, function()
|
||||
local Commands = require("lazy.view.commands")
|
||||
Commands.cmd(m.name)
|
||||
end, { buffer = buf })
|
||||
end
|
||||
|
||||
vim.api.nvim_create_autocmd("User", {
|
||||
pattern = "LazyRender",
|
||||
callback = function()
|
||||
|
|
|
@ -34,8 +34,6 @@ function M:update()
|
|||
self._diagnostics = {}
|
||||
self.plugin_range = {}
|
||||
|
||||
Plugin.update_state(true)
|
||||
|
||||
self.plugins = vim.tbl_values(Config.plugins)
|
||||
vim.list_extend(self.plugins, vim.tbl_values(Config.to_clean))
|
||||
table.sort(self.plugins, function(a, b)
|
||||
|
@ -58,11 +56,15 @@ function M:update()
|
|||
end
|
||||
end
|
||||
|
||||
self:title()
|
||||
local mode = self:title()
|
||||
|
||||
if mode == "help" then
|
||||
self:help()
|
||||
else
|
||||
for _, section in ipairs(Sections) do
|
||||
self:section(section)
|
||||
end
|
||||
end
|
||||
|
||||
self:trim()
|
||||
self:render(self.buf)
|
||||
|
@ -90,19 +92,55 @@ function M:get_plugin(row)
|
|||
end
|
||||
|
||||
function M:title()
|
||||
self:append("Lazy", "LazyH1")
|
||||
if self.progress.done < self.progress.total then
|
||||
self:append(" (" .. self.progress.done .. "/" .. self.progress.total .. ")", "LazyMuted"):nl()
|
||||
self:progressbar()
|
||||
else
|
||||
self:append(" (" .. #self.plugins .. ")", "LazyMuted"):nl()
|
||||
self:append(" lazy.nvim ", "LazyH1"):center():nl()
|
||||
self:append("press "):append("g?", "LazySpecial"):append(" for help"):center():nl()
|
||||
self:append("https://github.com/folke/lazy.nvim", "LazyMuted"):center():nl()
|
||||
|
||||
local View = require("lazy.view")
|
||||
for _, mode in ipairs(View.modes) do
|
||||
if not mode.hide then
|
||||
local title = " " .. mode.name:sub(1, 1):upper() .. mode.name:sub(2) .. " (" .. mode.key .. ") "
|
||||
self:append(title, View.mode == mode.name and "LazyButtonActive" or "LazyButton"):append(" ")
|
||||
end
|
||||
end
|
||||
self:nl()
|
||||
if self.progress.done < self.progress.total then
|
||||
self:progressbar()
|
||||
end
|
||||
self:nl()
|
||||
|
||||
if View.mode ~= "help" then
|
||||
if self.progress.done < self.progress.total then
|
||||
self:append("Tasks: ", "LazyH2")
|
||||
self:append(self.progress.done .. "/" .. self.progress.total, "LazyMuted")
|
||||
else
|
||||
self:append("Total: ", "LazyH2")
|
||||
self:append(#self.plugins .. " plugins", "LazyMuted")
|
||||
end
|
||||
self:nl():nl()
|
||||
end
|
||||
return View.mode
|
||||
end
|
||||
|
||||
function M:help()
|
||||
local View = require("lazy.view")
|
||||
self:append("Help", "LazyH2"):nl():nl()
|
||||
|
||||
self:append("Keyboard Shortcuts", "LazyH2"):nl()
|
||||
for _, mode in ipairs(View.modes) do
|
||||
local title = mode.name:sub(1, 1):upper() .. mode.name:sub(2)
|
||||
self:append("- ", "LazySpecial", { indent = 2 })
|
||||
self:append(title, "Title"):append(" <" .. mode.key .. "> ", "LazyKey")
|
||||
self:append(mode.desc or ""):nl()
|
||||
end
|
||||
end
|
||||
|
||||
function M:progressbar()
|
||||
local width = vim.api.nvim_win_get_width(self.win) - 2 * self.padding
|
||||
local done = math.floor((self.progress.done / self.progress.total) * width + 0.5)
|
||||
if self.progress.done == self.progress.total then
|
||||
done = 0
|
||||
end
|
||||
self:append("", {
|
||||
virt_text_win_col = self.padding,
|
||||
virt_text = { { string.rep("─", done), "LazyProgressDone" } },
|
||||
|
|
Loading…
Reference in New Issue