Skip to main content

matchmaker/
message.rs

1use bitflags::bitflags;
2use crossterm::event::MouseEvent;
3use ratatui::layout::Rect;
4
5use crate::action::{Action, ActionExt};
6
7bitflags! {
8    #[derive(bitflags_derive::FlagsDisplay, bitflags_derive::FlagsFromStr, Debug, PartialEq, Eq, Hash, Clone, Copy, Default, PartialOrd, Ord)]
9    pub struct Event: u32 {
10        const Start        = 1 << 0;  // Lifecycle start
11        const Complete     = 1 << 1;  // Lifecycle end
12        const Synced       = 1 << 7;  // First completion of matcher
13        const Resynced     = 1 << 8;  // Matcher finished processing current state
14
15        const QueryChange  = 1 << 2;  // Input/query update
16        const CursorChange = 1 << 3;  // Cursor movement
17
18        const PreviewChange = 1 << 4; // Preview update
19        const OverlayChange = 1 << 5; // Overlay update
20        const PreviewSet    = 1 << 6; // Preview explicitly set
21
22        const Resize = 1 << 9;  // Window/terminal resize
23        const Refresh = 1 << 10; // Full redraw
24
25        const Pause  = 1 << 11; // Pause events
26        const Resume = 1 << 12; // Resume events
27    }
28}
29
30// ---------------------------------------------------------------------
31
32#[derive(Default, Debug, Copy, Clone, PartialEq, Eq)]
33#[repr(u8)]
34pub enum Interrupt {
35    #[default]
36    None,
37    Become,
38    Execute,
39    Print,
40    Reload,
41    Custom,
42}
43
44// ---------------------------------------------------------------------
45
46#[non_exhaustive]
47#[derive(Debug, strum_macros::Display, Clone)]
48pub enum RenderCommand<A: ActionExt> {
49    Action(Action<A>),
50    Mouse(MouseEvent),
51    Resize(Rect),
52    #[cfg(feature = "bracketed-paste")]
53    Paste(String),
54    HeaderColumns(Vec<ratatui::text::Text<'static>>),
55    Ack,
56    Tick,
57    Refresh,
58    QuitEmpty,
59}
60
61impl<A: ActionExt> From<&Action<A>> for RenderCommand<A> {
62    fn from(action: &Action<A>) -> Self {
63        RenderCommand::Action(action.clone())
64    }
65}
66
67impl<A: ActionExt> RenderCommand<A> {
68    pub fn quit() -> Self {
69        RenderCommand::Action(Action::Quit(1))
70    }
71}