mirror of
https://github.com/rose-pine/neovim.git
synced 2025-10-15 12:38:53 +02:00
feat: add new treesitter highlights (#217)
* feat: add WinBar and WinBarNC * feat: add new treesitter highlight groups * perf: parse necessary values upfront This commit no longer parses each highlight group, but rather user config values only. * fix: titles are no longer dynamically coloured Closes #216 #218 #219
This commit is contained in:
parent
2a4aad89a8
commit
bf00df18af
4 changed files with 292 additions and 157 deletions
|
|
@ -1,7 +1,7 @@
|
|||
---@alias Variant "main" | "moon" | "dawn"
|
||||
---@alias Palette { base: string, surface: string, overlay: string, muted: string, subtle: string, text: string, love: string, gold: string, rose: string, pine: string, foam: string, iris: string }
|
||||
---@alias PaletteColor "base" | "surface" | "overlay" | "muted" | "subtle" | "text" | "love" | "gold" | "rose" | "pine" | "foam" | "iris" | "highlight_low" | "highlight_med" | "highlight_high"
|
||||
---@alias Highlight { fg: string, bg: string, sp: string, bold: boolean, italic: boolean, undercurl: boolean, underline: boolean, underdouble: boolean, underdotted: boolean, underdashed: boolean, strikethrough: boolean }
|
||||
---@alias Highlight { fg: string, bg: string, sp: string, bold: boolean, italic: boolean, undercurl: boolean, underline: boolean, underdouble: boolean, underdotted: boolean, underdashed: boolean, strikethrough: boolean, inherit: boolean }
|
||||
|
||||
local config = {}
|
||||
|
||||
|
|
@ -24,8 +24,9 @@ config.options = {
|
|||
extend_background_behind_borders = true,
|
||||
|
||||
enable = {
|
||||
terminal = true,
|
||||
legacy_highlights = true,
|
||||
migrations = true,
|
||||
terminal = true,
|
||||
},
|
||||
|
||||
styles = {
|
||||
|
|
@ -43,6 +44,8 @@ config.options = {
|
|||
error = "love",
|
||||
hint = "iris",
|
||||
info = "foam",
|
||||
note = "pine",
|
||||
todo = "rose",
|
||||
warn = "gold",
|
||||
|
||||
git_add = "foam",
|
||||
|
|
@ -56,15 +59,13 @@ config.options = {
|
|||
git_text = "rose",
|
||||
git_untracked = "subtle",
|
||||
|
||||
---@type string | PaletteColor | table<string, string | PaletteColor>
|
||||
headings = {
|
||||
h1 = "iris",
|
||||
h2 = "foam",
|
||||
h3 = "rose",
|
||||
h4 = "gold",
|
||||
h5 = "pine",
|
||||
h6 = "foam",
|
||||
},
|
||||
---@type string | PaletteColor
|
||||
h1 = "iris",
|
||||
h2 = "foam",
|
||||
h3 = "rose",
|
||||
h4 = "gold",
|
||||
h5 = "pine",
|
||||
h6 = "foam",
|
||||
|
||||
---@deprecated Replaced by `options.highlight_groups["Normal"]`
|
||||
-- background = "base",
|
||||
|
|
@ -72,6 +73,8 @@ config.options = {
|
|||
-- comment = "subtle",
|
||||
---@deprecated Replaced by `options.highlight_groups["@punctuation"]`
|
||||
-- punctuation = "muted",
|
||||
---@deprecated Expects a table with values h1...h6
|
||||
-- headings = "text",
|
||||
},
|
||||
|
||||
---@type table<string, Highlight>
|
||||
|
|
@ -103,6 +106,10 @@ local function migrate(options)
|
|||
options.highlight_groups["WinSeparator"] = { fg = border, bg = border }
|
||||
end
|
||||
|
||||
if options.disable_background then
|
||||
options.highlight_groups["Normal"] = { bg = "NONE" }
|
||||
end
|
||||
|
||||
if options.disable_float_background then
|
||||
options.highlight_groups["NormalFloat"] = { bg = "NONE" }
|
||||
end
|
||||
|
|
@ -121,7 +128,8 @@ local function migrate(options)
|
|||
options.highlight_groups["@punctuation"] = { fg = options.groups.punctuation }
|
||||
end
|
||||
|
||||
options.styles.transparency = options.disable_background or options.styles.transparency
|
||||
options.styles.transparency = (options.disable_background and options.disable_float_background)
|
||||
or options.styles.transparency
|
||||
|
||||
-- These never actually existed, but may be set intuitively by the user
|
||||
-- because of `disable_italics` existing.
|
||||
|
|
@ -142,6 +150,14 @@ local function migrate(options)
|
|||
h6 = options.groups.headings,
|
||||
}
|
||||
end
|
||||
if type(options.groups.headings) == "table" then
|
||||
options.groups.h1 = options.groups.headings.h1 or options.groups.h1
|
||||
options.groups.h2 = options.groups.headings.h2 or options.groups.h2
|
||||
options.groups.h3 = options.groups.headings.h3 or options.groups.h3
|
||||
options.groups.h4 = options.groups.headings.h4 or options.groups.h4
|
||||
options.groups.h5 = options.groups.headings.h5 or options.groups.h5
|
||||
options.groups.h6 = options.groups.headings.h6 or options.groups.h6
|
||||
end
|
||||
|
||||
return options
|
||||
end
|
||||
|
|
|
|||
|
|
@ -15,9 +15,9 @@ local function color_to_rgb(color)
|
|||
end
|
||||
|
||||
---@param color string Palette key or hex value
|
||||
local function parse_color(color)
|
||||
function utilities.parse_color(color)
|
||||
if color == nil then
|
||||
return print("Invalid color")
|
||||
return print("Invalid color: " .. color)
|
||||
end
|
||||
|
||||
color = color:lower()
|
||||
|
|
@ -32,7 +32,7 @@ end
|
|||
---@param fg string Foreground color
|
||||
---@param bg string Background color
|
||||
---@param alpha number Between 0 (background) and 1 (foreground)
|
||||
local function blend(fg, bg, alpha)
|
||||
function utilities.blend(fg, bg, alpha)
|
||||
local fg_rgb = color_to_rgb(fg)
|
||||
local bg_rgb = color_to_rgb(bg)
|
||||
|
||||
|
|
@ -44,23 +44,4 @@ local function blend(fg, bg, alpha)
|
|||
return string.format("#%02X%02X%02X", blend_channel(1), blend_channel(2), blend_channel(3))
|
||||
end
|
||||
|
||||
---@param group string
|
||||
---@param highlight table<string, any>
|
||||
function utilities.highlight(group, highlight, blend_on)
|
||||
local fg = highlight.fg and parse_color(highlight.fg) or "NONE"
|
||||
local bg = highlight.bg and parse_color(highlight.bg) or "NONE"
|
||||
local sp = highlight.sp and parse_color(highlight.sp) or "NONE"
|
||||
|
||||
if highlight.blend ~= nil and (highlight.blend >= 0 and highlight.blend <= 100) and bg ~= nil then
|
||||
bg = blend(bg, blend_on or require("rose-pine.palette").base, highlight.blend / 100)
|
||||
end
|
||||
|
||||
highlight.fg = fg
|
||||
highlight.bg = bg
|
||||
highlight.sp = sp
|
||||
-- highlight = vim.tbl_extend("force", highlight, { fg = fg, bg = bg, sp = sp })
|
||||
|
||||
vim.api.nvim_set_hl(0, group, highlight)
|
||||
end
|
||||
|
||||
return utilities
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue