mirror of
https://github.com/folke/snacks.nvim
synced 2025-08-04 10:49:08 +00:00
feat(snacks): zen mode
This commit is contained in:
parent
fc71e36c90
commit
c509ea52b7
3 changed files with 272 additions and 0 deletions
104
doc/snacks-zen.txt
Normal file
104
doc/snacks-zen.txt
Normal file
|
@ -0,0 +1,104 @@
|
|||
*snacks-zen.txt* snacks.nvim
|
||||
|
||||
==============================================================================
|
||||
Table of Contents *snacks-zen-table-of-contents*
|
||||
|
||||
1. Setup |snacks-zen-setup|
|
||||
2. Config |snacks-zen-config|
|
||||
3. Styles |snacks-zen-styles|
|
||||
- zen |snacks-zen-styles-zen|
|
||||
- zoom |snacks-zen-styles-zoom|
|
||||
4. Module |snacks-zen-module|
|
||||
- Snacks.zen.main() |snacks-zen-module-snacks.zen.main()|
|
||||
- Snacks.zen.zen() |snacks-zen-module-snacks.zen.zen()|
|
||||
- Snacks.zen.zoom() |snacks-zen-module-snacks.zen.zoom()|
|
||||
|
||||
==============================================================================
|
||||
1. Setup *snacks-zen-setup*
|
||||
|
||||
>lua
|
||||
-- lazy.nvim
|
||||
{
|
||||
"folke/snacks.nvim",
|
||||
opts = {
|
||||
zen = {
|
||||
-- your zen configuration comes here
|
||||
-- or leave it empty to use the default settings
|
||||
-- refer to the configuration section below
|
||||
}
|
||||
}
|
||||
}
|
||||
<
|
||||
|
||||
|
||||
==============================================================================
|
||||
2. Config *snacks-zen-config*
|
||||
|
||||
>lua
|
||||
---@class snacks.zen.Config
|
||||
{}
|
||||
<
|
||||
|
||||
|
||||
==============================================================================
|
||||
3. Styles *snacks-zen-styles*
|
||||
|
||||
|
||||
ZEN *snacks-zen-styles-zen*
|
||||
|
||||
>lua
|
||||
{
|
||||
enter = true,
|
||||
fixbuf = false,
|
||||
minimal = false,
|
||||
width = 120,
|
||||
height = 0,
|
||||
backdrop = { transparent = true, blend = 20 },
|
||||
keys = { q = false },
|
||||
wo = {
|
||||
winhighlight = "NormalFloat:Normal",
|
||||
},
|
||||
}
|
||||
<
|
||||
|
||||
|
||||
ZOOM *snacks-zen-styles-zoom*
|
||||
|
||||
>lua
|
||||
{
|
||||
style = "zen",
|
||||
backdrop = false,
|
||||
width = 0,
|
||||
}
|
||||
<
|
||||
|
||||
|
||||
==============================================================================
|
||||
4. Module *snacks-zen-module*
|
||||
|
||||
|
||||
`Snacks.zen.main()` *Snacks.zen.main()*
|
||||
|
||||
>lua
|
||||
Snacks.zen.main()
|
||||
<
|
||||
|
||||
|
||||
`Snacks.zen.zen()` *Snacks.zen.zen()*
|
||||
|
||||
>lua
|
||||
---@param opts? snacks.win.Config
|
||||
Snacks.zen.zen(opts)
|
||||
<
|
||||
|
||||
|
||||
`Snacks.zen.zoom()` *Snacks.zen.zoom()*
|
||||
|
||||
>lua
|
||||
---@param opts? snacks.win.Config
|
||||
Snacks.zen.zoom(opts)
|
||||
<
|
||||
|
||||
Generated by panvimdoc <https://github.com/kdheepak/panvimdoc>
|
||||
|
||||
vim:tw=78:ts=8:noet:ft=help:norl:
|
77
docs/zen.md
Normal file
77
docs/zen.md
Normal file
|
@ -0,0 +1,77 @@
|
|||
# 🍿 zen
|
||||
|
||||
<!-- docgen -->
|
||||
|
||||
## 📦 Setup
|
||||
|
||||
```lua
|
||||
-- lazy.nvim
|
||||
{
|
||||
"folke/snacks.nvim",
|
||||
opts = {
|
||||
zen = {
|
||||
-- your zen configuration comes here
|
||||
-- or leave it empty to use the default settings
|
||||
-- refer to the configuration section below
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## ⚙️ Config
|
||||
|
||||
```lua
|
||||
---@class snacks.zen.Config
|
||||
{}
|
||||
```
|
||||
|
||||
## 🎨 Styles
|
||||
|
||||
### `zen`
|
||||
|
||||
```lua
|
||||
{
|
||||
enter = true,
|
||||
fixbuf = false,
|
||||
minimal = false,
|
||||
width = 120,
|
||||
height = 0,
|
||||
backdrop = { transparent = true, blend = 20 },
|
||||
keys = { q = false },
|
||||
wo = {
|
||||
winhighlight = "NormalFloat:Normal",
|
||||
},
|
||||
}
|
||||
```
|
||||
|
||||
### `zoom`
|
||||
|
||||
```lua
|
||||
{
|
||||
style = "zen",
|
||||
backdrop = false,
|
||||
width = 0,
|
||||
}
|
||||
```
|
||||
|
||||
## 📦 Module
|
||||
|
||||
### `Snacks.zen.main()`
|
||||
|
||||
```lua
|
||||
Snacks.zen.main()
|
||||
```
|
||||
|
||||
### `Snacks.zen.zen()`
|
||||
|
||||
```lua
|
||||
---@param opts? snacks.win.Config
|
||||
Snacks.zen.zen(opts)
|
||||
```
|
||||
|
||||
### `Snacks.zen.zoom()`
|
||||
|
||||
```lua
|
||||
---@param opts? snacks.win.Config
|
||||
Snacks.zen.zoom(opts)
|
||||
```
|
91
lua/snacks/zen.lua
Normal file
91
lua/snacks/zen.lua
Normal file
|
@ -0,0 +1,91 @@
|
|||
---@class snacks.zen
|
||||
local M = {}
|
||||
|
||||
---@class snacks.zen.Config
|
||||
local defaults = {}
|
||||
|
||||
Snacks.config.style("zen", {
|
||||
enter = true,
|
||||
fixbuf = false,
|
||||
minimal = false,
|
||||
width = 120,
|
||||
height = 0,
|
||||
backdrop = { transparent = true, blend = 20 },
|
||||
keys = { q = false },
|
||||
wo = {
|
||||
winhighlight = "NormalFloat:Normal",
|
||||
},
|
||||
})
|
||||
|
||||
Snacks.config.style("zoom", {
|
||||
style = "zen",
|
||||
backdrop = false,
|
||||
width = 0,
|
||||
})
|
||||
|
||||
---@param opts? snacks.win.Config
|
||||
function M.zen(opts)
|
||||
-- close if already open
|
||||
if vim.w[vim.api.nvim_get_current_win()].snacks_zen then
|
||||
vim.cmd("close")
|
||||
return
|
||||
end
|
||||
|
||||
local parent_win = vim.api.nvim_get_current_win()
|
||||
local buf = vim.api.nvim_get_current_buf()
|
||||
local win = Snacks.win(Snacks.win.resolve({ style = "zen" }, opts, { buf = buf }))
|
||||
|
||||
vim.w[win.win].snacks_zen = true
|
||||
|
||||
-- update the buffer of the parent window
|
||||
-- when the zen buffer changes
|
||||
vim.api.nvim_create_autocmd("BufWinEnter", {
|
||||
group = win.augroup,
|
||||
callback = function()
|
||||
vim.api.nvim_win_set_buf(parent_win, win.buf)
|
||||
end,
|
||||
})
|
||||
|
||||
-- close when entering another window
|
||||
vim.api.nvim_create_autocmd("WinEnter", {
|
||||
group = win.augroup,
|
||||
callback = function()
|
||||
local w = vim.api.nvim_get_current_win()
|
||||
if w == win.win then
|
||||
return
|
||||
end
|
||||
-- exit if other window is not a floating window
|
||||
if vim.api.nvim_win_get_config(w).relative == "" then
|
||||
win:close()
|
||||
end
|
||||
end,
|
||||
})
|
||||
return win
|
||||
end
|
||||
|
||||
---@param opts? snacks.win.Config
|
||||
function M.zoom(opts)
|
||||
opts = Snacks.win.resolve({
|
||||
style = "zoom",
|
||||
col = M.main().col,
|
||||
height = function()
|
||||
return M.main().height
|
||||
end,
|
||||
}, opts)
|
||||
return M.zen(opts)
|
||||
end
|
||||
|
||||
function M.main()
|
||||
local bottom = vim.o.cmdheight + (vim.o.laststatus == 3 and 1 or 0)
|
||||
local top = (vim.o.showtabline == 2 or (vim.o.showtabline == 1 and #vim.api.nvim_list_tabpages() > 1)) and 1 or 0
|
||||
---@class snacks.zen.Main values are 0-indexed
|
||||
local ret = {
|
||||
col = 0,
|
||||
width = vim.o.columns,
|
||||
row = top,
|
||||
height = vim.o.lines - top - bottom,
|
||||
}
|
||||
return ret
|
||||
end
|
||||
|
||||
return M
|
Loading…
Add table
Add a link
Reference in a new issue