src/app/config/config.rs

be4224817b612a60266af4f70f7e6836e60d0e9c
youtube-tui/src/app/config/config.rs history · blame · raw

44 lines · 1072 bytes

 1use std::error::Error;
 2
 3use super::{commands::CommandsConfig, MainConfig, PageCommandsConfig, KeybindingsConfig};
 4use crate::traits::ConfigItem;
 5
 6#[derive(Clone, Debug)]
 7pub struct Config {
 8    pub commands: CommandsConfig,
 9    pub main: MainConfig,
10    pub page_commands: PageCommandsConfig,
11    pub keybindings: KeybindingsConfig,
12}
13
14impl Default for Config {
15    fn default() -> Self {
16        Self {
17            commands: CommandsConfig::default(),
18            main: MainConfig::default(),
19            page_commands: PageCommandsConfig::default(),
20            keybindings: KeybindingsConfig::default(),
21        }
22    }
23}
24
25impl Config {
26    pub fn load() -> Result<Self, Box<dyn Error>> {
27        Ok(Self {
28            main: MainConfig::load()?,
29            commands: CommandsConfig::load()?,
30            page_commands: PageCommandsConfig::load()?,
31            keybindings: KeybindingsConfig::load()?.into(),
32        })
33    }
34}
35
36pub struct EnvVar {
37    pub url: Option<String>,
38}
39
40impl Default for EnvVar {
41    fn default() -> Self {
42        Self { url: None }
43    }
44}