liner icon indicating copy to clipboard operation
liner copied to clipboard

Make keyboard interrupts (e.g. SIGINT from Ctrl-c) work

Open dcampbell24 opened this issue 8 years ago • 8 comments

I think handling keyboard signals correctly is a key feature for liner to have, but don't know what work is required.

dcampbell24 avatar Jul 07 '16 00:07 dcampbell24

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?

MovingtoMars avatar Jul 10 '16 07:07 MovingtoMars

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.

iamcodemaker avatar Apr 20 '17 12:04 iamcodemaker

How do other readline libs handle this?

iamcodemaker avatar Apr 20 '17 12:04 iamcodemaker

Created a PR for this: #42

iamcodemaker avatar Apr 23 '17 18:04 iamcodemaker

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.

MovingtoMars avatar Apr 30 '17 08:04 MovingtoMars

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

iamcodemaker avatar Apr 30 '17 15:04 iamcodemaker

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.

MovingtoMars avatar Apr 30 '17 22:04 MovingtoMars

We should probably handle ctrl-z as well. I'll look into it when I have a some time.

iamcodemaker avatar May 01 '17 00:05 iamcodemaker