Struct Cursor

Source
pub struct Cursor { /* private fields */ }
Expand description

Cursor structure.

Implementations§

Source§

impl Cursor

Source

pub fn new( background: Rgb, position: Position, wrap_around: bool, get_direction: Option<fn(key: Key) -> Option<Direction>>, ) -> Self

Creates new cursor.

§Arguments

background - background color of the cell where cursor is placed. Use termion::color.

position - cursor start position.

wrap_around - should cursor be wrapped around or not.

get_direction - pointer to key handler function (optional). This function should translate key into cursor move direction. Function must return None if key is not handled. If function isn’t provided the default function is used.

fn get_direction_default(key: Key) -> Option<Direction> {
    match key {
        Key::Char('a') | Key::Left => Some(Direction::Left),
        Key::Char('s') | Key::Down => Some(Direction::Down),
        Key::Char('w') | Key::Up => Some(Direction::Up),
        Key::Char('d') | Key::Right => Some(Direction::Right),
        _ => None,
    }
}
§Examples
use termion::color;

const START_POSITION: Position = Position(1, 1);
let cursor = Cursor::new(color::Rgb(0, 0, 200), START_POSITION, true, None);

Auto Trait Implementations§

§

impl Freeze for Cursor

§

impl RefUnwindSafe for Cursor

§

impl Send for Cursor

§

impl Sync for Cursor

§

impl Unpin for Cursor

§

impl UnwindSafe for Cursor

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, U> TryFrom<U> for T
where U: Into<T>,

Source§

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>,

Source§

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.