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