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

Implementing terminal::pause() functinality #39

Closed
GarkGarcia opened this issue Nov 6, 2018 · 7 comments
Closed

Implementing terminal::pause() functinality #39

GarkGarcia opened this issue Nov 6, 2018 · 7 comments
Assignees
Milestone

Comments

@GarkGarcia
Copy link

So apparently doing the equivalent of C's System('pause') in Rust is a bit harder than it should be, as you can see in this discussion.

I just thought that since the focus of this crate is cross-platform terminal functionality and this is such a common thing to do (Press any key to continue...), maybe it could get implemented as a simple function like terminal::pause() or something along this lines.

If you think pause() is a bit too specific, terminal::read_char() or stdin().read_char() would be nice too.

@GarkGarcia GarkGarcia changed the title Implementing pause/read functinality Implementing terminal::pause() functinality Nov 6, 2018
@TimonPost
Copy link
Member

Yea, seems a nice function to have. I'll investigate further into it.

@TimonPost TimonPost added this to the 0.5.0 milestone Nov 14, 2018
@TimonPost TimonPost self-assigned this Nov 14, 2018
@TimonPost
Copy link
Member

TimonPost commented Nov 21, 2018

I will make the follwing enum:

pub enum CloseType {
    OnKeyPress(u8),
    OnEnter,
    OnAnyKeyPress
}

the user will be able to call:

let terminal = terminal();
terminal.pause(CloseType::OnEnter);

If you have better names our ideas I like to hear it. I'll be releasing it this or next week.

@TimonPost
Copy link
Member

#47

@GarkGarcia
Copy link
Author

Seems fine to me!

@czy-29
Copy link

czy-29 commented Mar 10, 2023

How to achieve this capability for now? Four years have passed, and the terminal::pause function seems to have disappeared...

@TimonPost
Copy link
Member

For input, reading refer to poll and read functions in the docs. Also checkout the EventStream. You should be able to use this API to achieve waiting for input.

@c-vision
Copy link

c-vision commented Apr 5, 2024

use crossterm::event::{read, Event};

pub fn pause() {
    loop {
        match read().unwrap() {
            Event::Key(_event) => break,
            _ => continue,
        }
    }
}

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

4 participants