Skip to content

Commit

Permalink
feat(spec): support custom highlight blending
Browse files Browse the repository at this point in the history
Example:

```
{
	highlight_groups = {
		StatusLine = { bg = 'love', blend = 10 }
	}
}
```
  • Loading branch information
mvllow committed Jan 8, 2023
1 parent 36b7db5 commit bc40b69
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 10 deletions.
8 changes: 3 additions & 5 deletions lua/rose-pine/theme.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
local blend = require('rose-pine.util').blend

local M = {}

function M.get(config)
Expand Down Expand Up @@ -29,10 +27,10 @@ function M.get(config)
CursorLineNr = { fg = p.text },
DarkenedPanel = { bg = groups.panel },
DarkenedStatusline = { bg = groups.panel },
DiffAdd = { bg = blend(groups.git_add, groups.background, 0.2) },
DiffAdd = { bg = groups.git_add, blend = 20 },
DiffChange = { bg = p.overlay },
DiffDelete = { bg = blend(groups.git_delete, groups.background, 0.2) },
DiffText = { bg = blend(groups.git_text, groups.background, 0.2) },
DiffDelete = { bg = groups.git_delete, blend = 20 },
DiffText = { bg = groups.git_text, blend = 20 },
diffAdded = { link = 'DiffAdd' },
diffChanged = { link = 'DiffChange' },
diffRemoved = { link = 'DiffDelete' },
Expand Down
17 changes: 13 additions & 4 deletions lua/rose-pine/util.lua
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@ end
---@param bg string background color
---@param alpha number number between 0 (background) and 1 (foreground)
util.blend = function(fg, bg, alpha)
fg = rgb(parse_color(fg))
bg = rgb(parse_color(bg))
local fg_rgb = rgb(parse_color(fg))
local bg_rgb = rgb(parse_color(bg))

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

Expand All @@ -50,10 +50,19 @@ util.blend = function(fg, bg, alpha)
end

---@param group string
---@param color table<string, string>
---@param color table<string, any>
util.highlight = function(group, color)
local fg = color.fg and parse_color(color.fg) or 'none'
local bg = color.bg and parse_color(color.bg) or 'none'

if
color.blend ~= nil
and (color.blend >= 0 or color.blend <= 100)
and bg ~= nil
then
bg = util.blend(bg, parse_color('base') or '', color.blend / 100)
end

local sp = color.sp and parse_color(color.sp) or ''

color = vim.tbl_extend('force', color, { fg = fg, bg = bg, sp = sp })
Expand Down
6 changes: 5 additions & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,11 @@ require('rose-pine').setup({

-- Change specific vim highlight groups
highlight_groups = {
ColorColumn = { bg = 'rose' }
ColorColumn = { bg = 'rose' },

-- Blend colours against the "base" background
CursorLine = { bg = 'foam', blend = 10 },
StatusLine = { fg = 'love', bg = 'love', blend = 10 },
}
})

Expand Down

0 comments on commit bc40b69

Please sign in to comment.