Skip to main content

rite_tui/
msg.rs

1//! `Msg` and `Cmd`, the inputs and outputs of `update`.
2
3use crossterm::event::{KeyEvent, MouseEvent};
4use rite_runtime::{ExecEvent, UiCommand};
5
6/// Input to the pure [`update`] function.
7///
8/// Every state transition in the UI corresponds to exactly one `Msg`,
9/// which makes the audit surface a single enum.
10///
11/// [`update`]: crate::update::update
12#[derive(Debug)]
13pub enum Msg {
14    /// Key press from the terminal.
15    Key(KeyEvent),
16    /// Mouse event from the terminal (currently unused, reserved).
17    Mouse(MouseEvent),
18    /// Terminal resize.
19    Resize {
20        /// New width in cells.
21        cols: u16,
22        /// New height in cells.
23        rows: u16,
24    },
25    /// Timer tick for spinners and time-driven redraws.
26    Tick,
27    /// Event from the runtime executor. Boxed: it is far larger than the
28    /// other variants, and every message would otherwise be its size.
29    Exec(Box<ExecEvent>),
30    /// Explicit quit signal.
31    Quit,
32}
33
34/// Side effect produced by [`update`]. The runtime loop interprets these
35/// after every `update` call.
36///
37/// [`update`]: crate::update::update
38#[derive(Debug)]
39pub enum Cmd {
40    /// Send a command back to the executor thread.
41    SendCommand(UiCommand),
42    /// Stop the loop.
43    Quit,
44}