1use crate::buffer::{AppMode, FilterState, FuzzyFilterState, SearchState};
4use crate::ui::state::shadow_state::SearchType;
5
6#[derive(Debug, Clone)]
8pub enum StateEvent {
9 ModeChanged { from: AppMode, to: AppMode },
11
12 SearchStarted { search_type: SearchType },
14
15 SearchEnded { search_type: SearchType },
17
18 SearchPatternUpdated {
20 search_type: SearchType,
21 pattern: String,
22 },
23
24 FilterToggled {
26 filter_type: FilterType,
27 active: bool,
28 },
29
30 DataViewUpdated,
32
33 ColumnOperation { op: ColumnOp },
35
36 ViewportChanged { row: usize, col: usize },
38}
39
40#[derive(Debug, Clone)]
41pub enum FilterType {
42 Regex,
43 Fuzzy,
44 Column,
45}
46
47#[derive(Debug, Clone)]
48pub enum ColumnOp {
49 Hide(usize),
50 Pin(usize),
51 Sort(usize),
52 Reset,
53}
54
55#[derive(Debug, Default, Clone)]
57pub struct StateChange {
58 pub mode: Option<AppMode>,
59 pub search_state: Option<SearchState>,
60 pub filter_state: Option<FilterState>,
61 pub fuzzy_filter_state: Option<FuzzyFilterState>,
62 pub clear_all_searches: bool,
63}
64
65impl StateChange {
66 #[must_use]
68 pub fn clear_searches() -> Self {
69 Self {
70 search_state: Some(SearchState::default()),
71 filter_state: Some(FilterState::default()),
72 fuzzy_filter_state: Some(FuzzyFilterState::default()),
73 clear_all_searches: true,
74 ..Default::default()
75 }
76 }
77
78 #[must_use]
80 pub fn mode(mode: AppMode) -> Self {
81 Self {
82 mode: Some(mode),
83 ..Default::default()
84 }
85 }
86
87 pub fn and(mut self, other: StateChange) -> Self {
89 if other.mode.is_some() {
90 self.mode = other.mode;
91 }
92 if other.search_state.is_some() {
93 self.search_state = other.search_state;
94 }
95 if other.filter_state.is_some() {
96 self.filter_state = other.filter_state;
97 }
98 if other.fuzzy_filter_state.is_some() {
99 self.fuzzy_filter_state = other.fuzzy_filter_state;
100 }
101 if other.clear_all_searches {
102 self.clear_all_searches = true;
103 }
104 self
105 }
106}