Skip to content

Commit 93c760b

Browse files
committed
feat: support custom highlight blending
Example: ``` { highlight_groups = { StatusLine = { bg = 'love', blend = 10 } } } ```
1 parent eda49fd commit 93c760b

File tree

3 files changed

+20
-10
lines changed

3 files changed

+20
-10
lines changed

Diff for: lua/rose-pine/theme.lua

+3-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
local blend = require('rose-pine.util').blend
2-
31
local M = {}
42

53
function M.get(config)
@@ -29,10 +27,10 @@ function M.get(config)
2927
CursorLineNr = { fg = p.text },
3028
DarkenedPanel = { bg = groups.panel },
3129
DarkenedStatusline = { bg = groups.panel },
32-
DiffAdd = { bg = blend(groups.git_add, groups.background, 0.2) },
30+
DiffAdd = { bg = groups.git_add, blend = 20 },
3331
DiffChange = { bg = p.overlay },
34-
DiffDelete = { bg = blend(groups.git_delete, groups.background, 0.2) },
35-
DiffText = { bg = blend(groups.git_text, groups.background, 0.2) },
32+
DiffDelete = { bg = groups.git_delete, blend = 20 },
33+
DiffText = { bg = groups.git_text, blend = 20 },
3634
diffAdded = { link = 'DiffAdd' },
3735
diffChanged = { link = 'DiffChange' },
3836
diffRemoved = { link = 'DiffDelete' },

Diff for: lua/rose-pine/util.lua

+12-4
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,11 @@ end
3333
---@param bg string background color
3434
---@param alpha number number between 0 (background) and 1 (foreground)
3535
util.blend = function(fg, bg, alpha)
36-
fg = rgb(parse_color(fg))
37-
bg = rgb(parse_color(bg))
36+
local fg_rgb = rgb(parse_color(fg))
37+
local bg_rgb = rgb(parse_color(bg))
3838

3939
local function blend_channel(i)
40-
local ret = (alpha * fg[i] + ((1 - alpha) * bg[i]))
40+
local ret = (alpha * fg_rgb[i] + ((1 - alpha) * bg_rgb[i]))
4141
return math.floor(math.min(math.max(0, ret), 255) + 0.5)
4242
end
4343

@@ -50,12 +50,20 @@ util.blend = function(fg, bg, alpha)
5050
end
5151

5252
---@param group string
53-
---@param color table<string, string>
53+
---@param color table<string, any>
5454
util.highlight = function(group, color)
5555
local fg = color.fg and parse_color(color.fg) or 'none'
5656
local bg = color.bg and parse_color(color.bg) or 'none'
5757
local sp = color.sp and parse_color(color.sp) or ''
5858

59+
if
60+
color.blend ~= nil
61+
and (color.blend >= 0 or color.blend <= 100)
62+
and bg ~= nil
63+
then
64+
bg = util.blend(bg, parse_color('base') or '', color.blend / 100)
65+
end
66+
5967
color = vim.tbl_extend('force', color, { fg = fg, bg = bg, sp = sp })
6068
vim.api.nvim_set_hl(0, group, color)
6169
end

Diff for: readme.md

+5-1
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,11 @@ require('rose-pine').setup({
8585

8686
-- Change specific vim highlight groups
8787
highlight_groups = {
88-
ColorColumn = { bg = 'rose' }
88+
ColorColumn = { bg = 'rose' },
89+
90+
-- Blend colours against the "base" background
91+
CursorLine = { bg = 'foam', blend = 10 },
92+
StatusLine = { fg = 'love', bg = 'love', blend = 10 },
8993
}
9094
})
9195

0 commit comments

Comments
 (0)