Skip to content

Commit a6b74f3

Browse files
committed
feat(ui): backdrop for the lazy floating window. Can be disabled with opts.ui.backdrop
1 parent 08954f7 commit a6b74f3

File tree

3 files changed

+106
-59
lines changed

3 files changed

+106
-59
lines changed

Diff for: README.md

+60-57
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ You can add the following Lua code to your `init.lua` to bootstrap **lazy.nvim**
3838

3939
```lua
4040
local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim"
41-
if not vim.loop.fs_stat(lazypath) then
41+
if not vim.uv.fs_stat(lazypath) then
4242
vim.fn.system({
4343
"git",
4444
"clone",
@@ -308,11 +308,12 @@ return {
308308
-- leave nil when passing the spec as the first argument to setup()
309309
spec = nil, ---@type LazySpec
310310
lockfile = vim.fn.stdpath("config") .. "/lazy-lock.json", -- lockfile generated after running update.
311-
concurrency = jit.os:find("Windows") and (vim.loop.available_parallelism() * 2) or nil, ---@type number limit the maximum amount of concurrent tasks
311+
---@type number? limit the maximum amount of concurrent tasks
312+
concurrency = jit.os:find("Windows") and (vim.uv.available_parallelism() * 2) or nil,
312313
git = {
313314
-- defaults for the `Lazy log` command
314-
-- log = { "-10" }, -- show the last 10 commits
315-
log = { "-8" }, -- show commits from the last 3 days
315+
-- log = { "--since=3 days ago" }, -- show commits from the last 3 days
316+
log = { "-8" }, -- show the last 8 commits
316317
timeout = 120, -- kill processes that take more than 2 minutes
317318
url_format = "https://github.com/%s.git",
318319
-- lazy.nvim requires git >=2.19.0. If you really want to use lazy with an older version,
@@ -339,14 +340,16 @@ return {
339340
wrap = true, -- wrap the lines in the ui
340341
-- The border to use for the UI window. Accepts same border values as |nvim_open_win()|.
341342
border = "none",
343+
-- The backdrop opacity. 0 is fully opaque, 100 is fully transparent.
344+
backdrop = 60,
342345
title = nil, ---@type string only works when border is not "none"
343346
title_pos = "center", ---@type "center" | "left" | "right"
344347
-- Show pills on top of the Lazy window
345348
pills = true, ---@type boolean
346349
icons = {
347350
cmd = "",
348351
config = "",
349-
event = "",
352+
event = " ",
350353
ft = "",
351354
init = "",
352355
import = "",
@@ -358,7 +361,7 @@ return {
358361
runtime = "",
359362
require = "󰢱 ",
360363
source = "",
361-
start = "",
364+
start = " ",
362365
task = "",
363366
list = {
364367
"",
@@ -513,24 +516,24 @@ Any operation can be started from the UI, with a sub command or an API function:
513516

514517
<!-- commands:start -->
515518

516-
| Command | Lua | Description |
517-
| ------------------------- | -------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------- |
518-
| `:Lazy build {plugins}` | `require("lazy").build(opts)` | Rebuild a plugin |
519-
| `:Lazy check [plugins]` | `require("lazy").check(opts?)` | Check for updates and show the log (git fetch) |
520-
| `:Lazy clean [plugins]` | `require("lazy").clean(opts?)` | Clean plugins that are no longer needed |
521-
| `:Lazy clear` | `require("lazy").clear()` | Clear finished tasks |
522-
| `:Lazy debug` | `require("lazy").debug()` | Show debug information |
523-
| `:Lazy health` | `require("lazy").health()` | Run `:checkhealth lazy` |
524-
| `:Lazy help` | `require("lazy").help()` | Toggle this help page |
525-
| `:Lazy home` | `require("lazy").home()` | Go back to plugin list |
526-
| `:Lazy install [plugins]` | `require("lazy").install(opts?)` | Install missing plugins |
527-
| `:Lazy load {plugins}` | `require("lazy").load(opts)` | Load a plugin that has not been loaded yet. Similar to `:packadd`. Like `:Lazy load foo.nvim`. Use `:Lazy! load` to skip `cond` checks. |
528-
| `:Lazy log [plugins]` | `require("lazy").log(opts?)` | Show recent updates |
529-
| `:Lazy profile` | `require("lazy").profile()` | Show detailed profiling |
530-
| `:Lazy reload {plugins}` | `require("lazy").reload(opts)` | Reload a plugin (experimental!!) |
519+
| Command | Lua | Description |
520+
| --- | --- | --- | --- |
521+
| `:Lazy build {plugins}` | `require("lazy").build(opts)` | Rebuild a plugin |
522+
| `:Lazy check [plugins]` | `require("lazy").check(opts?)` | Check for updates and show the log (git fetch) |
523+
| `:Lazy clean [plugins]` | `require("lazy").clean(opts?)` | Clean plugins that are no longer needed |
524+
| `:Lazy clear` | `require("lazy").clear()` | Clear finished tasks |
525+
| `:Lazy debug` | `require("lazy").debug()` | Show debug information |
526+
| `:Lazy health` | `require("lazy").health()` | Run `:checkhealth lazy` |
527+
| `:Lazy help` | `require("lazy").help()` | Toggle this help page |
528+
| `:Lazy home` | `require("lazy").home()` | Go back to plugin list |
529+
| `:Lazy install [plugins]` | `require("lazy").install(opts?)` | Install missing plugins |
530+
| `:Lazy load {plugins}` | `require("lazy").load(opts)` | Load a plugin that has not been loaded yet. Similar to `:packadd`. Like `:Lazy load foo.nvim`. Use `:Lazy! load` to skip `cond` checks. |
531+
| `:Lazy log [plugins]` | `require("lazy").log(opts?)` | Show recent updates |
532+
| `:Lazy profile` | `require("lazy").profile()` | Show detailed profiling |
533+
| `:Lazy reload {plugins}` | `require("lazy").reload(opts)` | Reload a plugin (experimental!!) |
531534
| `:Lazy restore [plugins]` | `require("lazy").restore(opts?)` | Updates all plugins to the state in the lockfile. For a single plugin: restore it to the state in the lockfile or to a given commit under the cursor |
532-
| `:Lazy sync [plugins]` | `require("lazy").sync(opts?)` | Run install, clean and update |
533-
| `:Lazy update [plugins]` | `require("lazy").update(opts?)` | Update plugins. This will also update the lockfile |
535+
| `:Lazy sync [plugins]` | `require("lazy").sync(opts?)` | Run install, clean and update |
536+
| `:Lazy update [plugins]` | `require("lazy").update(opts?)` | Update plugins. This will also update the lockfile |
534537

535538
<!-- commands:end -->
536539

@@ -781,40 +784,40 @@ To uninstall **lazy.nvim**, you need to remove the following files and directori
781784

782785
<!-- colors:start -->
783786

784-
| Highlight Group | Default Group | Description |
785-
| --------------------- | -------------------------- | --------------------------------------------------- |
786-
| **LazyButton** | **_CursorLine_** | |
787-
| **LazyButtonActive** | **_Visual_** | |
788-
| **LazyComment** | **_Comment_** | |
789-
| **LazyCommit** | **_@variable.builtin_** | commit ref |
790-
| **LazyCommitIssue** | **_Number_** | |
791-
| **LazyCommitScope** | **_Italic_** | conventional commit scope |
792-
| **LazyCommitType** | **_Title_** | conventional commit type |
793-
| **LazyDimmed** | **_Conceal_** | property |
794-
| **LazyDir** | **_@markup.link_** | directory |
795-
| **LazyH1** | **_IncSearch_** | home button |
796-
| **LazyH2** | **_Bold_** | titles |
797-
| **LazyLocal** | **_Constant_** | |
798-
| **LazyNoCond** | **_DiagnosticWarn_** | unloaded icon for a plugin where `cond()` was false |
799-
| **LazyNormal** | **_NormalFloat_** | |
800-
| **LazyProgressDone** | **_Constant_** | progress bar done |
801-
| **LazyProgressTodo** | **_LineNr_** | progress bar todo |
802-
| **LazyProp** | **_Conceal_** | property |
803-
| **LazyReasonCmd** | **_Operator_** | |
804-
| **LazyReasonEvent** | **_Constant_** | |
805-
| **LazyReasonFt** | **_Character_** | |
806-
| **LazyReasonImport** | **_Identifier_** | |
807-
| **LazyReasonKeys** | **_Statement_** | |
808-
| **LazyReasonPlugin** | **_Special_** | |
809-
| **LazyReasonRequire** | **_@variable.parameter_** | |
810-
| **LazyReasonRuntime** | **_@macro_** | |
811-
| **LazyReasonSource** | **_Character_** | |
812-
| **LazyReasonStart** | **_@variable.member_** | |
813-
| **LazySpecial** | **_@punctuation.special_** | |
814-
| **LazyTaskError** | **_ErrorMsg_** | task errors |
815-
| **LazyTaskOutput** | **_MsgArea_** | task output |
816-
| **LazyUrl** | **_@markup.link_** | url |
817-
| **LazyValue** | **_@string_** | value of a property |
787+
| Highlight Group | Default Group | Description |
788+
| --- | --- | --- |
789+
| **LazyButton** | ***CursorLine*** | |
790+
| **LazyButtonActive** | ***Visual*** | |
791+
| **LazyComment** | ***Comment*** | |
792+
| **LazyCommit** | ***@variable.builtin*** | commit ref |
793+
| **LazyCommitIssue** | ***Number*** | |
794+
| **LazyCommitScope** | ***Italic*** | conventional commit scope |
795+
| **LazyCommitType** | ***Title*** | conventional commit type |
796+
| **LazyDimmed** | ***Conceal*** | property |
797+
| **LazyDir** | ***@markup.link*** | directory |
798+
| **LazyH1** | ***IncSearch*** | home button |
799+
| **LazyH2** | ***Bold*** | titles |
800+
| **LazyLocal** | ***Constant*** | |
801+
| **LazyNoCond** | ***DiagnosticWarn*** | unloaded icon for a plugin where `cond()` was false |
802+
| **LazyNormal** | ***NormalFloat*** | |
803+
| **LazyProgressDone** | ***Constant*** | progress bar done |
804+
| **LazyProgressTodo** | ***LineNr*** | progress bar todo |
805+
| **LazyProp** | ***Conceal*** | property |
806+
| **LazyReasonCmd** | ***Operator*** | |
807+
| **LazyReasonEvent** | ***Constant*** | |
808+
| **LazyReasonFt** | ***Character*** | |
809+
| **LazyReasonImport** | ***Identifier*** | |
810+
| **LazyReasonKeys** | ***Statement*** | |
811+
| **LazyReasonPlugin** | ***Special*** | |
812+
| **LazyReasonRequire** | ***@variable.parameter*** | |
813+
| **LazyReasonRuntime** | ***@macro*** | |
814+
| **LazyReasonSource** | ***Character*** | |
815+
| **LazyReasonStart** | ***@variable.member*** | |
816+
| **LazySpecial** | ***@punctuation.special*** | |
817+
| **LazyTaskError** | ***ErrorMsg*** | task errors |
818+
| **LazyTaskOutput** | ***MsgArea*** | task output |
819+
| **LazyUrl** | ***@markup.link*** | url |
820+
| **LazyValue** | ***@string*** | value of a property |
818821

819822
<!-- colors:end -->
820823

Diff for: lua/lazy/core/config.lua

+4-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ M.defaults = {
1717
-- leave nil when passing the spec as the first argument to setup()
1818
spec = nil, ---@type LazySpec
1919
lockfile = vim.fn.stdpath("config") .. "/lazy-lock.json", -- lockfile generated after running update.
20-
concurrency = jit.os:find("Windows") and (vim.uv.available_parallelism() * 2) or nil, ---@type number limit the maximum amount of concurrent tasks
20+
---@type number? limit the maximum amount of concurrent tasks
21+
concurrency = jit.os:find("Windows") and (vim.uv.available_parallelism() * 2) or nil,
2122
git = {
2223
-- defaults for the `Lazy log` command
2324
-- log = { "--since=3 days ago" }, -- show commits from the last 3 days
@@ -48,6 +49,8 @@ M.defaults = {
4849
wrap = true, -- wrap the lines in the ui
4950
-- The border to use for the UI window. Accepts same border values as |nvim_open_win()|.
5051
border = "none",
52+
-- The backdrop opacity. 0 is fully opaque, 100 is fully transparent.
53+
backdrop = 60,
5154
title = nil, ---@type string only works when border is not "none"
5255
title_pos = "center", ---@type "center" | "left" | "right"
5356
-- Show pills on top of the Lazy window

Diff for: lua/lazy/view/float.lua

+42-1
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,15 @@ local ViewConfig = require("lazy.view.config")
1515
---@field persistent? boolean
1616
---@field ft? string
1717
---@field noautocmd? boolean
18+
---@field backdrop? float
1819

1920
---@class LazyFloat
2021
---@field buf number
2122
---@field win number
2223
---@field opts LazyFloatOptions
2324
---@field win_opts LazyWinOpts
25+
---@field backdrop_buf number
26+
---@field backdrop_win number
2427
---@overload fun(opts?:LazyFloatOptions):LazyFloat
2528
local M = {}
2629

@@ -43,6 +46,7 @@ function M:init(opts)
4346
size = Config.options.ui.size,
4447
style = "minimal",
4548
border = Config.options.ui.border or "none",
49+
backdrop = Config.options.ui.backdrop or 60,
4650
zindex = 50,
4751
}, opts or {})
4852

@@ -62,7 +66,7 @@ function M:init(opts)
6266
}
6367
self:mount()
6468
self:on_key(ViewConfig.keys.close, self.close)
65-
self:on({ "BufDelete", "BufHidden" }, self.close, { once = true })
69+
self:on({ "BufDelete", "BufHidden" }, self.close, { once = false })
6670
return self
6771
end
6872

@@ -114,6 +118,24 @@ function M:mount()
114118
self.buf = vim.api.nvim_create_buf(false, true)
115119
end
116120

121+
if self.opts.backdrop and self.opts.backdrop < 100 then
122+
self.backdrop_buf = vim.api.nvim_create_buf(false, true)
123+
self.backdrop_win = vim.api.nvim_open_win(self.backdrop_buf, false, {
124+
relative = "editor",
125+
width = vim.o.columns,
126+
height = vim.o.lines,
127+
row = 0,
128+
col = 0,
129+
style = "minimal",
130+
focusable = false,
131+
zindex = self.opts.zindex - 1,
132+
})
133+
vim.api.nvim_set_hl(0, "LazyBackdrop", { bg = "#000000", default = true })
134+
Util.wo(self.backdrop_win, "winhighlight", "Normal:LazyBackdrop")
135+
Util.wo(self.backdrop_win, "winblend", self.opts.backdrop)
136+
vim.bo[self.backdrop_buf].buftype = "nofile"
137+
end
138+
117139
self:layout()
118140
self.win = vim.api.nvim_open_win(self.buf, true, self.win_opts)
119141
self:focus()
@@ -149,6 +171,14 @@ function M:mount()
149171
end
150172
config.style = self.opts.style ~= "" and self.opts.style or nil
151173
vim.api.nvim_win_set_config(self.win, config)
174+
175+
if self.backdrop_win and vim.api.nvim_win_is_valid(self.backdrop_win) then
176+
vim.api.nvim_win_set_config(self.backdrop_win, {
177+
width = vim.o.columns,
178+
height = vim.o.lines,
179+
})
180+
end
181+
152182
opts()
153183
vim.api.nvim_exec_autocmds("User", { pattern = "LazyFloatResized", modeline = false })
154184
end,
@@ -204,7 +234,18 @@ function M:close(opts)
204234
if wipe then
205235
self.buf = nil
206236
end
237+
local backdrop_buf = self.backdrop_buf
238+
local backdrop_win = self.backdrop_win
239+
self.backdrop_buf = nil
240+
self.backdrop_win = nil
241+
207242
vim.schedule(function()
243+
if backdrop_win and vim.api.nvim_win_is_valid(backdrop_win) then
244+
vim.api.nvim_win_close(backdrop_win, true)
245+
end
246+
if backdrop_buf and vim.api.nvim_buf_is_valid(backdrop_buf) then
247+
vim.api.nvim_buf_delete(backdrop_buf, { force = true })
248+
end
208249
if win and vim.api.nvim_win_is_valid(win) then
209250
vim.api.nvim_win_close(win, true)
210251
end

0 commit comments

Comments
 (0)