src/global/structs/status.rs
68 lines · 1941 bytes
5 symbols in this file
1use ratatui::layout::Rect;
2use tui_additions::widgets::TextField;
3use typemap::{CloneMap, Key, TypeMap};
4
5use crate::config::Provider;
6
7/// a struct for storing different info, currently only stores one info
8#[derive(Clone)]
9pub struct Status {
10 /// is there is a popup opened
11 pub popup_opened: bool,
12 /// is search filter popup opened
13 pub search_filter_opened: bool,
14 /// to prevent rerendering the same image
15 pub render_image: bool,
16 /// the textfield for command capture
17 pub command_capture: Option<TextField>,
18 /// used for command history and stuff
19 pub command_history_index: Option<usize>,
20 /// currently editing command
21 pub command_editing_cache: String,
22 /// if true, exit in the next iteration
23 pub exit: bool,
24 /// stores the area of the previously rendered frame
25 pub prev_frame: Option<Rect>,
26 /// stores global provider (yt/inv)
27 pub provider: Provider,
28 /// if provider is updated, lasts for 1 event loop
29 pub provider_updated: bool,
30 /// storage that is cleared every event loop
31 pub storage: CloneMap,
32}
33
34impl Key for Status {
35 type Value = Self;
36}
37
38impl Default for Status {
39 fn default() -> Self {
40 Self {
41 popup_opened: false,
42 search_filter_opened: false,
43 render_image: true,
44 command_capture: None,
45 exit: false,
46 command_history_index: None,
47 command_editing_cache: String::new(),
48 prev_frame: None,
49 provider: Provider::YouTube,
50 provider_updated: false,
51 storage: TypeMap::custom(),
52 }
53 }
54}
55
56impl Status {
57 pub fn reset(&mut self) {
58 *self = Self::default();
59 }
60}
61
62impl Status {
63 pub fn reset_command_capture(&mut self) {
64 self.command_capture = Some(TextField::default());
65 self.command_history_index = None;
66 self.command_editing_cache = String::new();
67 }
68}