nadrad / h-m-m

Hackers Mind Map

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Problem with entering text for search and filenames

llagerlof opened this issue · comments

With any node focused, including the root one, when I press the slash key (/) nothing happens.

I am using Fedora 36, gnome-terminal, bash (tested with zsh too).

Note: I doesn't have the slash keybinded on gnome-terminal.

I just added '?' and 'ctrl+f' as alternative key bindings for search. Check to see if any of those works for you.

Thank you. But I am having another keybindings issues. For example, when I hit "s" or "S" h-m-m shows me "Saving cancelled". The new ones does nothing for me too.

Some other keys are working, like TAB, ENTER and "e".

I thought it was the gnome-terminal, so I tried with 3 others terminal emulators. Same behaviour, very strange.

Well, I am feeling my case is very particular because yesterday everything was working. Maybe you could left this issue open for some days to check if someone report the same problem?

Just to add some info, I checked out the yesterday version, the version that worked for me. Same problem. At least now we know that wasn't any particular update.

So, the problem seems to be related to the readline function. The save as function shows "saving cancelled" if you press enter without entering any name, and the search function clears search highlights if you press '/' and then 'enter' (which would look like nothing has happened if you don't already have a search highlight).

Editing the nodes is different, because it doesn't use the readline function, but processes all the key presses and do it in a low-level way.

So, when you press 's', do you see the message immediately, or do you have to press 'enter' to see the message?
The former suggests that there's a problem with readline and the latter may be a simple case such as a problem with detecting the height of the screen and printing the prompt outside the visible area.

Debugging here, you are right. For some reason readline() is not prompting for user input. The execution passes by the readline but doesn't pause for user input.

To find this I logged the $mm['query'] in the search() function. Before the readline it has the NULL value. After readline has the boolen FALSE.

edit: Just to add some info, I tried read directly from stdin, but not worked. The execution passes directly too.

$h = fopen("php://stdin","r");
$mm['query'] = fgets($h);

Tried to use readline and fopen/fget in a separated script. It worked (thank god, I thought my stdin was broken)

I was just reading about it, and seemingly, the readline function is just an interface with GNU Readline! (who said php is not a proper language? ;)

Anyway, it seems possible for someone to have php without it, and they would need to install libreadline or something like that. However, you said that readline works for you in other scripts! That's strange. Maybe it has something to do with the screen attributes... try commenting the set_up_screen function and see if it helps. If it does, then one of those attributes is causing the issue with readline.

set_up_screen() is definetively necessary. The program is unusable without these settings. curses! 😉

edit: all tests made mentioned in comments above were made with php 7.4 and 8.1

I could grab an error that was happening when type "s". Appeared very fast:

read: read error: 0: Resource temporarily unavailable

I replaced $mm['filename'] = trim(readline()); for exec('read </dev/tty');, just for testing.

Oddly enough, I could read directly from tty (executing read like above). I could type and confirm with ENTER, but I don't know how to retrieve the typed string inside the php in this case since the output goes to $REPLY 😅

Correct; it's not even possible to test it without that function. Let's replace the function with this single line:

  system('stty cbreak -echo ');

Then you can test it and see what's going on.

Meanwhile, I'll check to see how difficult it is to extract the editing feature from its function and turn it into a generic readline replacement to use for all purposes. That can be the ultimate solution.

OK, I've replaced the readlines with my homemade, fancy, dependency-less readline :)

I think it should be fine for you now.

You homemade, fancy, dependency-less readline magic_readline() function is working flawlessly. Thank you very much.