jarun / nnn

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

'open with' not working #1924

Closed chrimbo closed 2 months ago

chrimbo commented 2 months ago

I've encountered the following problem. If I want to open a file using 'o', the open with prompt is shown, but after entering the command, I get dropped back to nnn interface without running the command.

I'm running nnn in version 4.8 from ubuntu official repo (mantic). But also having the same issue on master branch.

So I compiled nnn with O_DEBUG=1 but didn't find any useful information.

So I dug deeper and finally found function get_input defined on line 1490 and inserted some xprintf's. The prompt is shown, the first get_wch(ch) returns 'L' and therefore the while (*ch == KEY_RESIZE) is not executed and the functions returns with (int)'L'

I can simply fix it by inserting a seconds get_wch(ch) just the line below the first occurance, but this looks quite odd to me.

Cause this looks like it could be a curses problem, here additional info:

➜ pkg-config --cflags ncursesw
-D_DEFAULT_SOURCE -D_XOPEN_SOURCE=600 
➜ pkg-config --libs ncursesw
-lncursesw -ltinfo
➜ ncursesw6-config --version
6.4.20230625
jarun commented 2 months ago

On master, the sequence should be:

open with: enter the command here
['g'ui]/'c'li?: enter g or c here

get_input() is invoked in the second prompt. What did you press in this prompt?

chrimbo commented 2 months ago

yes, it should be, but isn't. I did not press anything. The sequence looks like select file (e.g. test.xls) then olocalc<enter>

I found something new about it. I wanted to record the problem using asciinema. To show you both, the output of /tmp/nnndbg and nnn itself, I started tmux to have two panes. Then it works as normal. So, I tried other terminals. The Ubuntu Terminal App (gnome terminal) doesn't show the gui/cli prompt, while UXterm does. Terminator also doesn't work.

<<<EDIT: Kitty does also work, it shows the prompt>>>

I also tried different shells, zsh, bash, even sh.

I used this patch to debug

``` diff --git a/src/nnn.c b/src/nnn.c index 1208288b..10d8e000 100644 --- a/src/nnn.c +++ b/src/nnn.c @@ -1489,6 +1489,7 @@ static inline bool xconfirm(int c) static int get_input(const char *prompt) { + xprintf(DEBUG_FD, "[get_input] Prompt: %s\n", prompt); wint_t ch[1]; if (prompt) @@ -1496,9 +1497,11 @@ static int get_input(const char *prompt) cleartimeout(); get_wch(ch); + xprintf(DEBUG_FD, "[get_input] get_wch returned: %c\n", *ch); #ifdef KEY_RESIZE while (*ch == KEY_RESIZE) { + xprintf(DEBUG_FD, "[get_input] while(*ch == KEY_RESIZE)-> ch: %c\n", *ch); if (prompt) { clearoldprompt(); xlines = LINES; @@ -1509,6 +1512,7 @@ static int get_input(const char *prompt) } #endif settimeout(); + xprintf(DEBUG_FD, "[get_input] ended with: %c\n", *ch); return (int)*ch; } ```

here is the outcome https://asciinema.org/a/F4nd06gsFpnAKeWqzhK0sgpmL I never pressed 'L'

<<< EDIT: I just found out, that terminator's headline is multiple GNOME terminals in one window, So it might be a problem of gnome terminal>>>

chrimbo commented 2 months ago

Oops. The "L" is incorrect. I printed it as a char instead of wchar. It's a Ɍ (0x24c)

N-R-K commented 2 months ago

If it's only happening on gnome terminals, then it's likely not an nnn issue. Make sure your $TERM variable is set correctly. Otherwise you can also try export TERM=xterm-256color and see if that changes anything or not.

chrimbo commented 2 months ago

Thank you for trying to help, but TERM's already xterm-256color

I tried to set it to xterm only, cause UXTerm is setting this value, but doesn't solve it

chrimbo commented 2 months ago

I've made some progress.

On gnome terminal, when pressing o (open with), get_wch returns (not the key in ch, but the return value, which is discarded in nnn) KEY_CODE_YES (ch is then 0x24c). While on UXTerm the returnvalue is OK and *ch is the pressed character.

I now patched my nnn to workaround this

Patch

``` diff --git a/src/nnn.c b/src/nnn.c index 1208288b..e401c3c4 100644 --- a/src/nnn.c +++ b/src/nnn.c @@ -1490,22 +1490,23 @@ static inline bool xconfirm(int c) static int get_input(const char *prompt) { wint_t ch[1]; + int statuscode; if (prompt) printmsg(prompt); cleartimeout(); - get_wch(ch); + statuscode = get_wch(ch); #ifdef KEY_RESIZE - while (*ch == KEY_RESIZE) { + while (statuscode != OK) { if (prompt) { clearoldprompt(); xlines = LINES; printmsg(prompt); } - get_wch(ch); + statuscode = get_wch(ch); } #endif settimeout(); ```

N-R-K commented 2 months ago

That patch is not correct though. According to the docs, it will return OK for any wide characters read.

When get_wch, wget_wch, mvget_wch, and mvwget_wch functions successfully report the pressing of a function key, they return KEY_CODE_YES. When they successfully report a wide character, they return OK. Otherwise, they return ERR.

We want to check the specific character that was entered, not whether the read was successful or not.

chrimbo commented 2 months ago

I just wanted to help. I don´t know why this happened on my machine (ubuntu 23.10), so I provided the information I have.

BTW, my other machine with ubuntu 24.04 is not affected.

The patch works for me, at least if I have no typo. This is even stranger. If I open with 'g'ui but the program is non existent (e.g. a typo), I cannot open with again, as get_wch returns 0 (ERR) and *ch is also 0.

If I find the time, I will install a fresh copy of ubuntu 23.10 with nnn only to check if it's a local env thing.