1use std::sync::Arc;
2
3use crossterm::event::KeyEvent;
4use ratatui::{
5 layout::Size,
6 text::Line,
7};
8use tracexec_core::event::{
9 EventId,
10 TracerEventDetails,
11};
12
13use crate::{
14 backtrace_popup::BacktracePopupState,
15 copy_popup::CopyPopupState,
16 details_popup::DetailsPopupState,
17 error_popup::InfoPopupState,
18 query::Query,
19};
20
21#[derive(Debug)]
22pub enum Action {
23 Quit,
25 Render,
27 Resize(Size),
29 NextItem,
31 PrevItem,
32 PageDown,
33 PageUp,
34 PageLeft,
35 PageRight,
36 ScrollLeft,
37 ScrollRight,
38 ScrollToTop,
39 ScrollToBottom,
40 ScrollToStart,
41 ScrollToEnd,
42 ToggleFollow,
43 ToggleEnvDisplay,
44 ToggleCwdDisplay,
45 StopFollow,
46 ScrollToId(EventId),
47 ShrinkPane,
49 GrowPane,
50 SwitchLayout,
52 SwitchActivePane,
54 SetActivePopup(ActivePopup),
56 CancelCurrentPopup,
57 ShowCopyDialog(Arc<TracerEventDetails>),
59 CopyToClipboard {
60 target: CopyTarget,
61 event: Arc<TracerEventDetails>,
62 },
63 BeginSearch,
65 EndSearch,
66 ExecuteSearch(Query),
67 NextMatch,
68 PrevMatch,
69 HandleTerminalKeyPress(KeyEvent),
71 ShowBreakpointManager,
73 CloseBreakpointManager,
74 ShowHitManager,
75 HideHitManager,
76}
77
78impl Action {
79 pub fn show_error_popup<E: ToString>(title: String, error: E) -> Self {
80 Self::SetActivePopup(ActivePopup::InfoPopup(InfoPopupState::error(
81 title,
82 vec![Line::raw(error.to_string())],
83 )))
84 }
85}
86
87#[derive(Debug, Clone, Copy, PartialEq, Eq)]
88pub enum CopyTarget {
89 Line,
90 Commandline(SupportedShell),
91 CommandlineWithFullEnv(SupportedShell),
92 CommandlineWithStdio(SupportedShell),
93 CommandlineWithFds(SupportedShell),
94 Env,
95 Argv,
96 Filename,
97 SyscallResult,
98 EnvDiff,
99}
100
101#[derive(Debug, Clone, Copy, PartialEq, Eq)]
102pub enum SupportedShell {
103 Bash,
104 Sh,
105 Fish,
106}
107
108#[derive(Debug)]
109pub enum ActivePopup {
110 Help,
111 Backtrace(Box<BacktracePopupState>),
112 ViewDetails(DetailsPopupState),
113 CopyTargetSelection(CopyPopupState),
114 InfoPopup(InfoPopupState),
115}