tui_dispatch_core/debug/
actions.rs1#[derive(Debug, Clone, PartialEq, Eq)]
8pub enum DebugAction {
9 Toggle,
11 CopyFrame,
13 ToggleState,
15 ToggleMouseCapture,
17 InspectCell { column: u16, row: u16 },
19 CloseOverlay,
21 RequestCapture,
23}
24
25impl DebugAction {
26 pub const CMD_TOGGLE: &'static str = "debug.toggle";
28 pub const CMD_COPY_FRAME: &'static str = "debug.copy";
29 pub const CMD_TOGGLE_STATE: &'static str = "debug.state";
30 pub const CMD_TOGGLE_MOUSE: &'static str = "debug.mouse";
31 pub const CMD_CLOSE_OVERLAY: &'static str = "debug.close";
32
33 pub fn from_command(cmd: &str) -> Option<Self> {
35 match cmd {
36 Self::CMD_TOGGLE => Some(Self::Toggle),
37 Self::CMD_COPY_FRAME => Some(Self::CopyFrame),
38 Self::CMD_TOGGLE_STATE => Some(Self::ToggleState),
39 Self::CMD_TOGGLE_MOUSE => Some(Self::ToggleMouseCapture),
40 Self::CMD_CLOSE_OVERLAY => Some(Self::CloseOverlay),
41 _ => None,
42 }
43 }
44
45 pub fn command(&self) -> Option<&'static str> {
47 match self {
48 Self::Toggle => Some(Self::CMD_TOGGLE),
49 Self::CopyFrame => Some(Self::CMD_COPY_FRAME),
50 Self::ToggleState => Some(Self::CMD_TOGGLE_STATE),
51 Self::ToggleMouseCapture => Some(Self::CMD_TOGGLE_MOUSE),
52 Self::CloseOverlay => Some(Self::CMD_CLOSE_OVERLAY),
53 Self::InspectCell { .. } | Self::RequestCapture => None,
55 }
56 }
57}
58
59#[derive(Debug)]
64pub enum DebugSideEffect<A> {
65 ProcessQueuedActions(Vec<A>),
70
71 CopyToClipboard(String),
75
76 EnableMouseCapture,
80
81 DisableMouseCapture,
85}
86
87#[cfg(test)]
88mod tests {
89 use super::*;
90
91 #[test]
92 fn test_from_command() {
93 assert_eq!(
94 DebugAction::from_command("debug.toggle"),
95 Some(DebugAction::Toggle)
96 );
97 assert_eq!(
98 DebugAction::from_command("debug.copy"),
99 Some(DebugAction::CopyFrame)
100 );
101 assert_eq!(
102 DebugAction::from_command("debug.state"),
103 Some(DebugAction::ToggleState)
104 );
105 assert_eq!(DebugAction::from_command("unknown"), None);
106 }
107
108 #[test]
109 fn test_command_roundtrip() {
110 let actions = [
111 DebugAction::Toggle,
112 DebugAction::CopyFrame,
113 DebugAction::ToggleState,
114 DebugAction::ToggleMouseCapture,
115 DebugAction::CloseOverlay,
116 ];
117
118 for action in actions {
119 let cmd = action.command().expect("should have command");
120 let parsed = DebugAction::from_command(cmd).expect("should parse");
121 assert_eq!(parsed, action);
122 }
123 }
124}