Point

Struct Point 

Source
pub struct Point {
    pub x: u16,
    pub y: u16,
}
Expand description

A point in the terminal. Starts from (0, 0)

Fields§

§x: u16§y: u16

Implementations§

Source§

impl Point

Source

pub fn new(x: u16, y: u16) -> Self

Examples found in repository?
examples/example.rs (line 32)
24    fn process_input(&mut self, state: &mut app::State, key_event: event::Key) {
25        match key_event {
26            Key::Esc => state.stop(),
27            Key::Char('\n') => {
28                let pos = state.cursor_position;
29
30                state
31                    .command()
32                    .push(cursor::Goto(Point::new(0, pos.y + 1)))
33                    .execute();
34            }
35
36            Key::Char('c') => state
37                .command()
38                .push(clear::All)
39                .push(cursor::Goto(Point::new(0, 0)))
40                .execute(),
41            Key::Char('p') => {
42                let pos = state.cursor_position;
43
44                state.command().push(pos).execute();
45            }
46
47            Key::Char('H') => state.command().push(cursor::Show).execute(),
48            Key::Char('h') => state.command().push(cursor::Hide).execute(),
49            Key::Char('m') => state.command().push("message ").execute(),
50            Key::Char('q') => state.change_scene(Box::new(QuitScene)),
51
52            Key::Char('s') => {
53                let size = state.size();
54
55                state.command().push(size).execute();
56            }
57
58            _ => {}
59        }
60
61        state.flush();
62    }
63
64    fn update(&mut self, state: &mut app::State) {
65        let size = state.size();
66
67        let pos = state.cursor_position;
68
69        let write_pos = Point::new(size.x - pos.to_string().len() as u16, size.y);
70
71        state
72            .command()
73            .push(cursor::Save)
74            .push(cursor::Goto(write_pos))
75            .push(clear::CurrentLine)
76            .push(color::Fg(color::AnsiValue(self.color)))
77            .push(pos)
78            .push(color::Fg(color::Reset))
79            .push(cursor::Restore)
80            .execute();
81
82        state.flush();
83
84        self.color = self.color.overflowing_add(1).0;
85    }
86}
87
88struct QuitScene;
89
90impl Scene for QuitScene {
91    fn init(&mut self, state: &mut app::State) {
92        state
93            .command()
94            .push(clear::All)
95            .push(cursor::Goto(Point::new(0, 0)))
96            .push("Press any key to exit. ")
97            .execute();
98
99        state.flush();
100    }

Trait Implementations§

Source§

impl Clone for Point

Source§

fn clone(&self) -> Point

Returns a duplicate 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 Display for Point

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Copy for Point

Auto Trait Implementations§

§

impl Freeze for Point

§

impl RefUnwindSafe for Point

§

impl Send for Point

§

impl Sync for Point

§

impl Unpin for Point

§

impl UnwindSafe for Point

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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,

Source§

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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
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.