-
Notifications
You must be signed in to change notification settings - Fork 178
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
Signal handling / listening #804
Comments
Did you try:
? |
isn't this for recognizing signal input on stdin ? I might've explained myself poorly. Currently, rustyline never yields, and remains ''stuck'' on waiting for input, what I'd like rustyline to do, is to listen for signals coming from another thread / task, something as simple as Yes, calling a SIGINT already closes the process, but it's brutal and it'd be better if rustyline could exit its loop properly. with that in mind, this idea could be expanded to other signals. |
Ok, use std::thread;
use std::time::Duration;
use rustyline::{Config, DefaultEditor, Result};
fn main() -> Result<()> {
env_logger::init();
let config = Config::builder().enable_signals(true).build();
let mut rl = DefaultEditor::with_config(config)?;
thread::spawn(|| {
thread::sleep(Duration::from_secs(5));
unsafe { libc::raise(libc::SIGINT) }
});
loop {
let result = rl.readline("> ");
match result {
Ok(line) => {
println!("Line: {line}");
}
Err(err) => {
println!("Err: {err:?}");
break Err(err);
}
}
}
} rustyline % RUST_LOG=rustyline=debug cargo run --example signal doesn't work.
So And while trying to rewrite this code in Rust: use std::io::{Error, Read};
use std::os::unix::net::UnixStream;
use signal_hook::consts::{SIGUSR1, SIGUSR2};
use signal_hook::low_level::{pipe, raise};
fn main() -> Result<(), Error> {
let (mut read, write) = UnixStream::pair()?;
pipe::register(SIGUSR1, write.try_clone()?)?;
pipe::register(SIGUSR2, write)?;
let signal = SIGUSR2;
raise(signal).unwrap();
let mut buff = [0];
read.read_exact(&mut buff)?;
println!("buff: {buff:?} / {signal}");
Ok(())
} https://docs.rs/signal-hook/latest/signal_hook/low_level/pipe/index.html
|
Current implementation of |
I mean yeah, if it feels more in tune with rustyline philosophy. Should the dev explicitly use an emulate method from the public api or should sending a "Ctrl-C" &str be recognized as actual Ctrl-C? |
Hi, I was wondering if the rustyline team was interested for help concerning signal handling ?
Currently, rustlyline only listens to SIGWINCH and it would be nice to have at least SIGINT, (that would solve #780).
I was thinking in doing it in similar way to linefeed where you specify a list of signals you'd want to listen (my main personnal need would be for SIGINT).
If so, would you be kind to indicate which approach would fit your philosophy better :
ATM, I've done quick modifications just to listen to another signal of your choice here.
thanks !
The text was updated successfully, but these errors were encountered: