hanslub42 / rlwrap

A readline wrapper
GNU General Public License v2.0
2.59k stars 151 forks source link

Is multi word input possible #156

Closed nkh closed 2 years ago

nkh commented 2 years ago

running the man page example in a subshell order=$(rlwrap -pYellow -S 'Your pizza? ' -H past_orders -P Margherita -o cat)

I want a multi word "order": Margherita with extra everything

rlwrap doesn't accept space as input; I ran the same code with -c and was able to input multiple file names and a word but only one word

looked in the man page and googled around to no end

hanslub42 commented 2 years ago

I cannot reproduce this. When you say

rlwrap doesn't accept space as input;

... what exactly happens?

nkh commented 2 years ago

say that I clear the line, I type press "ABCDE" , only "ABCDE" are shown, so I can't type a multi word answer.

Let me know if I can run any test that can help

hanslub42 commented 2 years ago

I still don't get it, sorry. ABCDE is one word - what happens if you type AB CD E?

nkh commented 2 years ago

sorry, I edited it and disapeared !

if I type AB CD E: I get ABCDE, spaces are ignored

hanslub42 commented 2 years ago

I cannot reproduce. This is what I see:

$ order=$(rlwrap -pYellow -S 'Your pizza? ' -H past_orders -P Margherita -o cat)
Your pizza? AB CD E # this remains on screen after pressing ENTER
$ echo $order
AB CD E
$ order=$(rlwrap -pYellow -S 'Your pizza? ' -H past_orders -P Margherita -o cat)
Your pizza? AB CD E #after pressing the up arrow once
nkh commented 2 years ago

what can I do to help find the problem?

hanslub42 commented 2 years ago

First: make sure it is rlwrap-specific:

Then, only when this really turns out to be rlwrap-specific: re-compile rlwrap with the --enable-debug config option, call the compiled rlwrap with the --debug option and send me the resulting debug log /tmp/rlwrap.debug

nkh commented 2 years ago

test: I run in konsole + tmux, where the problem occurs, I tried with xterm + tmux and only xterm -> same problem test: order=$(head -n 1) ; echo you ordered: $order -> I get back my input, including the spaces

anything in my terminal setting/inputrc, ... that I can check?

I'll compile with debugging and come back with the information

hanslub42 commented 2 years ago

Before you do that, one more test:

$ rlwrap cat

Does this "eat" the spaces as well? If not - that would suggest that this is the same problem as #145

nkh commented 2 years ago

It does eat spaces! I will re-read #145 and try to understand what the problem is

nkh commented 2 years ago

@hanslub42 I'm confused. I read #145 but I can't understand how it is related, apart from an incompatibility with Bash, as the ticket is about tty settings not being restored upon leaving rlwrap and my problem is while I am still in rlwrap.

Does rlwrap set the tty and start some sub shell where the settings are changed upon entry?

Do I need to to wrap the command I use in a script and set the tty properly? and in that case to what?

hanslub42 commented 2 years ago

I need some time to investigate. rlwrap manupulates its terminal settings (e.g. the ECHO flag, using tcsetattr(), and the terminal's bracketed paste settings, by outputting special codes). Usually, rlwrap's input and output are the same terminal, so that it doesn't matter whether it manipulates that terminal via the input or the output filehandle. This has possibly made me complacent, manipulating the output filehandle even when it is not a tty. This would leave the terminal in a corrupt state when rlwrap runs in a pileline, or a $(...) context

That said, I know of no terminal setting that would make spaces unprintable. For a terminal, a space is just a character lijke Q or 5, so your problem is just as puzzling as when every letter would be printed except Q

hanslub42 commented 2 years ago

That said, I know of no terminal setting that would make spaces unprintable.

If you bind SPACE in your .inputrc that could make the space key inoperable.

nkh commented 2 years ago

I do have:

Space: magic-space

in my inputrc, tried without and "rlwrap cat" works as expected, I hope this helps.

hanslub42 commented 2 years ago

Ah, this explains the problem. Thanks for reporting back!

By the way, you can still enjoy your magic spaces by enclosing the relevant .inputrc line in a $if... $endif pair:

$if bash
  SPACE: magic-space
$endif