Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
dcampbell24 opened this issue Jul 7, 2016 · 8 comments
Open

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

dcampbell24 opened this issue Jul 7, 2016 · 8 comments

Comments

@dcampbell24
Copy link
Contributor

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

@MovingtoMars
Copy link
Owner

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?

@iamcodemaker
Copy link
Contributor

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
Copy link
Contributor

How do other readline libs handle this?

@iamcodemaker
Copy link
Contributor

Created a PR for this: #42

@MovingtoMars
Copy link
Owner

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.

@iamcodemaker
Copy link
Contributor

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

@MovingtoMars
Copy link
Owner

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.

@iamcodemaker
Copy link
Contributor

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

MovingtoMars pushed a commit that referenced this issue May 6, 2017
This is done by returning an `io::Error` with `ErrorKind::Interrupted`.

Issue: #4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants