mirror of
https://github.com/LazyVim/LazyVim.git
synced 2025-06-28 03:30:12 +02:00
refactor(lualine): status component
This commit is contained in:
parent
ea266e7326
commit
5df382765b
2 changed files with 36 additions and 49 deletions
|
@ -44,36 +44,17 @@ return {
|
||||||
optional = true,
|
optional = true,
|
||||||
event = "VeryLazy",
|
event = "VeryLazy",
|
||||||
opts = function(_, opts)
|
opts = function(_, opts)
|
||||||
local colors = {
|
table.insert(
|
||||||
[""] = LazyVim.ui.fg("Special"),
|
opts.sections.lualine_x,
|
||||||
["Normal"] = LazyVim.ui.fg("Special"),
|
2,
|
||||||
["Warning"] = LazyVim.ui.fg("DiagnosticError"),
|
LazyVim.lualine.status(LazyVim.config.icons.kinds.Copilot, function()
|
||||||
["InProgress"] = LazyVim.ui.fg("DiagnosticWarn"),
|
local clients = package.loaded["copilot"] and LazyVim.lsp.get_clients({ name = "copilot", bufnr = 0 }) or {}
|
||||||
}
|
if #clients > 0 then
|
||||||
table.insert(opts.sections.lualine_x, 2, {
|
local status = require("copilot.api").status.data.status
|
||||||
function()
|
return (status == "InProgress" and "pending") or (status == "Warning" and "error") or "ok"
|
||||||
local icon = LazyVim.config.icons.kinds.Copilot
|
|
||||||
local status = require("copilot.api").status.data
|
|
||||||
return icon .. (status.message or "")
|
|
||||||
end,
|
|
||||||
cond = function()
|
|
||||||
if not package.loaded["copilot"] then
|
|
||||||
return
|
|
||||||
end
|
end
|
||||||
local ok, clients = pcall(LazyVim.lsp.get_clients, { name = "copilot", bufnr = 0 })
|
end)
|
||||||
if not ok then
|
)
|
||||||
return false
|
|
||||||
end
|
|
||||||
return ok and #clients > 0
|
|
||||||
end,
|
|
||||||
color = function()
|
|
||||||
if not package.loaded["copilot"] then
|
|
||||||
return
|
|
||||||
end
|
|
||||||
local status = require("copilot.api").status.data
|
|
||||||
return colors[status.status] or colors[""]
|
|
||||||
end,
|
|
||||||
})
|
|
||||||
end,
|
end,
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
|
@ -1,9 +1,33 @@
|
||||||
---@class lazyvim.util.lualine
|
---@class lazyvim.util.lualine
|
||||||
local M = {}
|
local M = {}
|
||||||
|
|
||||||
|
---@param icon string
|
||||||
|
---@param status fun(): nil|"ok"|"error"|"pending"
|
||||||
|
function M.status(icon, status)
|
||||||
|
local colors = {
|
||||||
|
ok = LazyVim.ui.fg("Special"),
|
||||||
|
error = LazyVim.ui.fg("DiagnosticError"),
|
||||||
|
pending = LazyVim.ui.fg("DiagnosticWarn"),
|
||||||
|
}
|
||||||
|
return {
|
||||||
|
function()
|
||||||
|
return icon
|
||||||
|
end,
|
||||||
|
cond = function()
|
||||||
|
return status() ~= nil
|
||||||
|
end,
|
||||||
|
color = function()
|
||||||
|
return colors[status()] or colors.ok
|
||||||
|
end,
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
|
---@param name string
|
||||||
|
---@param icon? string
|
||||||
function M.cmp_source(name, icon)
|
function M.cmp_source(name, icon)
|
||||||
|
icon = icon or LazyVim.config.icons.kinds[name:sub(1, 1):upper() .. name:sub(2)]
|
||||||
local started = false
|
local started = false
|
||||||
local function status()
|
return M.status(icon, function()
|
||||||
if not package.loaded["cmp"] then
|
if not package.loaded["cmp"] then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
@ -20,25 +44,7 @@ function M.cmp_source(name, icon)
|
||||||
return "ok"
|
return "ok"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end)
|
||||||
|
|
||||||
local colors = {
|
|
||||||
ok = LazyVim.ui.fg("Special"),
|
|
||||||
error = LazyVim.ui.fg("DiagnosticError"),
|
|
||||||
pending = LazyVim.ui.fg("DiagnosticWarn"),
|
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
|
||||||
function()
|
|
||||||
return icon or LazyVim.config.icons.kinds[name:sub(1, 1):upper() .. name:sub(2)]
|
|
||||||
end,
|
|
||||||
cond = function()
|
|
||||||
return status() ~= nil
|
|
||||||
end,
|
|
||||||
color = function()
|
|
||||||
return colors[status()] or colors.ok
|
|
||||||
end,
|
|
||||||
}
|
|
||||||
end
|
end
|
||||||
|
|
||||||
---@param component any
|
---@param component any
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue