Struct textmode::blocking::Input

source ·
pub struct Input { /* private fields */ }
Expand description

Manages handling terminal input from stdin.

The primary interface provided is read_key. You can additionally configure the types of keypresses you are interested in through the parse_* methods. This configuration can be changed between any two calls to read_key.

Implementations§

source§

impl Input

source

pub fn new() -> Result<Self>

Creates a new Input instance containing a RawGuard instance.

Errors
  • Error::SetTerminalMode: failed to put the terminal into raw mode
source

pub fn new_without_raw() -> Self

Creates a new Input instance without creating a RawGuard instance.

source

pub fn take_raw_guard(&mut self) -> Option<RawGuard>

Removes the RawGuard instance stored in this Input instance and returns it. This can be useful if you need to manage the lifetime of the RawGuard instance separately.

source

pub fn parse_utf8(&mut self, parse: bool)

Sets whether read_key should try to produce String or Char keys when possible, rather than Bytes or Byte keys. Note that Bytes or Byte keys may still be produced if the input fails to be parsed as UTF-8. Defaults to true.

source

pub fn parse_ctrl(&mut self, parse: bool)

Sets whether read_key should produce Ctrl keys when possible, rather than Bytes or Byte keys. Defaults to true.

source

pub fn parse_meta(&mut self, parse: bool)

Sets whether read_key should produce Meta keys when possible, rather than producing the Escape key separately. Defaults to true.

source

pub fn parse_special_keys(&mut self, parse: bool)

Sets whether read_key should produce keys other than String, Char, Bytes, Byte, Ctrl, or Meta. Defaults to true.

source

pub fn parse_single(&mut self, parse: bool)

Sets whether read_key should produce individual Char or Byte keys, rather than combining them into String or Bytes keys when possible. When this is true, String and Bytes will never be returned, and when this is false, Char and Byte will never be returned. Defaults to true.

source

pub fn read_key(&mut self) -> Result<Option<Key>>

Reads a keypress from the terminal on stdin. Returns Ok(None) on EOF.

Errors
  • Error::ReadStdin: failed to read data from stdin

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 Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

const: unstable · source§

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

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

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

const: unstable · 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, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

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

Performs the conversion.
source§

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

§

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

The type returned in the event of a conversion error.
const: unstable · source§

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

Performs the conversion.