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

Feature suggestion: prompt timeouts #266

Open
leontoeides opened this issue Jul 1, 2023 · 2 comments
Open

Feature suggestion: prompt timeouts #266

leontoeides opened this issue Jul 1, 2023 · 2 comments

Comments

@leontoeides
Copy link

Thank you for this useful crate. Very nice attention to detail! I see there are lots of pending requests I hope this doesn't overwhelm you.

Just an idea: a timeout for the prompts. If the user does not respond within 1 minute, 10 minutes, 30 minutes, etc. the prompt will exit and return a None. This is useful for situations where someone may not be available to key something in, but the system has alternative (but less desirable) sources of information. For an automated process that can be guided by a user, if they're available

@Gordon01
Copy link
Contributor

This would require a cancellable https://docs.rs/console/latest/console/struct.Term.html#method.read_line, which, I believe is not trivial to implement. Do you have ideas on how this can be implemented?

@Tudmotu
Copy link

Tudmotu commented Feb 3, 2024

+1 for the feature request.

Personally I managed to solve this for Input using a thread and a mpsc::channel.

But when I try this with Password it seems Dialoguer is unable to pick up the inputs, and it just fails after the timeout.

@Gordon01 do you have any idea if that's solvable?

Here's an approximation of the code I have:

let (send, recv) = mpsc::channel();

thread::spawn(move || {
    let input = Input::new()
        .allow_empty(true)
        .with_prompt("Name")
        .interact_text()
        .unwrap();
    send.send(input).unwrap();
});

let res = match recv.recv_timeout(Duration::from_secs(60)) {
    Ok(s) => Ok(s),
    Err(_error) => {
        std::println!("");
        Err("Prompt timed out")
    }
};

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

3 participants