(Experimental) Improve Sixel graphics support (#2544)

Progress:

* Sixel image can now be displayed with other text, and is scrollable
* If an image can't be displayed entirely due to the scroll offset, fzf
  will render a wireframe to indicate that an image should be displayed
* Renamed $FZF_PREVIEW_{WIDTH,HEIGHT} to $FZF_PREVIEW_PIXEL_{WIDTH,HEIGHT}
  for clarity
* Added bin/fzf-preview.sh script to demonstrate how to display an image
  using Kitty or Sixel protocol

An example:

  ls *.jpg | fzf --preview='seq $((FZF_PREVIEW_LINES*9/10)); fzf-preview.sh {}; seq 100'

A known issue:

* If you reduce the size of the preview window, the image may extend
  beyond the preview window
This commit is contained in:
Junegunn Choi
2023-10-26 00:22:28 +09:00
parent bac385b59c
commit d02b9442a5
10 changed files with 169 additions and 93 deletions

View File

@@ -3,27 +3,21 @@ CHANGELOG
0.43.1
------
- (Experimental) Added support for Sixel graphics in the preview window
```sh
# 1. $FZF_PREVIEW_WIDTH and $FZF_PREVIEW_HEIGHT will be set to the pixel width
# and height of the preview window
# 2. Special preview window flag 'clear' is added to always completely
# erase the preview window. This is similar to https://github.com/vifm/vifm/issues/588.
fzf --preview='
if file --mime-type {} | grep -qvF image/; then
bat --color=always {}
elif [[ -n $FZF_PREVIEW_WIDTH ]]; then
convert {} -resize ${FZF_PREVIEW_WIDTH}x${FZF_PREVIEW_HEIGHT} sixel:-
else
echo "Cannot display image data (unsupported platform)"
fi
' --preview-window clear
```
- (Experimental) Sixel image support in preview window (not available on Windows)
- `$FZF_PREVIEW_PIXEL_WIDTH` and `$FZF_PREVIEW_PIXEL_HEIGHT` are set to
the pixel width and height of the preview window
- [bin/fzf-preview.sh](bin/fzf-preview.sh) is added to demonstrate how to
display an image using Kitty image protocol or Sixel. You can use it
like so:
```sh
fzf --preview='fzf-preview.sh {}'
```
- Bug fixes
0.43.0
------
- (Experimental) Added support for Kitty image protocol in the preview window
(not available on Windows)
```sh
fzf --preview='
if file --mime-type {} | grep -qF image/; then