Skip to main content

matchmaker/
message.rs

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