simple_terminal_app/
lib.rs

1/// Module that contains the app and state. The app can be started from app::App::start.
2pub mod app;
3
4/// Module that contains the Scene-trait that is needed for creating scenes for the app.
5pub mod scene;
6
7/// Contains all the terminal commands as structs. Command.to_string() generates the ANSI escape code.
8pub mod commands {
9
10    /// Manipulating the cursor.
11    pub mod cursor {
12
13        pub use termion::cursor::{
14            BlinkingBar, BlinkingBlock, BlinkingUnderline, Down, Hide, HideCursor, Left, Restore,
15            Right, Save, Show, SteadyBar, SteadyBlock, SteadyUnderline, Up,
16        };
17
18        use crate::Point;
19
20        use std::fmt::Display;
21
22        pub struct Goto(pub Point);
23
24        impl Display for Goto {
25            fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
26                write!(f, "{}", termion::cursor::Goto(self.0.x + 1, self.0.y + 1))
27            }
28        }
29    }
30
31    /// Module for manipulating terminal colors.
32    pub mod color {
33        pub use termion::color::{
34            AnsiValue, Bg, Black, Blue, Cyan, Fg, Green, LightBlack, LightBlue, LightCyan,
35            LightGreen, LightMagenta, LightRed, LightWhite, LightYellow, Magenta, Red, Reset,
36            White, Yellow,
37        };
38    }
39
40    pub use termion::{clear, style};
41}
42
43/// A point in the terminal. Starts from (0, 0)
44#[derive(Clone, Copy)]
45pub struct Point {
46    pub x: u16,
47
48    pub y: u16,
49}
50
51impl Point {
52    // Creates a new point. Upper-left corner is (0, 0) and lower-right is state.size()
53    pub fn new(x: u16, y: u16) -> Self {
54        Self { x, y }
55    }
56}
57
58use std::fmt::Display;
59
60impl Display for Point {
61    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
62        write!(f, "({}, {})", self.x, self.y)
63    }
64}
65
66pub use termion::event;