src/global/structs/status.rs

54 lines · 1461 bytes

 1use tui::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    /// if true, exit in the next iteration
19    pub exit: bool,
20    /// stores the area of the previously rendered frame
21    pub prev_frame: Option<Rect>,
22    /// stores global provider (yt/inv)
23    pub provider: Provider,
24    /// if provider is updated, lasts for 1 event loop
25    pub provider_updated: bool,
26    /// storage that is cleared every event loop
27    pub storage: CloneMap,
28}
29
30impl Key for Status {
31    type Value = Self;
32}
33
34impl Default for Status {
35    fn default() -> Self {
36        Self {
37            popup_opened: false,
38            search_filter_opened: false,
39            render_image: true,
40            command_capture: None,
41            exit: false,
42            prev_frame: None,
43            provider: Provider::YouTube,
44            provider_updated: false,
45            storage: TypeMap::custom(),
46        }
47    }
48}
49
50impl Status {
51    pub fn reset(&mut self) {
52        *self = Self::default();
53    }
54}