liner
liner copied to clipboard
Make keyboard interrupts (e.g. SIGINT from Ctrl-c) work
I think handling keyboard signals correctly is a key feature for liner to have, but don't know what work is required.
Signal handling doesn't seem to be that well supported in Rust yet. chan-signal looks like the best option at the moment.
Maybe add a signal received Event
?
I don't think pressing ctrl-c will generate a signal. I think liner can just detect that c
was pressed when ctrl
was pressed. We just need a way to relay that to the caller.
How do other readline libs handle this?
Created a PR for this: #42
At least on Unix-like systems, the shell listens for signals just like any other program. The signals are generated by the terminal/TTY driver.
https://superuser.com/questions/288772/shell-sigkill-keybinding
The Control+[?] keybindings are actually handled by the tty driver and not by the shell, because as long as there is a process running in the foreground, input and output of your terminal will be forwarded directly to the process. The shell would never be able to act upon (or even see) your keypresses.
Also helpful: http://www.linusakesson.net/programming/tty/index.php
Of course, perhaps on Redox signal handling will be different. (I don't know how much this has been discussed among the Redox developers). However this does mean that, at least on non-Redox systems, we have to listen for Unix signals instead of detecting Ctrl+C (and so on) keypresses.
No signals are raised when ctrl-c
is pressed on my osx machine. I think this is because the terminal is in raw mode causing all key presses to be sent straight through to the program. See https://unix.stackexchange.com/questions/21752/what-s-the-difference-between-a-raw-and-a-cooked-device-driver
Oh, I see then. That is a bit confusing, since that means ctrl+c when editing a line is different to when some other program is running!
I'll merge the PR then.
We should probably handle ctrl-z
as well. I'll look into it when I have a some time.