1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
use crossterm::cursor; use std::io::Write; /// creates a Cmd representation which translate to actual tty commands #[derive(Debug, Clone, Copy)] pub enum Cmd { /// Move the cursor to x,y location MoveTo(usize, usize), /// show the cursor ShowCursor, } impl Cmd { /// execute the command to the supplied writable buffer (ie: stdout) pub fn execute(&self, w: &mut dyn Write) -> crossterm::Result<()> { match self { Cmd::MoveTo(x, y) => { crossterm::queue!(w, cursor::MoveTo(*x as u16, *y as u16)) } Cmd::ShowCursor => crossterm::queue!(w, cursor::Show), } } }