hanslub42 / rlwrap

A readline wrapper
GNU General Public License v2.0
2.53k stars 149 forks source link

is it possible to exit rlwrap with escape #158

Closed nkh closed 1 year ago

nkh commented 2 years ago

I'd to be able to press 'escape' to quit from: r=$(rlwrap -o cat) as if the user pressed return with no input, is that possible?

hanslub42 commented 1 year ago

This is difficult or impossible. When you press the left arrow key, your terminall actually sends Esc [ A That is why readline uses Esc as a prefix key

Rebinding key combinations like Esc [ A is actually quite easy by changing your .inputrc:

"\e[A":kill-whole-line

but trying to rebind Esc itself doesn't work:

 "\e":kill-whole-line # won't work

And even if it would, it would disable the arrow keys entirely, after whihc using rlwrap is rather pointless

nkh commented 1 year ago

I have this code that handles keyboard input, in the program that uses rlwrap for some specific input, it handles the escape key and arrow keys. thank you for the explanation about rebinding via .inputrc but I ws wondering if rlwrap was able to do it by itself.

https://github.com/nkh/ftl/blob/main/config/ftl/etc/core/keyboard

hanslub42 commented 1 year ago

My hunch is that, if bash's read can do it, rlwrap ought to be able as well, as both rely on readline for the heavy lifting. I just can't figure out how (without interfering with the arrow keys)

I would think that a prefix key should be bindable just like any other key (if readline doesn't see anything coming within timeout millisecs (500 by default) it will assume that the prefix key itself is meant. But I don't see that happening......

Google finds some similar questions, but never any answer.

nkh commented 1 year ago

I made a short video, I'm more than certainly the one doing something wrong or not understanding how I should ue it. I thought this would make things a bit clearer while some solution emerges from somewhere :)

https://user-images.githubusercontent.com/45409/197183042-58d09716-5e71-421c-856a-6633c1a2c345.mp4