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 pub fn clear_searches() -> Self {
68 Self {
69 search_state: Some(SearchState::default()),
70 filter_state: Some(FilterState::default()),
71 fuzzy_filter_state: Some(FuzzyFilterState::default()),
72 clear_all_searches: true,
73 ..Default::default()
74 }
75 }
76
77 pub fn mode(mode: AppMode) -> Self {
79 Self {
80 mode: Some(mode),
81 ..Default::default()
82 }
83 }
84
85 pub fn and(mut self, other: StateChange) -> Self {
87 if other.mode.is_some() {
88 self.mode = other.mode;
89 }
90 if other.search_state.is_some() {
91 self.search_state = other.search_state;
92 }
93 if other.filter_state.is_some() {
94 self.filter_state = other.filter_state;
95 }
96 if other.fuzzy_filter_state.is_some() {
97 self.fuzzy_filter_state = other.fuzzy_filter_state;
98 }
99 if other.clear_all_searches {
100 self.clear_all_searches = true;
101 }
102 self
103 }
104}