feat(ui): made it look a little less like a Mason rip-off :)

This commit is contained in:
Folke Lemaitre 2022-12-17 15:56:13 +01:00
parent 85e375223f
commit 9026a0e25d
No known key found for this signature in database
GPG Key ID: 41F8B1FBACAE2040
4 changed files with 31 additions and 13 deletions

View File

@ -7,7 +7,7 @@ local M = {}
---@param cmd string ---@param cmd string
---@param plugins? LazyPlugin[] ---@param plugins? LazyPlugin[]
function M.cmd(cmd, plugins) function M.cmd(cmd, plugins)
cmd = cmd == "" and "show" or cmd cmd = cmd == "" and "home" or cmd
local command = M.commands[cmd] local command = M.commands[cmd]
if command == nil then if command == nil then
Util.error("Invalid lazy command '" .. cmd .. "'") Util.error("Invalid lazy command '" .. cmd .. "'")
@ -30,8 +30,8 @@ M.commands = {
log = function(plugins) log = function(plugins)
Manage.log({ clear = true, mode = "log", plugins = plugins }) Manage.log({ clear = true, mode = "log", plugins = plugins })
end, end,
show = function() home = function()
View.show() View.show("home")
end, end,
help = function() help = function()
View.show("help") View.show("help")

View File

@ -5,6 +5,7 @@ local Config = require("lazy.core.config")
local M = {} local M = {}
M.modes = { M.modes = {
{ name = "home", key = "H", desc = "Go back to plugin list" },
{ name = "install", key = "I", desc = "Install missing plugins" }, { name = "install", key = "I", desc = "Install missing plugins" },
{ name = "update", key = "U", desc = "Update all plugins. This will also update the lockfile" }, { 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 = "sync", key = "S", desc = "Run install, clean and update" },
@ -14,7 +15,7 @@ M.modes = {
{ name = "restore", key = "R", desc = "Updates all plugins to the state in the lockfile" }, { name = "restore", key = "R", desc = "Updates all plugins to the state in the lockfile" },
{ name = "profile", key = "P", desc = "Show detailed profiling", toggle = true }, { name = "profile", key = "P", desc = "Show detailed profiling", toggle = true },
{ name = "debug", key = "D", desc = "Show debug information", toggle = true }, { name = "debug", key = "D", desc = "Show debug information", toggle = true },
{ name = "help", key = "?", hide = true, desc = "Toggle this help page", toggle = true }, { name = "help", key = "?", desc = "Toggle this help page", toggle = true },
{ plugin = true, name = "update", key = "u", desc = "Update this plugin. This will also update the lockfile" }, { plugin = true, name = "update", key = "u", desc = "Update this plugin. This will also update the lockfile" },
{ {
@ -38,7 +39,7 @@ function M.setup()
end end
function M.show(mode) function M.show(mode)
M.mode = mode or M.mode M.mode = mode or M.mode or "home"
require("lazy.view.colors").setup() require("lazy.view.colors").setup()
if M._buf and vim.api.nvim_buf_is_valid(M._buf) then if M._buf and vim.api.nvim_buf_is_valid(M._buf) then

View File

@ -94,15 +94,32 @@ function M:get_plugin(row)
end end
function M:title() function M:title()
self:append(" lazy.nvim ", "LazyH1"):center():nl() self:nl():nl()
self:append("press "):append("<?>", "LazySpecial"):append(" for help"):center():nl()
self:append("https://github.com/folke/lazy.nvim", "LazyMuted"):center():nl()
local View = require("lazy.view") local View = require("lazy.view")
for _, mode in ipairs(View.modes) do for _, mode in ipairs(View.modes) do
if not mode.hide and not mode.plugin then if not mode.hide and not mode.plugin then
local title = " " .. mode.name:sub(1, 1):upper() .. mode.name:sub(2) .. " (" .. mode.key .. ") " 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(" ") if mode.name == "home" then
if View.mode == "home" then
title = " lazy.nvim 鈴 "
else
title = " lazy.nvim (H) "
end
end
if View.mode == mode.name then
if mode.name == "home" then
self:append(title, "LazyH1")
else
self:append(title, "LazyButtonActive")
self:highlight({ ["%(.%)"] = "LazySpecial" })
end
else
self:append(title, "LazyButton")
self:highlight({ ["%(.%)"] = "LazySpecial" })
end
self:append(" ")
end end
end end
self:nl() self:nl()

View File

@ -137,9 +137,9 @@ function Text:center()
end end
function Text:trim() function Text:trim()
while #self._lines > 0 and #self._lines[1] == 0 do -- while #self._lines > 0 and #self._lines[1] == 0 do
table.remove(self._lines, 1) -- table.remove(self._lines, 1)
end -- end
while #self._lines > 0 and #self._lines[#self._lines] == 0 do while #self._lines > 0 and #self._lines[#self._lines] == 0 do
table.remove(self._lines) table.remove(self._lines)