mirror of
https://github.com/catppuccin/nvim.git
synced 2026-01-09 07:53:46 +08:00
feat(lualine): color overrides for lualine integration (#843)
* Implement lualine integration with color overrides * docs: auto generate vimdoc * Apply suggestions from code review minors from initial review Co-authored-by: robin <comfysagedev@gmail.com> * docs: auto generate vimdoc * Inline lualine/catppuccin lua config setup README.md As per suggestions in code review * docs: auto generate vimdoc --------- Co-authored-by: Nathan Bellows <nbellows@amazon.com> Co-authored-by: robin <comfysagedev@gmail.com>
This commit is contained in:
parent
ce8d176faa
commit
6efc53e42c
64
README.md
64
README.md
@ -997,11 +997,75 @@ require("lspsaga").setup {
|
||||
<td> <a href="https://github.com/nvim-lualine/lualine.nvim">lualine.nvim</a> </td>
|
||||
<td>
|
||||
|
||||
```lua
|
||||
-- transparent_bg = opts.transparent_background and "NONE" or C.mantle
|
||||
lualine = {
|
||||
normal = {
|
||||
a = { bg = C.blue, fg = C.mantle, gui = "bold" },
|
||||
b = { bg = C.surface0, fg = C.blue },
|
||||
c = { bg = transparent_bg, fg = C.text },
|
||||
},
|
||||
|
||||
insert = {
|
||||
a = { bg = C.green, fg = C.base, gui = "bold" },
|
||||
b = { bg = C.surface0, fg = C.green },
|
||||
},
|
||||
|
||||
terminal = {
|
||||
a = { bg = C.green, fg = C.base, gui = "bold" },
|
||||
b = { bg = C.surface0, fg = C.green },
|
||||
},
|
||||
|
||||
command = {
|
||||
a = { bg = C.peach, fg = C.base, gui = "bold" },
|
||||
b = { bg = C.surface0, fg = C.peach },
|
||||
},
|
||||
visual = {
|
||||
a = { bg = C.mauve, fg = C.base, gui = "bold" },
|
||||
b = { bg = C.surface0, fg = C.mauve },
|
||||
},
|
||||
replace = {
|
||||
a = { bg = C.red, fg = C.base, gui = "bold" },
|
||||
b = { bg = C.surface0, fg = C.red },
|
||||
},
|
||||
inactive = {
|
||||
a = { bg = transparent_bg, fg = C.blue },
|
||||
b = { bg = transparent_bg, fg = C.surface1, gui = "bold" },
|
||||
c = { bg = transparent_bg, fg = C.overlay0 },
|
||||
},
|
||||
},
|
||||
```
|
||||
|
||||
<details> <summary>Special</summary>
|
||||
|
||||
To implement color overrides in the `integrations.lualine` spec:
|
||||
```lua
|
||||
-- In your catppuccin config (integrations):
|
||||
lualine = {
|
||||
-- lualine color overrides in the following hierarchy: Catppuccin Flavor -> Mode -> Lualine Section
|
||||
-- The Catppuccin flavor entry can be any Catpuccin flavor or "all" to apply to all flavors
|
||||
-- The flavor entry can be either a table or a function which consumes the current Catppuccin palette, just like custom_highlights and color_overrides
|
||||
all = function(colors)
|
||||
---@type CtpIntegrationLualineOverride
|
||||
return {
|
||||
-- Specifying a normal-mode status line override for section a's background and b's foreground to use lavender like the main Catppuccin theme
|
||||
normal = {
|
||||
a = { bg = colors.lavender, gui = "italic" },
|
||||
b = { fg = colors.lavender },
|
||||
}
|
||||
}
|
||||
end,
|
||||
-- A macchiato-specific override, which takes priority over 'all'. Also using the direct table syntax instead of function in case you do not rely on dynamic palette colors
|
||||
macchiato = {
|
||||
normal = {
|
||||
a = { bg = "#abcdef" },
|
||||
}
|
||||
},
|
||||
},
|
||||
-- And in your lualine config:
|
||||
require('lualine').setup {
|
||||
options = {
|
||||
-- lualine will integrate with catppuccin by name or automatically via `vim.g.colors_name` by setting this to "auto"
|
||||
theme = "catppuccin"
|
||||
-- ... the rest of your lualine config
|
||||
}
|
||||
|
||||
@ -662,11 +662,76 @@ For custom Lsp Kind Icon and Color
|
||||
}
|
||||
<
|
||||
|
||||
lualine.nvimSpecial ~
|
||||
lualine.nvim>lua
|
||||
-- transparent_bg = opts.transparent_background and "NONE" or C.mantle
|
||||
lualine = {
|
||||
normal = {
|
||||
a = { bg = C.blue, fg = C.mantle, gui = "bold" },
|
||||
b = { bg = C.surface0, fg = C.blue },
|
||||
c = { bg = transparent_bg, fg = C.text },
|
||||
},
|
||||
|
||||
insert = {
|
||||
a = { bg = C.green, fg = C.base, gui = "bold" },
|
||||
b = { bg = C.surface0, fg = C.green },
|
||||
},
|
||||
|
||||
terminal = {
|
||||
a = { bg = C.green, fg = C.base, gui = "bold" },
|
||||
b = { bg = C.surface0, fg = C.green },
|
||||
},
|
||||
|
||||
command = {
|
||||
a = { bg = C.peach, fg = C.base, gui = "bold" },
|
||||
b = { bg = C.surface0, fg = C.peach },
|
||||
},
|
||||
visual = {
|
||||
a = { bg = C.mauve, fg = C.base, gui = "bold" },
|
||||
b = { bg = C.surface0, fg = C.mauve },
|
||||
},
|
||||
replace = {
|
||||
a = { bg = C.red, fg = C.base, gui = "bold" },
|
||||
b = { bg = C.surface0, fg = C.red },
|
||||
},
|
||||
inactive = {
|
||||
a = { bg = transparent_bg, fg = C.blue },
|
||||
b = { bg = transparent_bg, fg = C.surface1, gui = "bold" },
|
||||
c = { bg = transparent_bg, fg = C.overlay0 },
|
||||
},
|
||||
},
|
||||
<
|
||||
|
||||
Special ~
|
||||
|
||||
To implement color overrides in the `integrations.lualine` spec:
|
||||
|
||||
>lua
|
||||
-- In your catppuccin config (integrations):
|
||||
lualine = {
|
||||
-- lualine color overrides in the following hierarchy: Catppuccin Flavor -> Mode -> Lualine Section
|
||||
-- The Catppuccin flavor entry can be any Catpuccin flavor or "all" to apply to all flavors
|
||||
-- The flavor entry can be either a table or a function which consumes the current Catppuccin palette, just like custom_highlights and color_overrides
|
||||
all = function(colors)
|
||||
---@type CtpIntegrationLualineOverride
|
||||
return {
|
||||
-- Specifying a normal-mode status line override for section a's background and b's foreground to use lavender like the main Catppuccin theme
|
||||
normal = {
|
||||
a = { bg = colors.lavender, gui = "italic" },
|
||||
b = { fg = colors.lavender },
|
||||
}
|
||||
}
|
||||
end,
|
||||
-- A macchiato-specific override, which takes priority over 'all'. Also using the direct table syntax instead of function in case you do not rely on dynamic palette colors
|
||||
macchiato = {
|
||||
normal = {
|
||||
a = { bg = "#abcdef" },
|
||||
}
|
||||
},
|
||||
},
|
||||
-- And in your lualine config:
|
||||
require('lualine').setup {
|
||||
options = {
|
||||
-- lualine will integrate with catppuccin by name or automatically via `vim.g.colors_name` by setting this to "auto"
|
||||
theme = "catppuccin"
|
||||
-- ... the rest of your lualine config
|
||||
}
|
||||
|
||||
@ -197,6 +197,7 @@
|
||||
-- ```
|
||||
---@field lsp_saga boolean?
|
||||
---@field lsp_trouble boolean?
|
||||
---@field lualine CtpIntegrationLualine?
|
||||
---@field markview boolean?
|
||||
---@field mason boolean?
|
||||
-- You **NEED** to enable highlight in your `nvim-navic` config or it won't work:
|
||||
@ -291,6 +292,19 @@
|
||||
-- Sets the color of the scope line
|
||||
---@field indentscope_color CtpColor?
|
||||
|
||||
---@alias CtpIntegrationLualine CtpFlavors<CtpIntegrationLualineOverride | CtpIntegrationLualineOverrideFn>
|
||||
---@alias CtpIntegrationLualineOverride CtpIntegrationLualineModes<CtpIntegrationLualineSectionOverrides>
|
||||
---@alias CtpIntegrationLualineOverrideFn fun(colors: CtpColors<string>): CtpIntegrationLualineOverride
|
||||
---@alias CtpIntegrationLualineMode "normal" | "insert" | "visual" | "replace" | "command" | "terminal" | "inactive"
|
||||
---@class CtpIntegrationLualineModes<T>: { all: T, normal: T, insert: T, visual: T, replace: T, command: T, terminal: T, inactive: T }
|
||||
---@alias CtpIntegrationLualineSectionOverrides CtpIntegrationLualineSections<CtpIntegrationLualineSectionOverride>
|
||||
---@alias CtpIntegrationLualineSection "a" | "b" | "c"
|
||||
---@class CtpIntegrationLualineSections<T>: { a: T, b: T, c: T }
|
||||
---@class CtpIntegrationLualineSectionOverride
|
||||
---@field fg string?
|
||||
---@field bg string?
|
||||
---@field gui string? `gui` argument such as "italic,bold", see |highlight-gui|
|
||||
|
||||
---@class CtpIntegrationNavic
|
||||
-- Whether to enable the navic integration.
|
||||
---@field enabled boolean
|
||||
|
||||
@ -1,46 +1,60 @@
|
||||
---@param colors_override (CtpIntegrationLualineOverride | CtpIntegrationLualineOverrideFn)?
|
||||
---@param colors CtpColors<string>
|
||||
local function get_colors(colors_override, colors)
|
||||
if colors_override == nil then
|
||||
return {}
|
||||
elseif type(colors_override) == "function" then
|
||||
return colors_override(colors)
|
||||
else
|
||||
return colors_override
|
||||
end
|
||||
end
|
||||
return function(flavour)
|
||||
flavour = flavour or require("catppuccin").flavour or vim.g.catppuccin_flavour or "mocha"
|
||||
local C = require("catppuccin.palettes").get_palette(flavour)
|
||||
local O = require("catppuccin").options
|
||||
local catppuccin = {}
|
||||
|
||||
local transparent_bg = O.transparent_background and "NONE" or C.mantle
|
||||
local default_colors = {
|
||||
normal = {
|
||||
a = { bg = C.blue, fg = C.mantle, gui = "bold" },
|
||||
b = { bg = C.surface0, fg = C.blue },
|
||||
c = { bg = transparent_bg, fg = C.text },
|
||||
},
|
||||
|
||||
catppuccin.normal = {
|
||||
a = { bg = C.blue, fg = C.mantle, gui = "bold" },
|
||||
b = { bg = C.surface0, fg = C.blue },
|
||||
c = { bg = transparent_bg, fg = C.text },
|
||||
insert = {
|
||||
a = { bg = C.green, fg = C.base, gui = "bold" },
|
||||
b = { bg = C.surface0, fg = C.green },
|
||||
},
|
||||
|
||||
terminal = {
|
||||
a = { bg = C.green, fg = C.base, gui = "bold" },
|
||||
b = { bg = C.surface0, fg = C.green },
|
||||
},
|
||||
|
||||
command = {
|
||||
a = { bg = C.peach, fg = C.base, gui = "bold" },
|
||||
b = { bg = C.surface0, fg = C.peach },
|
||||
},
|
||||
visual = {
|
||||
a = { bg = C.mauve, fg = C.base, gui = "bold" },
|
||||
b = { bg = C.surface0, fg = C.mauve },
|
||||
},
|
||||
replace = {
|
||||
a = { bg = C.red, fg = C.base, gui = "bold" },
|
||||
b = { bg = C.surface0, fg = C.red },
|
||||
},
|
||||
inactive = {
|
||||
a = { bg = transparent_bg, fg = C.blue },
|
||||
b = { bg = transparent_bg, fg = C.surface1, gui = "bold" },
|
||||
c = { bg = transparent_bg, fg = C.overlay0 },
|
||||
},
|
||||
}
|
||||
|
||||
catppuccin.insert = {
|
||||
a = { bg = C.green, fg = C.base, gui = "bold" },
|
||||
b = { bg = C.surface0, fg = C.green },
|
||||
}
|
||||
|
||||
catppuccin.terminal = {
|
||||
a = { bg = C.green, fg = C.base, gui = "bold" },
|
||||
b = { bg = C.surface0, fg = C.green },
|
||||
}
|
||||
|
||||
catppuccin.command = {
|
||||
a = { bg = C.peach, fg = C.base, gui = "bold" },
|
||||
b = { bg = C.surface0, fg = C.peach },
|
||||
}
|
||||
|
||||
catppuccin.visual = {
|
||||
a = { bg = C.mauve, fg = C.base, gui = "bold" },
|
||||
b = { bg = C.surface0, fg = C.mauve },
|
||||
}
|
||||
|
||||
catppuccin.replace = {
|
||||
a = { bg = C.red, fg = C.base, gui = "bold" },
|
||||
b = { bg = C.surface0, fg = C.red },
|
||||
}
|
||||
|
||||
catppuccin.inactive = {
|
||||
a = { bg = transparent_bg, fg = C.blue },
|
||||
b = { bg = transparent_bg, fg = C.surface1, gui = "bold" },
|
||||
c = { bg = transparent_bg, fg = C.overlay0 },
|
||||
}
|
||||
|
||||
return catppuccin
|
||||
local overrides = O.integrations.lualine
|
||||
if overrides then
|
||||
local default_override = get_colors(overrides.all, C)
|
||||
local flavor_override = get_colors(overrides[flavour], C)
|
||||
return vim.tbl_deep_extend("force", default_colors, default_override, flavor_override)
|
||||
end
|
||||
return default_colors
|
||||
end
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user