"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "plugins/preview-tui" between
nnn-v4.1.1.tar.gz and nnn-v4.2.tar.gz

About: nnn is a full-featured terminal file manager.

preview-tui  (nnn-v4.1.1):preview-tui  (nnn-v4.2)
skipping to change at line 87 skipping to change at line 87
ICONLOOKUP="${ICONLOOKUP:-0}" ICONLOOKUP="${ICONLOOKUP:-0}"
PAGER="${PAGER:-less -P?n -R}" PAGER="${PAGER:-less -P?n -R}"
TMPDIR="${TMPDIR:-/tmp}" TMPDIR="${TMPDIR:-/tmp}"
BAT_STYLE="${BAT_STYLE:-numbers}" BAT_STYLE="${BAT_STYLE:-numbers}"
# Consider setting NNN_PREVIEWDIR to $XDG_CACHE_HOME/nnn/previews if you want to keep previews on disk between reboots # Consider setting NNN_PREVIEWDIR to $XDG_CACHE_HOME/nnn/previews if you want to keep previews on disk between reboots
NNN_PREVIEWDIR="${NNN_PREVIEWDIR:-$TMPDIR/nnn/previews}" NNN_PREVIEWDIR="${NNN_PREVIEWDIR:-$TMPDIR/nnn/previews}"
NNN_PREVIEWWIDTH="${NNN_PREVIEWWIDTH:-1920}" NNN_PREVIEWWIDTH="${NNN_PREVIEWWIDTH:-1920}"
NNN_PREVIEWHEIGHT="${NNN_PREVIEWHEIGHT:-1080}" NNN_PREVIEWHEIGHT="${NNN_PREVIEWHEIGHT:-1080}"
NNN_PARENT="${NNN_FIFO#*.}" NNN_PARENT="${NNN_FIFO#*.}"
FIFOPID="$TMPDIR/nnn-preview-tui-fifopid.$NNN_PARENT" FIFOPID="$TMPDIR/nnn-preview-tui-fifopid.$NNN_PARENT"
PAGERPID="$TMPDIR/nnn-preview-tui-pagerpid.$NNN_PARENT" PREVIEWPID="$TMPDIR/nnn-preview-tui-pagerpid.$NNN_PARENT"
IMGPID="$TMPDIR/nnn-preview-tui-imgpid.$NNN_PARENT"
CURSEL="$TMPDIR/nnn-preview-tui-selection.$NNN_PARENT" CURSEL="$TMPDIR/nnn-preview-tui-selection.$NNN_PARENT"
FIFO_UEBERZUG="$TMPDIR/nnn-preview-tui-ueberzug-fifo.$NNN_PARENT" FIFO_UEBERZUG="$TMPDIR/nnn-preview-tui-ueberzug-fifo.$NNN_PARENT"
start_preview() { start_preview() {
[ "$PAGER" = "most" ] && PAGER="less -R" [ "$PAGER" = "most" ] && PAGER="less -R"
if [ -e "${TMUX%%,*}" ] && tmux -V | grep -q '[ -][3456789]\.'; then if [ -e "${TMUX%%,*}" ] && tmux -V | grep -q '[ -][3456789]\.'; then
TERMINAL=tmux TERMINAL=tmux
elif [ -n "$KITTY_LISTEN_ON" ]; then elif [ -n "$KITTY_LISTEN_ON" ]; then
TERMINAL=kitty TERMINAL=kitty
skipping to change at line 112 skipping to change at line 111
if [ -z "$SPLIT" ] && [ $(($(tput lines) * 2)) -gt "$(tput cols)" ]; then if [ -z "$SPLIT" ] && [ $(($(tput lines) * 2)) -gt "$(tput cols)" ]; then
SPLIT='h' SPLIT='h'
elif [ "$SPLIT" != 'h' ]; then elif [ "$SPLIT" != 'h' ]; then
SPLIT='v' SPLIT='v'
fi fi
case "$TERMINAL" in case "$TERMINAL" in
tmux) # tmux splits are inverted tmux) # tmux splits are inverted
if [ "$SPLIT" = "v" ]; then DSPLIT="h"; else DSPLIT="v"; fi if [ "$SPLIT" = "v" ]; then DSPLIT="h"; else DSPLIT="v"; fi
tmux split-window -e "NNN_FIFO=$NNN_FIFO" -e "PREVIEW_MODE=1" -e "PA tmux split-window -e "NNN_FIFO=$NNN_FIFO" -e "PREVIEW_MODE=1" \
GER=$PAGER" \ -e "CURSEL=$CURSEL" -e "TMPDIR=$TMPDIR" -e "FIFOPID=$FIFOPID" \
-e "BAT_STYLE=$BAT_STYLE" -e "PREVIEWPID=$PREVIEWPID" -e "PAGER=
$PAGER" \
-e "ICONLOOKUP=$ICONLOOKUP" -e "NNN_PREVIEWWIDTH=$NNN_PREVIEWWID
TH" \
-e "USE_SCOPE=$USE_SCOPE" -e "SPLIT=$SPLIT" -e "USE_PISTOL=$USE_ PISTOL" \ -e "USE_SCOPE=$USE_SCOPE" -e "SPLIT=$SPLIT" -e "USE_PISTOL=$USE_ PISTOL" \
-e "BAT_STYLE=$BAT_STYLE" -e "PAGERPID=$PAGERPID" -e "FIFOPID=$F -e "NNN_PREVIEWDIR=$NNN_PREVIEWDIR" -e "NNN_PREVIEWHEIGHT=$NNN_P
IFOPID" \ REVIEWHEIGHT" \
-e "IMGPID=$IMGPID" -e "CURSEL=$CURSEL" -e "TMPDIR=$TMPDIR" \
-e "ICONLOOKUP=$ICONLOOKUP" -e "NNN_PREVIEWDIR=$NNN_PREVIEWDIR"
\
-e "NNN_PREVIEWWIDTH=$NNN_PREVIEWWIDTH" -e "NNN_PREVIEWHEIGHT=$N
NN_PREVIEWHEIGHT" \
-e "FIFO_UEBERZUG=$FIFO_UEBERZUG" -e "QLPATH=$2" -d"$DSPLIT" "$0 " "$1" ;; -e "FIFO_UEBERZUG=$FIFO_UEBERZUG" -e "QLPATH=$2" -d"$DSPLIT" "$0 " "$1" ;;
kitty) # Setting the layout for the new window. It will be restored afte r the script ends. kitty) # Setting the layout for the new window. It will be restored afte r the script ends.
kitty @ goto-layout splits kitty @ goto-layout splits
# Trying to use kitty's integrated window management as the split wi ndow. All # Trying to use kitty's integrated window management as the split wi ndow. All
# environmental variables that will be used in the new window must b e explicitly passed. # environmental variables that will be used in the new window must b e explicitly passed.
kitty @ launch --no-response --title "nnn preview" --keep-focus \ kitty @ launch --no-response --title "nnn preview" --keep-focus \
--cwd "$PWD" --env "PATH=$PATH" --env "NNN_FIFO=$NNN_FIFO" \ --cwd "$PWD" --env "PATH=$PATH" --env "NNN_FIFO=$NNN_FIFO" \
--env "PREVIEW_MODE=1" --env "PAGER=$PAGER" --env "TMPDIR=$TMPDI R" \ --env "PREVIEW_MODE=1" --env "PAGER=$PAGER" --env "TMPDIR=$TMPDI R" \
--env "USE_SCOPE=$USE_SCOPE" --env "SPLIT=$SPLIT" --env "TERMINA L=$TERMINAL"\ --env "USE_SCOPE=$USE_SCOPE" --env "SPLIT=$SPLIT" --env "TERMINA L=$TERMINAL"\
--env "PREVIEWPID=$PREVIEWPID" --env "FIFO_UEBERZUG=$FIFO_UEBERZ
UG" \
--env "ICONLOOKUP=$ICONLOOKUP" --env "NNN_PREVIEWHEIGHT=$NNN_PRE
VIEWHEIGHT" \
--env "NNN_PREVIEWWIDTH=$NNN_PREVIEWWIDTH" --env "NNN_PREVIEWDIR
=$NNN_PREVIEWDIR" \
--env "USE_PISTOL=$USE_PISTOL" --env "BAT_STYLE=$BAT_STYLE" --en v "FIFOPID=$FIFOPID" \ --env "USE_PISTOL=$USE_PISTOL" --env "BAT_STYLE=$BAT_STYLE" --en v "FIFOPID=$FIFOPID" \
--env "PAGERPID=$PAGERPID" --env "IMGPID=$IMGPID" --env "FIFO_UE
BERZUG=$FIFO_UEBERZUG" \
--env "ICONLOOKUP=$ICONLOOKUP" --env "NNN_PREVIEWDIR=$NNN_PREVIE
WDIR" \
--env "NNN_PREVIEWWIDTH=$NNN_PREVIEWWIDTH" --env "NNN_PREVIEWHEI
GHT=$NNN_PREVIEWHEIGHT" \
--env "CURSEL=$CURSEL" --location "${SPLIT}split" "$0" "$1" ;; --env "CURSEL=$CURSEL" --location "${SPLIT}split" "$0" "$1" ;;
*) if [ -n "$2" ]; then *) if [ -n "$2" ]; then
QUICKLOOK=1 QLPATH="$2" PREVIEW_MODE=1 "$0" "$1" & QUICKLOOK=1 QLPATH="$2" PREVIEW_MODE=1 "$0" "$1" &
else else
PAGERPID="$PAGERPID" IMGPID="$IMGPID" CURSEL="$CURSEL" PREVIEW_M ODE=1 \ PREVIEWPID="$PREVIEWPID" CURSEL="$CURSEL" PREVIEW_MODE=1 \
FIFOPID="$FIFOPID" FIFO_UEBERZUG="$FIFO_UEBERZUG" $TERMINAL -e "$0" "$1" & FIFOPID="$FIFOPID" FIFO_UEBERZUG="$FIFO_UEBERZUG" $TERMINAL -e "$0" "$1" &
fi ;; fi ;;
esac esac
} >/dev/null 2>&1 } >/dev/null 2>&1
toggle_preview() { toggle_preview() {
if exists QuickLook.exe; then if exists QuickLook.exe; then
QLPATH="QuickLook.exe" QLPATH="QuickLook.exe"
elif exists Bridge.exe; then elif exists Bridge.exe; then
QLPATH="Bridge.exe" QLPATH="Bridge.exe"
fi fi
if pkill -P "$(cat "$FIFOPID")"; then if kill "$(cat "$FIFOPID")"; then
kill "$(cat "$PREVIEWPID")"
pkill -f "tail --follow $FIFO_UEBERZUG"
if [ -n "$QLPATH" ] && stat "$1"; then if [ -n "$QLPATH" ] && stat "$1"; then
f="$(wslpath -w "$1")" && "$QLPATH" "$f" & f="$(wslpath -w "$1")" && "$QLPATH" "$f" &
fi fi
else else
start_preview "$1" "$QLPATH" start_preview "$1" "$QLPATH"
fi fi
} >/dev/null 2>&1 } >/dev/null 2>&1
exists() { exists() {
type "$1" >/dev/null type "$1" >/dev/null
skipping to change at line 169 skipping to change at line 170
fifo_pager() { fifo_pager() {
cmd="$1" cmd="$1"
shift shift
# We use a FIFO to access $PAGER PID in jobs control # We use a FIFO to access $PAGER PID in jobs control
tmpfifopath="$TMPDIR/nnn-preview-tui-fifo.$$" tmpfifopath="$TMPDIR/nnn-preview-tui-fifo.$$"
mkfifo "$tmpfifopath" || return mkfifo "$tmpfifopath" || return
$PAGER < "$tmpfifopath" & $PAGER < "$tmpfifopath" &
printf "%s" "$!" > "$PAGERPID" printf "%s" "$!" > "$PREVIEWPID"
( (
exec > "$tmpfifopath" exec > "$tmpfifopath"
if [ "$cmd" = "pager" ]; then if [ "$cmd" = "pager" ]; then
if exists bat; then if exists bat; then
bat --terminal-width="$(tput cols)" --decorations=always --color =always \ bat --terminal-width="$(tput cols)" --decorations=always --color =always \
--paging=never --style="$BAT_STYLE" "$@" & --paging=never --style="$BAT_STYLE" "$@" &
else else
$PAGER "$@" & $PAGER "$@" &
fi fi
skipping to change at line 324 skipping to change at line 325
if [ ! -d "$NNN_PREVIEWDIR/$3" ]; then if [ ! -d "$NNN_PREVIEWDIR/$3" ]; then
mkdir -p "$NNN_PREVIEWDIR/$3" mkdir -p "$NNN_PREVIEWDIR/$3"
convert -coalesce -resize "$NNN_PREVIEWWIDTH"x"$NNN_PREV IEWHEIGHT"\> "$3" "$NNN_PREVIEWDIR/$3/${3##*/}.jpg" convert -coalesce -resize "$NNN_PREVIEWWIDTH"x"$NNN_PREV IEWHEIGHT"\> "$3" "$NNN_PREVIEWDIR/$3/${3##*/}.jpg"
fi fi
while true; do while true; do
for frame in $(find "$NNN_PREVIEWDIR/$3"/*.jpg | sor t -V); do for frame in $(find "$NNN_PREVIEWDIR/$3"/*.jpg | sor t -V); do
image_preview "$1" "$2" "$frame" image_preview "$1" "$2" "$frame"
sleep 0.1 sleep 0.1
done done
done & done &
printf "%s" "$!" > "$IMGPID" printf "%s" "$!" > "$PREVIEWPID"
return return
else else
exec >/dev/tty
image_preview "$1" "$2" "$3" image_preview "$1" "$2" "$3"
return return
fi ;; fi ;;
image) convert "$3" -flatten -resize "$NNN_PREVIEWWIDTH"x"$NNN_PREVI EWHEIGHT"\> "$NNN_PREVIEWDIR/$3.jpg" ;; image) convert "$3" -flatten -resize "$NNN_PREVIEWWIDTH"x"$NNN_PREVI EWHEIGHT"\> "$NNN_PREVIEWDIR/$3.jpg" ;;
office) libreoffice --convert-to jpg "$3" --outdir "$NNN_PREVIEWDIR/ ${3%/*}" office) libreoffice --convert-to jpg "$3" --outdir "$NNN_PREVIEWDIR/ ${3%/*}"
filename="$(printf "%s" "${3##*/}" | cut -d. -f1)" filename="$(printf "%s" "${3##*/}" | cut -d. -f1)"
mv "$NNN_PREVIEWDIR/${3%/*}/$filename.jpg" "$NNN_PREVIEWDIR/ $3.jpg" ;; mv "$NNN_PREVIEWDIR/${3%/*}/$filename.jpg" "$NNN_PREVIEWDIR/ $3.jpg" ;;
pdf) pdftoppm -jpeg -f 1 -singlefile "$3" "$NNN_PREVIEWDIR/$3" ;; pdf) pdftoppm -jpeg -f 1 -singlefile "$3" "$NNN_PREVIEWDIR/$3" ;;
video) ffmpegthumbnailer -s0 -i "$3" -o "$NNN_PREVIEWDIR/$3.jpg" || rm "$NNN_PREVIEWDIR/$3.jpg" ;; video) ffmpegthumbnailer -s0 -i "$3" -o "$NNN_PREVIEWDIR/$3.jpg" || rm "$NNN_PREVIEWDIR/$3.jpg" ;;
esac esac
skipping to change at line 359 skipping to change at line 361
kitty +kitten icat --silent --place "$1"x"$2"@0x0 --transfer-mode=stream --stdin=no "$3" & kitty +kitten icat --silent --place "$1"x"$2"@0x0 --transfer-mode=stream --stdin=no "$3" &
elif exists ueberzug; then elif exists ueberzug; then
ueberzug_layer "$1" "$2" "$3" && return ueberzug_layer "$1" "$2" "$3" && return
elif exists catimg; then elif exists catimg; then
catimg "$3" & catimg "$3" &
elif exists viu; then elif exists viu; then
viu -t "$3" & viu -t "$3" &
else else
fifo_pager print_bin_info "$3" && return fifo_pager print_bin_info "$3" && return
fi fi
printf "%s" "$!" > "$IMGPID" printf "%s" "$!" > "$PREVIEWPID"
} 2>/dev/null } 2>/dev/null
ueberzug_layer() { ueberzug_layer() {
printf '{"action": "add", "identifier": "nnn_ueberzug", "x": 0, "y": 0, "wid th": "%d", "height": "%d", "scaler": "fit_contain", "path": "%s"}\n' "$1" "$2" " $3" > "$FIFO_UEBERZUG" printf '{"action": "add", "identifier": "nnn_ueberzug", "x": 0, "y": 0, "wid th": "%d", "height": "%d", "scaler": "fit_contain", "path": "%s"}\n' "$1" "$2" " $3" > "$FIFO_UEBERZUG"
} }
ueberzug_remove() { ueberzug_remove() {
printf '{"action": "remove", "identifier": "nnn_ueberzug"}\n' > "$FIFO_UEBER ZUG" printf '{"action": "remove", "identifier": "nnn_ueberzug"}\n' > "$FIFO_UEBER ZUG"
} }
winch_handler() { winch_handler() {
clear clear
kill "$(cat "$IMGPID")" "$(cat "$PAGERPID")" kill "$(cat "$PREVIEWPID")"
if [ -p "$FIFO_UEBERZUG" ]; then if [ -p "$FIFO_UEBERZUG" ]; then
pkill -P "$$" pkill -f "tail --follow $FIFO_UEBERZUG"
tail --follow "$FIFO_UEBERZUG" | ueberzug layer --silent --parser json & tail --follow "$FIFO_UEBERZUG" | ueberzug layer --silent --parser json &
fi fi
cat "$CURSEL" > "$NNN_FIFO"
preview_file "$(cat "$CURSEL")" preview_file "$(cat "$CURSEL")"
preview_fifo & if ! kill -0 "$NNN_PARENT" || ! pgrep nnn >/dev/null; then
wait "$!" pkill -P "$$"
fi
} 2>/dev/null } 2>/dev/null
preview_fifo() { preview_fifo() {
printf "%s" "$$" > "$FIFOPID"
while read -r selection; do while read -r selection; do
kill "$(cat "$IMGPID")" "$(cat "$PAGERPID")" if [ -n "$selection" ]; then
[ -p "$FIFO_UEBERZUG" ] && ueberzug_remove kill "$(cat "$PREVIEWPID")"
preview_file "$selection" [ -p "$FIFO_UEBERZUG" ] && ueberzug_remove
printf "%s" "$selection" > "$CURSEL" preview_file "$selection"
printf "%s" "$selection" > "$CURSEL"
fi
done < "$NNN_FIFO" done < "$NNN_FIFO"
pkill -P "$$"
} 2>/dev/null } 2>/dev/null
if [ "$PREVIEW_MODE" ]; then if [ "$PREVIEW_MODE" ]; then
if [ "$TERMINAL" != "kitty" ] && exists ueberzug; then if [ "$TERMINAL" != "kitty" ] && exists ueberzug; then
mkfifo "$FIFO_UEBERZUG" mkfifo "$FIFO_UEBERZUG"
tail --follow "$FIFO_UEBERZUG" | ueberzug layer --silent --parser json & tail --follow "$FIFO_UEBERZUG" | ueberzug layer --silent --parser json &
fi fi
printf "%s" "$PWD/$1" > "$CURSEL"
preview_file "$PWD/$1" preview_file "$PWD/$1"
preview_fifo & preview_fifo &
trap 'winch_handler' WINCH printf "%s" "$!" > "$FIFOPID"
trap 'rm "$PAGERPID" "$IMGPID" "$CURSEL" "$FIFO_UEBERZUG" "$FIFOPID" 2>/dev/ printf "%s" "$PWD/$1" > "$CURSEL"
null' INT HUP EXIT trap 'winch_handler; wait' WINCH
trap 'rm "$PREVIEWPID" "$CURSEL" "$FIFO_UEBERZUG" "$FIFOPID" 2>/dev/null' IN
T HUP EXIT
wait "$!" 2>/dev/null wait "$!" 2>/dev/null
else else
if [ ! -r "$NNN_FIFO" ]; then if [ ! -r "$NNN_FIFO" ]; then
clear clear
printf "No FIFO available! (\$NNN_FIFO='%s')\nPlease read Usage in previ ew-tui." "$NNN_FIFO" printf "No FIFO available! (\$NNN_FIFO='%s')\nPlease read Usage in previ ew-tui." "$NNN_FIFO"
cfg=$(stty -g); stty raw -echo; head -c 1; stty "$cfg" cfg=$(stty -g); stty raw -echo; head -c 1; stty "$cfg"
elif [ "$KITTY_WINDOW_ID" ] && [ -z "$KITTY_LISTEN_ON" ]; then elif [ "$KITTY_WINDOW_ID" ] && [ -z "$TMUX" ] && [ -z "$KITTY_LISTEN_ON" ]; then
clear clear
printf "\$KITTY_LISTEN_ON not set!\nPlease read Usage in preview-tui." printf "\$KITTY_LISTEN_ON not set!\nPlease read Usage in preview-tui."
cfg=$(stty -g); stty raw -echo; head -c 1; stty "$cfg" cfg=$(stty -g); stty raw -echo; head -c 1; stty "$cfg"
else else
toggle_preview "$1" & toggle_preview "$1" &
fi fi
fi fi
 End of changes. 21 change blocks. 
37 lines changed or deleted 41 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)