mirror of
https://github.com/junegunn/fzf.git
synced 2025-05-19 04:40:22 -07:00
sixel: Export $FZF_PREVIEW_TOP to the preview command (#2544)
So that it can determine if it should subtract 1 from $FZF_PREVIEW_LINES to avoid scrolling issue of Sixel image that touches the bottom of the screen.
This commit is contained in:
parent
a0145cebf2
commit
21ab64e962
@ -13,14 +13,14 @@ if [[ $# -ne 1 ]]; then
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
file=${1/#\~\//$HOME/}
|
file=${1/#\~\//$HOME/}
|
||||||
type=$(file --mime-type "$file")
|
type=$(file --dereference --mime -- "$file")
|
||||||
|
|
||||||
dim=${FZF_PREVIEW_COLUMNS}x${FZF_PREVIEW_LINES}
|
|
||||||
if [[ $dim = x ]]; then
|
|
||||||
dim=$(stty size | awk '{print $2 "x" $1}')
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [[ ! $type =~ image/ ]]; then
|
if [[ ! $type =~ image/ ]]; then
|
||||||
|
if [[ $type =~ =binary ]]; then
|
||||||
|
file "$1"
|
||||||
|
exit
|
||||||
|
fi
|
||||||
|
|
||||||
# Sometimes bat is installed as batcat.
|
# Sometimes bat is installed as batcat.
|
||||||
if command -v batcat > /dev/null; then
|
if command -v batcat > /dev/null; then
|
||||||
batname="batcat"
|
batname="batcat"
|
||||||
@ -32,7 +32,19 @@ if [[ ! $type =~ image/ ]]; then
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
${batname} --style="${BAT_STYLE:-numbers}" --color=always --pager=never -- "$file"
|
${batname} --style="${BAT_STYLE:-numbers}" --color=always --pager=never -- "$file"
|
||||||
elif [[ $KITTY_WINDOW_ID ]]; then
|
exit
|
||||||
|
fi
|
||||||
|
|
||||||
|
dim=${FZF_PREVIEW_COLUMNS}x${FZF_PREVIEW_LINES}
|
||||||
|
if [[ $dim = x ]]; then
|
||||||
|
dim=$(stty size < /dev/tty | awk '{print $2 "x" $1}')
|
||||||
|
elif ! [[ $KITTY_WINDOW_ID ]] && (( FZF_PREVIEW_TOP + FZF_PREVIEW_LINES == $(stty size < /dev/tty | awk '{print $1}') )); then
|
||||||
|
# Avoid scrolling issue when the Sixel image touches the bottom of the screen
|
||||||
|
# * https://github.com/junegunn/fzf/issues/2544
|
||||||
|
dim=${FZF_PREVIEW_COLUMNS}x$((FZF_PREVIEW_LINES - 1))
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ $KITTY_WINDOW_ID ]]; then
|
||||||
# 1. 'memory' is the fastest option but if you want the image to be scrollable,
|
# 1. 'memory' is the fastest option but if you want the image to be scrollable,
|
||||||
# you have to use 'stream'.
|
# you have to use 'stream'.
|
||||||
#
|
#
|
||||||
@ -42,6 +54,7 @@ elif [[ $KITTY_WINDOW_ID ]]; then
|
|||||||
kitty icat --clear --transfer-mode=memory --stdin=no --place="$dim@0x0" "$file" | sed '$d' | sed $'$s/$/\e[m/'
|
kitty icat --clear --transfer-mode=memory --stdin=no --place="$dim@0x0" "$file" | sed '$d' | sed $'$s/$/\e[m/'
|
||||||
elif command -v chafa > /dev/null; then
|
elif command -v chafa > /dev/null; then
|
||||||
chafa -f sixel -s "$dim" "$file"
|
chafa -f sixel -s "$dim" "$file"
|
||||||
|
# Add a new line character so that fzf can display multiple images in the preview window
|
||||||
echo
|
echo
|
||||||
else
|
else
|
||||||
file "$file"
|
file "$file"
|
||||||
|
@ -548,6 +548,9 @@ they represent the exact size of the preview window. (It also overrides
|
|||||||
by the default shell, so prefer to refer to the ones with \fBFZF_PREVIEW_\fR
|
by the default shell, so prefer to refer to the ones with \fBFZF_PREVIEW_\fR
|
||||||
prefix.)
|
prefix.)
|
||||||
|
|
||||||
|
fzf also exports \fB$FZF_PREVIEW_TOP\fR and \fB$FZF_PREVIEW_LEFT\fR so that
|
||||||
|
the preview command can determine the position of the preview window.
|
||||||
|
|
||||||
A placeholder expression starting with \fB+\fR flag will be replaced to the
|
A placeholder expression starting with \fB+\fR flag will be replaced to the
|
||||||
space-separated list of the selected lines (or the current line if no selection
|
space-separated list of the selected lines (or the current line if no selection
|
||||||
was made) individually quoted.
|
was made) individually quoted.
|
||||||
|
@ -2067,9 +2067,6 @@ Loop:
|
|||||||
|
|
||||||
if requiredLines > 0 {
|
if requiredLines > 0 {
|
||||||
if y+requiredLines == height {
|
if y+requiredLines == height {
|
||||||
if t.tui.MaxY() == t.pwindow.Top()+height {
|
|
||||||
t.tui.PassThrough("\x1b[1T")
|
|
||||||
}
|
|
||||||
t.pwindow.Move(height-1, maxWidth-1)
|
t.pwindow.Move(height-1, maxWidth-1)
|
||||||
t.previewed.filled = true
|
t.previewed.filled = true
|
||||||
break Loop
|
break Loop
|
||||||
@ -2790,6 +2787,8 @@ func (t *Terminal) Loop() {
|
|||||||
env = append(env, "FZF_PREVIEW_"+lines)
|
env = append(env, "FZF_PREVIEW_"+lines)
|
||||||
env = append(env, columns)
|
env = append(env, columns)
|
||||||
env = append(env, "FZF_PREVIEW_"+columns)
|
env = append(env, "FZF_PREVIEW_"+columns)
|
||||||
|
env = append(env, fmt.Sprintf("FZF_PREVIEW_TOP=%d", t.tui.Top()+t.pwindow.Top()))
|
||||||
|
env = append(env, fmt.Sprintf("FZF_PREVIEW_LEFT=%d", t.pwindow.Left()))
|
||||||
}
|
}
|
||||||
cmd.Env = env
|
cmd.Env = env
|
||||||
|
|
||||||
|
@ -41,6 +41,7 @@ func (r *FullscreenRenderer) Close() {}
|
|||||||
func (r *FullscreenRenderer) Size() TermSize { return TermSize{} }
|
func (r *FullscreenRenderer) Size() TermSize { return TermSize{} }
|
||||||
|
|
||||||
func (r *FullscreenRenderer) GetChar() Event { return Event{} }
|
func (r *FullscreenRenderer) GetChar() Event { return Event{} }
|
||||||
|
func (r *FullscreenRenderer) Top() int { return 0 }
|
||||||
func (r *FullscreenRenderer) MaxX() int { return 0 }
|
func (r *FullscreenRenderer) MaxX() int { return 0 }
|
||||||
func (r *FullscreenRenderer) MaxY() int { return 0 }
|
func (r *FullscreenRenderer) MaxY() int { return 0 }
|
||||||
|
|
||||||
|
@ -720,6 +720,10 @@ func (r *LightRenderer) Close() {
|
|||||||
r.restoreTerminal()
|
r.restoreTerminal()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (r *LightRenderer) Top() int {
|
||||||
|
return r.yoffset
|
||||||
|
}
|
||||||
|
|
||||||
func (r *LightRenderer) MaxX() int {
|
func (r *LightRenderer) MaxX() int {
|
||||||
return r.width
|
return r.width
|
||||||
}
|
}
|
||||||
|
@ -172,6 +172,10 @@ func (r *FullscreenRenderer) Init() {
|
|||||||
initTheme(r.theme, r.defaultTheme(), r.forceBlack)
|
initTheme(r.theme, r.defaultTheme(), r.forceBlack)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (r *FullscreenRenderer) Top() int {
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
func (r *FullscreenRenderer) MaxX() int {
|
func (r *FullscreenRenderer) MaxX() int {
|
||||||
ncols, _ := _screen.Size()
|
ncols, _ := _screen.Size()
|
||||||
return int(ncols)
|
return int(ncols)
|
||||||
|
@ -494,6 +494,7 @@ type Renderer interface {
|
|||||||
|
|
||||||
GetChar() Event
|
GetChar() Event
|
||||||
|
|
||||||
|
Top() int
|
||||||
MaxX() int
|
MaxX() int
|
||||||
MaxY() int
|
MaxY() int
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user