2

I'm using readline in an application that follows the input realtime. I don't want to allow the user to press Enter, Control + J, or any other equivalent, and thus unintentionally clearing the field.

I'm actually forwarding the keys myself, so I can catch and prevent certain key inputs, but I don't think this is the way to go because reverse search (Control - R) must also be handled.

I've looked over the gnu docs, but haven't found anything useful.

My code is similar to this https://github.com/ulfalizer/readline-and-ncurses

vise
  • 12,713
  • 11
  • 52
  • 64
  • I'm no expert, but does anything in the [Alternative Interface](http://www.delorie.com/gnu/docs/readline/rlman_41.html) help? – JAL Sep 22 '16 at 14:06
  • Thanks for the link, unfortunately not. – vise Sep 22 '16 at 14:48

1 Answers1

1

You can inhibit this keys configuring key bindings in the initialization file of libreadline :

  1. in ~/.inputrc to configure for current user
  2. in /etc/inputrc to configure for all users.

To inhibit Enter and Control+J, you could add to the initialization file :

RETURN:
C-J:

If you prefer you can do this programmatically using rl_unbind_key, adding to your code :

rl_unbind_key('\r'); // unbind Enter
rl_unbind_key('\n'); // unbind Control+J
mpromonet
  • 11,326
  • 43
  • 62
  • 91