Module yacll::input

source ·
Expand description

Enums and structs for getting input from the user.

use yacll::{
    input::{
        Event,
        KeyCode,
    },
    Result, Yogurt,
};
use std::{
    time::Duration,
    thread::sleep,
};

fn main() -> Result<()> {
    let mut y = Yogurt::new();
    y.enter_alt()?;

    y.cursor_on(yacll::stylize::CursorAttr::Hidden)?;

    y.mv_print((0, 0), "press the any key to advance.")?;
    y.flush()?;
    y.block_event()?;

    y.mv_print((0, 1), "now press the q key in the next 10 seconds!")?;
    y.flush()?;
    match y.read_event(Duration::from_secs(10))? {
        Some(some) => if let Event::Key(ke) = some {
            if let KeyCode::Char('q') = ke.code {
                y.mv_print((0, 2), "you did it!")?;
            } else {
                y.mv_print((0, 2), "that's not q!")?;
            }
        } else {
            y.mv_print((0, 2), "that event isn't a key event!")?;
        }
        None => y.mv_print((0, 2), "you failed...")?,
    }
    y.flush()?;

    sleep(Duration::from_secs(3));

    y.cursor_off(yacll::stylize::CursorAttr::Hidden)?;

    y.leave_alt()?;
    Ok(())
}
// try running `$ cargo run --example=input` if you have the repository cloned!

Structs

A key event.
Possible key modifiers.
Represents a mouse event.

Enums

Possible events.
Represents possible keys.
Represents a keyboard event kind.