#[non_exhaustive]
pub struct Input { pub frame_skip: bool, pub event: Option<Event>, }

Fields (Non-exhaustive)§

This struct is marked as non-exhaustive
Non-exhaustive structs could have additional fields added in future. Therefore, non-exhaustive structs cannot be constructed in external crates using the traditional Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.
§frame_skip: bool

Returns true if the next frame should be skipped due to the previous frame taking too long

§event: Option<Event>

Implementations§

source§

impl Input

source

pub fn read() -> Self

Wait to get an input. When raw mode is disabled, the input will only be registered after enter is pressed. Call enable_raw_mode() to avoid having to press enter

Examples found in repository?
examples/single-char-input.rs (line 13)
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
fn main() {
    keypress::enable_raw_mode();

    loop {
        if let Some(Event::Key(key_event)) = Input::read().exit_on_kb_interrupt().event {
            match key_event {
                KeyEvent {
                    code: KeyCode::Char(char),
                    ..
                } => printr!("You pressed the {} key!", char),
                KeyEvent {
                    code: KeyCode::Enter,
                    kind: KeyEventKind::Press,
                    ..
                } => printr!("You pressed enter!"),
                _ => (),
            }
        }
    }
}
source

pub fn sleep_for_input(dur: Duration) -> Self

Spend the given duration attempted to get a keyboard press. Returns None if no event found within time limit. This function will always take the given duration to execute, even if an event is captured sooner than intended

source

pub fn sleep_fps_and_get_input(fps: f32, elapsed: Duration) -> Self

sleep for 1/fps given the passed fps argument, taking away the pass elapsed value to account for however long it took your gameloop to run. The returned bool is true if elapsed was more than 1/fps, in which case you should attempt to skip the next frame the best that you can

This function is intended to be inserted into MainLoopRoot::sleep_and_get_input_data in gemini-engine

source

pub fn as_tuple(&self) -> (bool, Option<Event>)

Generate a tuple from the input. Ideal to plug into gemini-engine’s MainLoopRoot::sleep_and_get_input_data

source

pub fn exit_on_kb_interrupt(self) -> Self

If this input was a Ctrl+C (Keyboard Interrupt), exit immediately. Consumes the original Input but returns it immediately, so is intended to be used like this:

// Will get the input but exit the process if the input was `Ctrl+C`
let input = Input::read()
    .exit_on_kb_interrupt();
Examples found in repository?
examples/single-char-input.rs (line 13)
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
fn main() {
    keypress::enable_raw_mode();

    loop {
        if let Some(Event::Key(key_event)) = Input::read().exit_on_kb_interrupt().event {
            match key_event {
                KeyEvent {
                    code: KeyCode::Char(char),
                    ..
                } => printr!("You pressed the {} key!", char),
                KeyEvent {
                    code: KeyCode::Enter,
                    kind: KeyEventKind::Press,
                    ..
                } => printr!("You pressed enter!"),
                _ => (),
            }
        }
    }
}

Trait Implementations§

source§

impl Clone for Input

source§

fn clone(&self) -> Input

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for Input

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl RefUnwindSafe for Input

§

impl Send for Input

§

impl Sync for Input

§

impl Unpin for Input

§

impl UnwindSafe for Input

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.