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    Print,
45    Reload,
46    Custom,
47}
48
49// ---------------------------------------------------------------------
50
51#[non_exhaustive]
52#[derive(Debug, strum_macros::Display, Clone)]
53pub enum RenderCommand<A: ActionExt> {
54    Action(Action<A>),
55    Mouse(MouseEvent),
56    Resize(Rect),
57    #[cfg(feature = "bracketed-paste")]
58    Paste(String),
59    HeaderTable(HeaderTable),
60    Ack,
61    Tick,
62    Refresh,
63    QuitEmpty,
64}
65
66impl<A: ActionExt> From<Action<A>> for RenderCommand<A> {
67    fn from(action: Action<A>) -> Self {
68        RenderCommand::Action(action)
69    }
70}
71
72impl<A: ActionExt> RenderCommand<A> {
73    pub fn quit() -> Self {
74        RenderCommand::Action(Action::Quit(1))
75    }
76}
77
78// ---------------------------------------------------------------------
79#[derive(Debug)]
80pub enum BindDirective<A: ActionExt> {
81    Bind(Trigger, Actions<A>),
82    PushBind(Trigger, Actions<A>),
83    Unbind(Trigger),
84    PopBind(Trigger),
85}