diff --git a/README.md b/README.md index 6e243652..dddda7a3 100644 --- a/README.md +++ b/README.md @@ -948,11 +948,75 @@ require("lspsaga").setup { 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 } diff --git a/doc/catppuccin.txt b/doc/catppuccin.txt index 979a80e9..289f469b 100644 --- a/doc/catppuccin.txt +++ b/doc/catppuccin.txt @@ -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 } diff --git a/lua/catppuccin/types.lua b/lua/catppuccin/types.lua index dec98a44..551f9535 100644 --- a/lua/catppuccin/types.lua +++ b/lua/catppuccin/types.lua @@ -195,6 +195,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: @@ -289,6 +290,19 @@ -- Sets the color of the scope line ---@field indentscope_color CtpColor? +---@alias CtpIntegrationLualine CtpFlavors +---@alias CtpIntegrationLualineOverride CtpIntegrationLualineModes +---@alias CtpIntegrationLualineOverrideFn fun(colors: CtpColors): CtpIntegrationLualineOverride +---@alias CtpIntegrationLualineMode "normal" | "insert" | "visual" | "replace" | "command" | "terminal" | "inactive" +---@class CtpIntegrationLualineModes: { all: T, normal: T, insert: T, visual: T, replace: T, command: T, terminal: T, inactive: T } +---@alias CtpIntegrationLualineSectionOverrides CtpIntegrationLualineSections +---@alias CtpIntegrationLualineSection "a" | "b" | "c" +---@class CtpIntegrationLualineSections: { 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 diff --git a/lua/catppuccin/utils/lualine.lua b/lua/catppuccin/utils/lualine.lua index 8f0b1f0b..a19802e3 100644 --- a/lua/catppuccin/utils/lualine.lua +++ b/lua/catppuccin/utils/lualine.lua @@ -1,46 +1,60 @@ +---@param colors_override (CtpIntegrationLualineOverride | CtpIntegrationLualineOverrideFn)? +---@param colors CtpColors +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 - - 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 }, - } - - 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 }, + 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 }, + }, + + 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.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