matchmaker/
message.rs

1use crossterm::event::MouseEvent;
2use ratatui::layout::Rect;
3use strum_macros::{Display, EnumString};
4
5use crate::{action::{Action, ActionExt, Exit}, render::Effect};
6
7#[derive(Debug, Hash, PartialEq, Eq, EnumString, Clone, Display)]
8#[strum(serialize_all = "lowercase")]
9#[non_exhaustive]
10pub enum Event {
11    Start,
12    Complete,
13    QueryChange,
14    CursorChange,
15    PreviewChange,
16    OverlayChange,
17    PreviewSet,
18    Synced,
19    Resize,
20    Refresh,
21    Pause,
22    Resume,
23    Custom(usize)
24}
25
26#[derive(Default, Debug, Clone)]
27#[non_exhaustive]
28pub enum Interrupt {
29    #[default]
30    None,
31    Become(String),
32    Execute(String),
33    Print(String),
34    Reload(String),
35    Custom(usize)
36}
37
38impl PartialEq for Interrupt {
39    fn eq(&self, other: &Self) -> bool {
40        std::mem::discriminant(self) == std::mem::discriminant(other)
41    }
42}
43
44impl Eq for Interrupt {}
45
46#[non_exhaustive]
47#[derive(Debug, strum_macros::Display, Clone)]
48pub enum RenderCommand<A: ActionExt> {
49    Action(Action<A>),
50    Input(char),
51    Mouse(MouseEvent),
52    Resize(Rect),
53    Effect(Effect),
54    Ack,
55    Tick,
56    Refresh
57}
58
59impl<A: ActionExt> From<&Action<A>> for RenderCommand<A> {
60    fn from(action: &Action<A>) -> Self {
61        RenderCommand::Action(action.clone())
62    }
63}
64
65impl<A: ActionExt> RenderCommand<A> {
66    pub fn quit() -> Self {
67        RenderCommand::Action(Action::Quit(Exit::default()))
68    }
69}