Skip to main content

matchmaker/
message.rs

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