mirror of
https://github.com/LazyVim/LazyVim.git
synced 2025-06-24 17:58:51 +02:00
feat(lazygit): allow customizing the lazygit theme. Check the code to change the hl group mapping. Fixes #2846
This commit is contained in:
parent
6ed771de9d
commit
bb1480a6b9
1 changed files with 55 additions and 15 deletions
|
@ -7,6 +7,31 @@ local M = setmetatable({}, {
|
|||
end,
|
||||
})
|
||||
|
||||
---@alias LazyGitColor {fg?:string, bg?:string, bold?:boolean}
|
||||
|
||||
---@class LazyGitTheme: table<number, LazyGitColor>
|
||||
---@field activeBorderColor LazyGitColor
|
||||
---@field cherryPickedCommitBgColor LazyGitColor
|
||||
---@field cherryPickedCommitFgColor LazyGitColor
|
||||
---@field defaultFgColor LazyGitColor
|
||||
---@field inactiveBorderColor LazyGitColor
|
||||
---@field optionsTextColor LazyGitColor
|
||||
---@field searchingActiveBorderColor LazyGitColor
|
||||
---@field selectedLineBgColor LazyGitColor
|
||||
---@field unstagedChangesColor LazyGitColor
|
||||
M.theme = {
|
||||
[241] = { fg = "Special" },
|
||||
activeBorderColor = { fg = "MatchParen", bold = true },
|
||||
cherryPickedCommitBgColor = { fg = "Identifier" },
|
||||
cherryPickedCommitFgColor = { fg = "Function" },
|
||||
defaultFgColor = { fg = "Normal" },
|
||||
inactiveBorderColor = { fg = "FloatBorder" },
|
||||
optionsTextColor = { fg = "Function" },
|
||||
searchingActiveBorderColor = { fg = "MatchParen", bold = true },
|
||||
selectedLineBgColor = { bg = "Visual" }, -- set to `default` to have no background colour
|
||||
unstagedChangesColor = { fg = "DiagnosticError" },
|
||||
}
|
||||
|
||||
M.theme_path = vim.fn.stdpath("cache") .. "/lazygit-theme.yml"
|
||||
|
||||
-- re-create config file on startup
|
||||
|
@ -63,22 +88,37 @@ function M.set_ansi_color(idx, color)
|
|||
io.write(("\27]4;%d;%s\7"):format(idx, color))
|
||||
end
|
||||
|
||||
function M.update_config()
|
||||
-- LazyGit uses color 241 a lot, so also set it to a nice color
|
||||
-- pcall, since some terminals don't like this
|
||||
pcall(M.set_ansi_color, 241, LazyVim.ui.color("Special") or "blue")
|
||||
---@param v LazyGitColor
|
||||
---@return string[]
|
||||
function M.get_color(v)
|
||||
---@type string[]
|
||||
local color = {}
|
||||
if v.fg then
|
||||
color[1] = LazyVim.ui.color(v.fg)
|
||||
elseif v.bg then
|
||||
color[1] = LazyVim.ui.color(v.bg, true)
|
||||
end
|
||||
if v.bold then
|
||||
table.insert(color, "bold")
|
||||
end
|
||||
return color
|
||||
end
|
||||
|
||||
function M.update_config()
|
||||
---@type table<string, string[]>
|
||||
local theme = {}
|
||||
|
||||
for k, v in pairs(M.theme) do
|
||||
if type(k) == "number" then
|
||||
local color = M.get_color(v)
|
||||
-- LazyGit uses color 241 a lot, so also set it to a nice color
|
||||
-- pcall, since some terminals don't like this
|
||||
pcall(M.set_ansi_color, k, color[1])
|
||||
else
|
||||
theme[k] = M.get_color(v)
|
||||
end
|
||||
end
|
||||
|
||||
local theme = {
|
||||
activeBorderColor = { LazyVim.ui.color("MatchParen") or "orange", "bold" },
|
||||
cherryPickedCommitBgColor = { "cyan" },
|
||||
cherryPickedCommitFgColor = { "blue" },
|
||||
defaultFgColor = { "default" },
|
||||
inactiveBorderColor = { LazyVim.ui.color("FloatBorder") or "blue" },
|
||||
optionsTextColor = { "blue" },
|
||||
searchingActiveBorderColor = { LazyVim.ui.color("MatchParen") or "orange", "bold" },
|
||||
selectedLineBgColor = { LazyVim.ui.color("Visual", true) }, -- set to `default` to have no background colour
|
||||
unstagedChangesColor = { "red" },
|
||||
}
|
||||
local config = [[
|
||||
os:
|
||||
editPreset: "nvim-remote"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue