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

Hardcoded to use Ctrl+C instead of respecting stty setting #274

Open
crabdancing opened this issue Sep 23, 2024 · 2 comments
Open

Hardcoded to use Ctrl+C instead of respecting stty setting #274

crabdancing opened this issue Sep 23, 2024 · 2 comments

Comments

@crabdancing
Copy link

Describe the bug

Well-behaved raw terminal programs will ideally identify how the interrupt key is configured, and use that to determine what they listen for when mimicking interrupt behavior. Inquire currently seems to be hardcoded to listen to only Ctrl+C.

To Reproduce
Steps to reproduce the behavior:

stty intr ^Q
cargo run --example multiselect

Then hit Ctrl+Q.

Expected behavior

Should interrupt the selection.

@mikaelmello
Copy link
Owner

hey @crabdancing, good to know, I had never heard of that before!

do you have an idea on how to implement this in Rust? I'll take a deeper look when I find some time

@crabdancing
Copy link
Author

crabdancing commented Oct 1, 2024

Thanks for the response! ^w^ I know how to do it in termios. I've been trying to popularize a technique on doing it like this:

use std::io::{self, Read};
use std::os::unix::io::AsRawFd;
use termios::*;

fn main() {
    let stdin_fd = io::stdin().as_raw_fd();
    let original_term_config = Termios::from_fd(stdin_fd).unwrap();

    let interrupt_char = original_term_config.c_cc[VINTR];

    let mut raw_termios = original_term_config;
    cfmakeraw(&mut raw_termios);
    tcsetattr(stdin_fd, TCSANOW, &mut raw_termios).unwrap();

    println!("Press the interrupt character to exit...\r");

    let mut buffer = [0u8; 1];
    loop {
        io::stdin().read_exact(&mut buffer).unwrap();
        eprintln!("Got: {:?}\r", &buffer);
        if buffer[0] == interrupt_char {
            break;
        }
    }

    tcsetattr(stdin_fd, TCSANOW, &original_term_config).unwrap();
}

Not sure how to do it in crossterm. I opened an issue about it, but they have yet to get back to me. :P

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

No branches or pull requests

2 participants