1
1
mirror of https://github.com/jarun/nnn.git synced 2024-11-12 21:41:22 +03:00

preview-tui fixes (#900)

* redraw preview on resize

* fix stray preview pane after exit

* restore cleanup

* fix image bin info fallback
This commit is contained in:
luukvbaal 2021-03-21 02:41:14 +01:00 committed by GitHub
parent 49c458517f
commit ac29a7c166
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 8 deletions

View File

@ -69,6 +69,7 @@ TMPDIR="${TMPDIR:-/tmp}"
NUMPREVIEWTUI="$(($(find "$TMPDIR" -maxdepth 1 -name 'nnn-preview-tui-pagerpid*' 2>/dev/null | wc -l) + 1))"
PAGERPID="$TMPDIR/nnn-preview-tui-pagerpid.$NUMPREVIEWTUI"
GIFPID="$TMPDIR/nnn-preview-tui-gifpid.$NUMPREVIEWTUI"
CURSEL="$TMPDIR/nnn-preview-tui-selection.$NUMPREVIEWTUI"
FIFO_UEBERZUG="$TMPDIR/nnn-preview-tui-ueberzug-fifo.$NUMPREVIEWTUI"
[ "$PAGER" = "most" ] && PAGER="less -R"
@ -191,7 +192,7 @@ image_preview() {
viu -t "$3" &
echo "$!" > "$GIFPID"
else
fifo_pager print_bin_info "$1"
fifo_pager print_bin_info "$3"
fi
}
@ -205,16 +206,18 @@ ueberzug_remove() {
ueberzug_refresh() {
clear
kill "$(cat "$GIFPID" 2>/dev/null)" >/dev/null 2>&1
pkill -P "$$" >/dev/null 2>&1
pkill -f -n preview-tui-ext >/dev/null 2>&1
echo > "$NNN_FIFO"
tail --follow "$FIFO_UEBERZUG" | ueberzug layer --silent --parser json &
preview_file "$(cat "$CURSEL")"
echo > "$NNN_FIFO"
preview_fifo &
wait
}
if [ "$TERMINAL" != "kitty" ] && [ "$PREVIEW_MODE" ] && exists ueberzug; then
trap 'ueberzug_refresh' WINCH
trap 'rm "$FIFO_UEBERZUG" "$PAGERPID" "$GIFPID"' INT HUP EXIT
trap 'rm "$FIFO_UEBERZUG" "$PAGERPID" "$GIFPID" "$CURSEL"' INT HUP EXIT
fi
preview_fifo() {
@ -226,9 +229,11 @@ preview_fifo() {
kill "$(cat "$PAGERPID" 2>/dev/null)" >/dev/null 2>&1
[ "$TERMINAL" != "kitty" ] && exists ueberzug && ueberzug_remove
preview_file "$selection"
echo "$selection" > "$CURSEL"
done
[ "$TERMINAL" != "kitty" ] && exists ueberzug && rm "$FIFO_UEBERZUG"
rm "$PAGERPID" "$GIFPID" >/dev/null 2>&1
rm "$PAGERPID" "$GIFPID" "$CURSEL" >/dev/null 2>&1
pkill -P "$$" >/dev/null 2>&1
}
if [ "$PREVIEW_MODE" ]; then

View File

@ -79,6 +79,7 @@ TMPDIR="${TMPDIR:-/tmp}"
NUMPREVIEWTUI="$(($(find "$TMPDIR" -maxdepth 1 -name 'nnn-preview-tui-pagerpid*' 2>/dev/null | wc -l) + 1))"
PAGERPID="$TMPDIR/nnn-preview-tui-pagerpid.$NUMPREVIEWTUI"
GIFPID="$TMPDIR/nnn-preview-tui-gifpid.$NUMPREVIEWTUI"
CURSEL="$TMPDIR/nnn-preview-tui-selection.$NUMPREVIEWTUI"
FIFO_UEBERZUG="$TMPDIR/nnn-preview-tui-ueberzug-fifo.$NUMPREVIEWTUI"
[ "$PAGER" = "most" ] && PAGER="less -R"
@ -272,7 +273,7 @@ image_preview() {
viu -t "$3" &
echo "$!" > "$GIFPID"
else
fifo_pager print_bin_info "$1"
fifo_pager print_bin_info "$3"
fi
}
@ -286,16 +287,18 @@ ueberzug_remove() {
ueberzug_refresh() {
clear
kill "$(cat "$GIFPID" 2>/dev/null)" >/dev/null 2>&1
pkill -P "$$" >/dev/null 2>&1
pkill -f -n preview-tui-ext >/dev/null 2>&1
echo > "$NNN_FIFO"
tail --follow "$FIFO_UEBERZUG" | ueberzug layer --silent --parser json &
preview_file "$(cat "$CURSEL")"
echo > "$NNN_FIFO"
preview_fifo &
wait
}
if [ "$TERMINAL" != "kitty" ] && [ "$PREVIEW_MODE" ] && exists ueberzug; then
trap 'ueberzug_refresh' WINCH
trap 'rm "$FIFO_UEBERZUG" "$PAGERPID" "$GIFPID"' INT HUP EXIT
trap 'rm "$FIFO_UEBERZUG" "$PAGERPID" "$GIFPID" "$CURSEL"' INT HUP EXIT
fi
preview_fifo() {
@ -307,9 +310,11 @@ preview_fifo() {
kill "$(cat "$PAGERPID" 2>/dev/null)" >/dev/null 2>&1
[ "$TERMINAL" != "kitty" ] && exists ueberzug && ueberzug_remove
preview_file "$selection"
echo "$selection" > "$CURSEL"
done
[ "$TERMINAL" != "kitty" ] && exists ueberzug && rm "$FIFO_UEBERZUG"
rm "$PAGERPID" "$GIFPID" >/dev/null 2>&1
rm "$PAGERPID" "$GIFPID" "$CURSEL" >/dev/null 2>&1
pkill -P "$$" >/dev/null 2>&1
}