feat: added new image snacks plugin for the kitty graphics protocol

This commit is contained in:
Folke Lemaitre 2025-02-09 22:35:13 +01:00
parent a17788539a
commit 4e4e63048e
No known key found for this signature in database
GPG key ID: 41F8B1FBACAE2040
18 changed files with 704 additions and 12 deletions

115
docs/image.md Normal file
View file

@ -0,0 +1,115 @@
# 🍿 image
<!-- docgen -->
## 📦 Setup
```lua
-- lazy.nvim
{
"folke/snacks.nvim",
---@type snacks.Config
opts = {
image = {
-- your image configuration comes here
-- or leave it empty to use the default settings
-- refer to the configuration section below
}
}
}
```
## ⚙️ Config
```lua
---@class snacks.image.Config
---@field file? string
{}
```
## 📚 Types
```lua
---@alias snacks.image.Dim {col: number, row: number, width: number, height: number}
```
## 📦 Module
```lua
---@class snacks.Image
---@field id number
---@field buf number
---@field wins table<number, snacks.image.Dim>
---@field opts snacks.image.Config
---@field file string
---@field _convert uv.uv_process_t?
Snacks.image = {}
```
### `Snacks.image.new()`
```lua
---@param buf number
---@param opts? snacks.image.Config
Snacks.image.new(buf, opts)
```
### `Snacks.image.supports()`
```lua
---@param file string
Snacks.image.supports(file)
```
### `image:convert()`
```lua
image:convert()
```
### `image:create()`
```lua
image:create()
```
### `image:dim()`
```lua
---@param win number
---@return snacks.image.Dim
image:dim(win)
```
### `image:hide()`
```lua
---@param win? number
image:hide(win)
```
### `image:ready()`
```lua
image:ready()
```
### `image:render()`
```lua
---@param win number
image:render(win)
```
### `image:request()`
```lua
---@param opts table<string, string|number>|{data?: string}
image:request(opts)
```
### `image:update()`
```lua
image:update()
```

View file

@ -12,6 +12,7 @@
---@field dim? snacks.dim.Config
---@field explorer? snacks.explorer.Config
---@field gitbrowse? snacks.gitbrowse.Config
---@field image? snacks.image.Config
---@field indent? snacks.indent.Config
---@field input? snacks.input.Config
---@field layout? snacks.layout.Config
@ -55,6 +56,7 @@
---@field git snacks.git
---@field gitbrowse snacks.gitbrowse
---@field health snacks.health
---@field image snacks.image
---@field indent snacks.indent
---@field input snacks.input
---@field layout snacks.layout

View file

@ -37,6 +37,16 @@ Snacks.util.bo(buf, bo)
Snacks.util.color(group, prop)
```
### `Snacks.util.debounce()`
```lua
---@generic T
---@param fn T
---@param opts? {ms?:number}
---@return T
Snacks.util.debounce(fn, opts)
```
### `Snacks.util.file_decode()`
Decodes a file name to a string.