I use stty raw -echo
in my tcl terminal program.
What I want is to do some actions for only a few key press events such as Tab. For the rest of the key press events I want to delegate to rlwrap or other default handling program, such as ← to move cursor to left hand side and insert text in where the cursor is, or Ctrl+C to terminate the program. Is there a way to do it?

- 133,037
- 18
- 149
- 215

- 538
- 1
- 4
- 15
-
1probably not the way you're thinking, since delegating the responsibility across programs makes the terminal connection (and initialization) cumbersome. – Thomas Dickey Jan 17 '17 at 02:12
3 Answers
The latest GitHub version of rlwrap
has a bindable readline command rlwrap-direct-keypress
that can be bound (e.g. in your .inputrc
) to any key you want to pass on directly to your program, bypassing rlwrap
All other keys will still work as usual (e.g. moving the cursor) when editing an input line with readline

- 5,513
- 1
- 23
- 43
There is an option in stty that handles signals for you which is the isig
option.
Also, -opost
process "\n" to "\r\n" for you.
stty raw -echo isig
Another choice is to use explicit -icanon min 1 time 0
instead of raw
option.

- 538
- 1
- 4
- 15
Alas, terminal handling systems don't work in ways that make that easy. But it isn't impossible. The simplest mechanism I can think of (indeed, the only one that doesn't make me cringe at the thought) is to use some of the more advanced features of the Expect extension's interact
command.
In particular, interact
effectively connects the program spawn
ed by Expect to the outside world, yet you can also add patterns to allow extended behaviour.
package require Expect
spawn /your/program yourarguments...
interact {
"\t" {
# Do something special here as we've got a Tab
send "special special special\r"
}
}
You can use rlwrap on the spawned process:
spawn rlwrap /your/program yourarguments...

- 133,037
- 18
- 149
- 215
-
Thank you. But I didn't install Expect and I want to distribute the program. Not many have Expect installed I guess. Is there a way in tcl to put the program in background when you receive Ctrl+Z? – Herbert Jan 17 '17 at 17:14