src/config/main.rs

db597a03bc7a1786d5261e8a55628da30193c775
youtube-tui/src/config/main.rs history · blame · raw

84 lines · 2166 bytes

 1use super::ConfigTrait;
 2use serde::{Deserialize, Serialize};
 3use std::collections::HashMap;
 4use typemap::Key;
 5
 6#[derive(Serialize, Deserialize, Clone)]
 7pub struct MainConfig {
 8    #[serde(default = "invidious_instance_default")]
 9    pub invidious_instance: String,
10    #[serde(default = "allow_unicode_default")]
11    pub allow_unicode: bool,
12    #[serde(default = "message_bar_default_default")]
13    pub message_bar_default: String,
14    #[serde(default = "images_default")]
15    pub images: Images,
16    #[serde(default = "image_index_default")]
17    // The image to download from the array of images provided by the invidious api
18    // 0 is usually `maxres` and 3 (default) is good enough for normal uses without having huge files sizes
19    // Check `https://{any invidious instance}/api/v1/videos/{any valid video id}` property videoThumbnails in Firefox dev tools to see it for yourself
20    pub image_index: usize,
21    #[serde(default)]
22    pub env: HashMap<String, String>,
23}
24
25impl Key for MainConfig {
26    type Value = Self;
27}
28
29impl Default for MainConfig {
30    fn default() -> Self {
31        Self {
32            invidious_instance: invidious_instance_default(),
33            allow_unicode: allow_unicode_default(),
34            message_bar_default: message_bar_default_default(),
35            images: images_default(),
36            image_index: image_index_default(),
37
38            env: HashMap::default(),
39        }
40    }
41}
42
43impl ConfigTrait for MainConfig {
44    const LABEL: &'static str = "main";
45}
46
47#[derive(Clone, Copy, Serialize, Deserialize, PartialEq, Eq)]
48pub enum Images {
49    r#None,
50    HalfBlocks,
51    Sixels,
52}
53
54impl Images {
55    pub fn display(&self) -> bool {
56        !(self == &Self::None)
57    }
58
59    pub fn use_sixels(&self) -> bool {
60        self == &Self::Sixels
61    }
62}
63
64// default functions
65
66fn invidious_instance_default() -> String {
67    String::from("https://invidious.sethforprivacy.com")
68}
69
70fn message_bar_default_default() -> String {
71    String::from("All good :)")
72}
73
74const fn images_default() -> Images {
75    Images::HalfBlocks
76}
77
78const fn image_index_default() -> usize {
79    4
80}
81
82const fn allow_unicode_default() -> bool {
83    false
84}