sql_cli/ui/state/
tui_state.rs

1#[derive(Clone)]
2pub enum SelectionMode {
3    Normal,
4    Column,
5    Block,
6    Visual,
7}
8
9#[derive(Clone)]
10pub struct FilterState {
11    pub active: bool,
12    pub pattern: String,
13    pub cursor_pos: usize,
14}
15
16#[derive(Clone)]
17pub struct FuzzyFilterState {
18    pub active: bool,
19    pub pattern: String,
20    pub cursor_pos: usize,
21}
22
23#[derive(Clone)]
24pub struct ColumnSearchState {
25    pub active: bool,
26    pub column_index: usize,
27    pub pattern: String,
28    pub cursor_pos: usize,
29    pub results: Vec<usize>,
30    pub current_match: usize,
31}
32
33#[derive(Clone)]
34pub struct SearchState {
35    pub pattern: String,
36    pub current_match: Option<(usize, usize)>, // (row, col)
37    pub matches: Vec<(usize, usize)>,
38    pub match_index: usize,
39}
40
41#[derive(Clone)]
42pub struct CompletionState {
43    pub items: Vec<String>,
44    pub selected_index: usize,
45    pub active: bool,
46    pub prefix_len: usize,
47}
48
49pub struct HistoryState {
50    pub active: bool,
51    pub input: String,
52    pub cursor_pos: usize,
53}
54
55#[derive(Clone)]
56pub struct TuiState {
57    pub filter_state: FilterState,
58    pub fuzzy_filter_state: FuzzyFilterState,
59    pub column_search_state: ColumnSearchState,
60    pub search_state: SearchState,
61    pub completion_state: CompletionState,
62}
63
64impl Default for FilterState {
65    fn default() -> Self {
66        Self {
67            active: false,
68            pattern: String::new(),
69            cursor_pos: 0,
70        }
71    }
72}
73
74impl Default for FuzzyFilterState {
75    fn default() -> Self {
76        Self {
77            active: false,
78            pattern: String::new(),
79            cursor_pos: 0,
80        }
81    }
82}
83
84impl Default for ColumnSearchState {
85    fn default() -> Self {
86        Self {
87            active: false,
88            column_index: 0,
89            pattern: String::new(),
90            cursor_pos: 0,
91            results: Vec::new(),
92            current_match: 0,
93        }
94    }
95}
96
97impl Default for SearchState {
98    fn default() -> Self {
99        Self {
100            pattern: String::new(),
101            current_match: None,
102            matches: Vec::new(),
103            match_index: 0,
104        }
105    }
106}
107
108impl Default for CompletionState {
109    fn default() -> Self {
110        Self {
111            items: Vec::new(),
112            selected_index: 0,
113            active: false,
114            prefix_len: 0,
115        }
116    }
117}
118
119impl Default for HistoryState {
120    fn default() -> Self {
121        Self {
122            active: false,
123            input: String::new(),
124            cursor_pos: 0,
125        }
126    }
127}
128
129impl Default for TuiState {
130    fn default() -> Self {
131        Self {
132            filter_state: FilterState::default(),
133            fuzzy_filter_state: FuzzyFilterState::default(),
134            column_search_state: ColumnSearchState::default(),
135            search_state: SearchState::default(),
136            completion_state: CompletionState::default(),
137        }
138    }
139}