1

I want to bind terminal behavior to hotkeys without having to define escape sequences.

I understand readline binds to characters instead of actual key presses. Can it also bind to the lower level virtual keys? e.g. so I can use CTRL+LEFT_ARROW instead of whatever ascii escape sequence (^[^[D) my current terminal uses.

How can I achieve this behavior (doesn't have to be readline). I don't use X, just the Linux console and terminal text editors.

jiggunjer
  • 440
  • 1
  • 7
  • 13

1 Answers1

3

readline can't do that. Some applications can open a connection to the X server and detect X events (such as xev), but the readline library isn't one of those applications.

Call it a technical limitation. readline uses system interfaces (mostly POSIX termios) which can only read the characters sent by the terminal, and has no access to their internal state.

Thomas Dickey
  • 75,040
  • 9
  • 171
  • 268
  • I don't have a window server. Is this limitation by design or would it have technical reasons? – jiggunjer Feb 26 '17 at 07:42
  • @jiggunjer Yes, there's a technical reason: terminal applications receive characters as input, not keys. See [“Text mode application, running in a terminal” — “Input”](http://unix.stackexchange.com/questions/116629/how-do-keyboard-input-and-text-output-work/116630#116630). If you want to have access to key events, use X11. – Gilles 'SO- stop being evil' Feb 26 '17 at 21:27
  • @Gilles I am skeptical of the advice to install a graphics stack just to change the character-centric behavior of a terminal. While *terminal applications* such as bash receive characters, the *terminal itself* also receives "keys" from the keyboard. Instead of converting certain keys to characters and passing them on to the application (or ignoring them), I want to map terminal behavior/attribute modifiers to certain keys. Maybe there is a userland alternative to the `TERM=linux` console that does this. – jiggunjer Feb 27 '17 at 06:47
  • @jiggunjer A shell or text editor running in a terminal is an application. There is a mechanism to bypass the terminal interface and access the underlying hardware driver directly (svgalib) but I doubt that you'll find a shell or text editor that supports it, because everybody has moved to X since about 20 years agao. – Gilles 'SO- stop being evil' Feb 27 '17 at 12:20