mirror of
https://github.com/jarun/nnn.git
synced 2025-01-15 21:36:42 +00:00
preview-tui: make debugging easier
i've noticed that there's a non-trival amount of issues user face related to preview-tui. allowing all the null redirection to be easily switched on/off can make debugging much easier, both for the users and for us.
This commit is contained in:
parent
cb410e25d8
commit
c3534bd7e0
|
@ -78,6 +78,7 @@
|
||||||
|
|
||||||
#SPLIT="$SPLIT" # you can set a permanent split here
|
#SPLIT="$SPLIT" # you can set a permanent split here
|
||||||
#TERMINAL="$TERMINAL" # same goes for the terminal
|
#TERMINAL="$TERMINAL" # same goes for the terminal
|
||||||
|
DEBUG_LOG=0 # set to 1 to enable logging for debug purposes
|
||||||
USE_SCOPE="${USE_SCOPE:-0}"
|
USE_SCOPE="${USE_SCOPE:-0}"
|
||||||
USE_PISTOL="${USE_PISTOL:-0}"
|
USE_PISTOL="${USE_PISTOL:-0}"
|
||||||
ICONLOOKUP="${ICONLOOKUP:-0}"
|
ICONLOOKUP="${ICONLOOKUP:-0}"
|
||||||
|
@ -96,6 +97,12 @@ PREVIEWPID="$TMPDIR/nnn-preview-tui-pagerpid.$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"
|
||||||
|
|
||||||
|
if [ "$DEBUG_LOG" -eq 0 ]; then
|
||||||
|
DEBUG_LOGFILE="/dev/null"
|
||||||
|
else
|
||||||
|
DEBUG_LOGFILE="${TMPDIR}/preview-tui-log"
|
||||||
|
fi
|
||||||
|
|
||||||
start_preview() {
|
start_preview() {
|
||||||
[ "$PAGER" = "most" ] && PAGER="less -R"
|
[ "$PAGER" = "most" ] && PAGER="less -R"
|
||||||
|
|
||||||
|
@ -176,7 +183,7 @@ EOF
|
||||||
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
|
} >"$DEBUG_LOGFILE" 2>&1
|
||||||
|
|
||||||
toggle_preview() {
|
toggle_preview() {
|
||||||
if exists QuickLook.exe; then
|
if exists QuickLook.exe; then
|
||||||
|
@ -195,7 +202,7 @@ toggle_preview() {
|
||||||
[ -p "$NNN_PPIPE" ] && printf "1" > "$NNN_PPIPE"
|
[ -p "$NNN_PPIPE" ] && printf "1" > "$NNN_PPIPE"
|
||||||
start_preview "$1" "$QLPATH"
|
start_preview "$1" "$QLPATH"
|
||||||
fi
|
fi
|
||||||
} >/dev/null 2>&1
|
} >"$DEBUG_LOGFILE" 2>&1
|
||||||
|
|
||||||
exists() {
|
exists() {
|
||||||
type "$1" >/dev/null
|
type "$1" >/dev/null
|
||||||
|
@ -227,7 +234,7 @@ fifo_pager() {
|
||||||
)
|
)
|
||||||
|
|
||||||
rm "$tmpfifopath"
|
rm "$tmpfifopath"
|
||||||
} 2>/dev/null
|
} 2>"$DEBUG_LOGFILE"
|
||||||
|
|
||||||
# Binary file: show file info inside the pager
|
# Binary file: show file info inside the pager
|
||||||
print_bin_info() {
|
print_bin_info() {
|
||||||
|
@ -237,7 +244,7 @@ print_bin_info() {
|
||||||
else
|
else
|
||||||
file -b "$1"
|
file -b "$1"
|
||||||
fi
|
fi
|
||||||
} 2>/dev/null
|
} 2>"$DEBUG_LOGFILE"
|
||||||
|
|
||||||
handle_mime() {
|
handle_mime() {
|
||||||
case "$2" in
|
case "$2" in
|
||||||
|
@ -343,7 +350,7 @@ preview_file() {
|
||||||
else
|
else
|
||||||
handle_mime "$1" "$mimetype" "$ext"
|
handle_mime "$1" "$mimetype" "$ext"
|
||||||
fi
|
fi
|
||||||
} 2>/dev/null
|
} 2>"$DEBUG_LOGFILE"
|
||||||
|
|
||||||
generate_preview() {
|
generate_preview() {
|
||||||
if [ -n "$QLPATH" ] && stat "$3"; then
|
if [ -n "$QLPATH" ] && stat "$3"; then
|
||||||
|
@ -387,13 +394,13 @@ generate_preview() {
|
||||||
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
|
||||||
fi >/dev/null
|
fi >"$DEBUG_LOGFILE"
|
||||||
if [ -f "$NNN_PREVIEWDIR/$3.jpg" ]; then
|
if [ -f "$NNN_PREVIEWDIR/$3.jpg" ]; then
|
||||||
image_preview "$1" "$2" "$NNN_PREVIEWDIR/$3.jpg"
|
image_preview "$1" "$2" "$NNN_PREVIEWDIR/$3.jpg"
|
||||||
else
|
else
|
||||||
fifo_pager print_bin_info "$3"
|
fifo_pager print_bin_info "$3"
|
||||||
fi
|
fi
|
||||||
} 2>/dev/null
|
} 2>"$DEBUG_LOGFILE"
|
||||||
|
|
||||||
image_preview() {
|
image_preview() {
|
||||||
clear
|
clear
|
||||||
|
@ -410,7 +417,7 @@ image_preview() {
|
||||||
fifo_pager print_bin_info "$3" && return
|
fifo_pager print_bin_info "$3" && return
|
||||||
fi
|
fi
|
||||||
printf "%s" "$!" > "$PREVIEWPID"
|
printf "%s" "$!" > "$PREVIEWPID"
|
||||||
} 2>/dev/null
|
} 2>"$DEBUG_LOGFILE"
|
||||||
|
|
||||||
ueberzug_layer() {
|
ueberzug_layer() {
|
||||||
printf '{"action": "add", "identifier": "nnn_ueberzug", "x": 0, "y": 0, "width": "%d", "height": "%d", "scaler": "fit_contain", "path": "%s"}\n' "$1" "$2" "$3" > "$FIFO_UEBERZUG"
|
printf '{"action": "add", "identifier": "nnn_ueberzug", "x": 0, "y": 0, "width": "%d", "height": "%d", "scaler": "fit_contain", "path": "%s"}\n' "$1" "$2" "$3" > "$FIFO_UEBERZUG"
|
||||||
|
@ -428,7 +435,7 @@ winch_handler() {
|
||||||
tail --follow "$FIFO_UEBERZUG" | ueberzug layer --silent --parser json &
|
tail --follow "$FIFO_UEBERZUG" | ueberzug layer --silent --parser json &
|
||||||
fi
|
fi
|
||||||
preview_file "$(cat "$CURSEL")"
|
preview_file "$(cat "$CURSEL")"
|
||||||
} 2>/dev/null
|
} 2>"$DEBUG_LOGFILE"
|
||||||
|
|
||||||
preview_fifo() {
|
preview_fifo() {
|
||||||
while read -r selection; do
|
while read -r selection; do
|
||||||
|
@ -442,7 +449,7 @@ preview_fifo() {
|
||||||
done < "$NNN_FIFO"
|
done < "$NNN_FIFO"
|
||||||
sleep 0.1 # make sure potential preview by winch_handler is killed
|
sleep 0.1 # make sure potential preview by winch_handler is killed
|
||||||
pkill -P "$$"
|
pkill -P "$$"
|
||||||
} 2>/dev/null
|
} 2>"$DEBUG_LOGFILE"
|
||||||
|
|
||||||
if [ "$PREVIEW_MODE" ]; then
|
if [ "$PREVIEW_MODE" ]; then
|
||||||
if [ "$TERMINAL" != "kitty" ] && exists ueberzug; then
|
if [ "$TERMINAL" != "kitty" ] && exists ueberzug; then
|
||||||
|
|
Loading…
Reference in a new issue