Skip to content

Commit 87c80e3

Browse files
committed
feat: add blend
1 parent 4d57f3a commit 87c80e3

File tree

2 files changed

+56
-7
lines changed

2 files changed

+56
-7
lines changed

lua/colorbuddy/group.lua

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ Group.is_existing_group = function(key)
187187
return _group_hash[string.lower(key)] ~= nil
188188
end
189189

190-
Group.__private_create = function(name, fg, bg, style, guisp, default, bang)
190+
Group.__private_create = function(name, fg, bg, style, guisp, blend, default, bang)
191191
name = string.lower(name)
192192

193193
local handler = {}
@@ -229,6 +229,7 @@ Group.__private_create = function(name, fg, bg, style, guisp, default, bang)
229229
obj.bg = bg_color
230230
obj.style = style_style
231231
obj.guisp = guisp_color
232+
obj.blend = blend
232233

233234
obj:update()
234235
else
@@ -245,6 +246,7 @@ Group.__private_create = function(name, fg, bg, style, guisp, default, bang)
245246
bg = bg_color,
246247
style = style_style,
247248
guisp = guisp_color,
249+
blend = blend,
248250

249251
children = {
250252
fg = {},
@@ -289,12 +291,12 @@ Group.__private_create = function(name, fg, bg, style, guisp, default, bang)
289291
return obj
290292
end
291293

292-
Group.default = function(name, fg, bg, style, guisp, bang)
293-
return Group.__private_create(name, fg, bg, style, guisp, true, bang)
294+
Group.default = function(name, fg, bg, style, guisp, blend, bang)
295+
return Group.__private_create(name, fg, bg, style, guisp, blend, true, bang)
294296
end
295297

296-
Group.new = function(name, fg, bg, style, guisp)
297-
return Group.__private_create(name, fg, bg, style, guisp, false, false)
298+
Group.new = function(name, fg, bg, style, guisp, blend)
299+
return Group.__private_create(name, fg, bg, style, guisp, blend, false, false)
298300
end
299301

300302
Group.link = function(name, linked_group)
@@ -321,14 +323,15 @@ function Group:apply()
321323
Example: >
322324
:hi comment guifg='salmon pink'
323325
--]]
326+
324327
-- Only clear old highlighting if we're not the default
325328
if self.__default__ == false then
326329
-- Clear the current highlighting
327330
vim.api.nvim_command(string.format("highlight %s NONE", self.name))
328331
end
329332

330333
-- Apply the new highlighting
331-
vim.api.nvim_command(string.format(
334+
local command = string.format(
332335
"highlight%s %s %s guifg=%s guibg=%s gui=%s guisp=%s",
333336
execute.fif(self.__bang__, "!", ""),
334337
execute.fif(self.__default__, "default", ""),
@@ -337,7 +340,13 @@ function Group:apply()
337340
self.bg:to_rgb(),
338341
self.style:to_nvim(),
339342
self.guisp:to_rgb()
340-
))
343+
)
344+
345+
if self.blend then
346+
command = command .. string.format(" blend=%s", self.blend)
347+
end
348+
349+
vim.api.nvim_command(command)
341350
end
342351

343352
Group.update = function(self, updated)

scratch/test_blend.lua

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
local ui = vim.api.nvim_list_uis()[1]
2+
3+
local bufnr = vim.api.nvim_create_buf(false, true)
4+
local win = vim.api.nvim_open_win(bufnr, true, {
5+
relative = "editor",
6+
width = ui.width,
7+
height = ui.height,
8+
row = 10,
9+
col = 10,
10+
style = "minimal",
11+
})
12+
13+
vim.api.nvim_win_set_option(win, "winblend", 1)
14+
15+
local blend_start = 15
16+
local offset = 1
17+
18+
CANCEL = false
19+
local timer = vim.loop.new_timer()
20+
timer:start(
21+
0,
22+
50,
23+
vim.schedule_wrap(function()
24+
blend_start = blend_start + offset
25+
26+
if blend_start > 90 then
27+
offset = -1
28+
elseif blend_start < 10 then
29+
offset = 1
30+
end
31+
32+
if CANCEL or not vim.api.nvim_win_is_valid(win) then
33+
timer:close()
34+
timer:stop()
35+
return
36+
end
37+
38+
vim.cmd([[highlight NormalFloat blend=]] .. tostring(blend_start))
39+
end)
40+
)

0 commit comments

Comments
 (0)