jarun / nnn

n³ The unorthodox terminal file manager
BSD 2-Clause "Simplified" License
19.1k stars 760 forks source link

NNN does not close Tmux pane on opening a file while preview #1814

Closed AinTEAsports closed 3 months ago

AinTEAsports commented 7 months ago

Environment details (Put x in the checkbox along with the information)

Exact steps to reproduce the issue

  1. Open Kitty
  2. Run tmux
  3. Run nnn -Adeo -Pp (so that it starts with preview files)
  4. Navigate to any file and press enter so that it opens vim to edit the file

The pane showing the preview is not closed on opening of vim (I did not tried to reproduce the bug with any other editor than vim).

Oxore commented 7 months ago

You should try patches/restorepreview/mainline.diff. It fixed the issue for me, at least.

AinTEAsports commented 7 months ago

Looks like it does nothing in my case.

N-R-K commented 7 months ago

Maybe related: https://github.com/jarun/nnn/discussions/1809

CityofSirtel commented 7 months ago

I'm pretty sure restorepreview only applies to the internal editor, pressing e, enter handles it with your opener, nuke etc. # Description: Adds preview pipe to enable closing and re-opening the preview pane when running an undetached editor. I just copied the toggle_preview from preview_tui in a wrapper that kills the preview and uses tmux to reenable it

``` #!/usr/bin/env bash TMPDIR=${TMPDIR:-/tmp} # location of temporary files PLUG_KEY=$(echo "$NNN_PLUG" | sed 's/.*\(.\):preview-tui.*$/\1/') NNN_PARENT=${NNN_FIFO#*.} FIFOPID="$TMPDIR/nnn-preview-tui-fifopid.$NNN_PARENT" #PREVIEWPID="$TMPDIR/nnn-preview-tui-previewpid.$NNN_PARENT" #FIFO_UEBERZUG="$TMPDIR/nnn-preview-tui-ueberzug-fifo.$NNN_PARENT" pkill() { command pkill "$@" >/dev/null 2>&1 ;} pidkill() { if [ -f "$1" ]; then PID="$(cat "$1" 2>/dev/null)" || return 1 kill "$PID" >/dev/null 2>&1 RET=$? wait "$PID" 2>/dev/null return $RET fi return 1 } run_cmd() { if [ -n "$TMUX" ]; then if pidkill "$FIFOPID"; then "$@" tmux send-keys "M-$PLUG_KEY" else "$@" fi else "$@" fi return 1 } ```

then all you have to do to toggle it for any plugin is

source toggle_prev
run_cmd do stuff here

If you wanted it to toggle on file open you'd have to make a custom opener or edit nuke to do something similar, I just open vim in a new tmux window

luukvbaal commented 7 months ago

Correct, the restorepreview patch hides and restores preview-tui when opening and closing an attached editor. I guess I didn't consider the case for forked programs since we don't know when it closes, or when it makes sense to restore preview-tui.

Despite that, I suppose closing preview-tui unconditionally when a file is opened can make sense as well. Not sure if it makes sense to change the restorepreview patch at this point, although I wouldn't mind it.

KlzXS commented 3 months ago

Since there hasn't been any response from @AinTEAsports and there has been a proposed solution I'll close this as stale.

Feel free to reopen if you want further discussion and to work on this topic.