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
impl Point
Sourcepub fn new(x: u16, y: u16) -> Self
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§
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more