src/app/config/page_commands.rs

2512b334b421431b5e8577ab9c3031350fcd71bd
youtube-tui/src/app/config/page_commands.rs history · blame · raw

72 lines · 2254 bytes

 1use std::collections::HashMap;
 2
 3use serde::{Deserialize, Serialize};
 4
 5use crate::traits::ConfigItem;
 6
 7#[derive(Debug, Clone, Serialize, Deserialize)]
 8pub struct PageCommandsConfig(pub HashMap<String, Vec<PageCommand>>);
 9
10impl PageCommandsConfig {
11    fn blank() -> Self {
12        Self(HashMap::default())
13    }
14}
15
16impl Default for PageCommandsConfig {
17    fn default() -> Self {
18        let mut out = Self::blank();
19
20        out.0.insert(
21            String::from("item_info:video"),
22            vec![
23                PageCommand::from("Watch video", "video_player"),
24                PageCommand::from("Play audio", "audio_player"),
25                PageCommand::from("Download video", "video_downloader"),
26                PageCommand::from("Download audio", "audio_downloader"),
27                PageCommand::from("Visit channel", "{goto_channel}"),
28                PageCommand::from("{mode}", "{toggle_mode}"),
29            ],
30        );
31
32        out.0.insert(
33            String::from("item_info:playlist"),
34            vec![
35                PageCommand::from("Switch view", "{switch_view}"),
36                PageCommand::from("Watch all", "video_player"),
37                PageCommand::from("Play all audio", "audio_player"),
38                PageCommand::from("Shuffle play all audio", "audio_playlist_shuffle"),
39                PageCommand::from(
40                    "Shuffle play all audio (loop)",
41                    "audio_playlist_shuffle_loop",
42                ),
43                PageCommand::from("Download all video", "video_downloader"),
44                PageCommand::from("Download all audio", "audio_downloader"),
45                PageCommand::from("Visit channel", "{goto_channel}"),
46                PageCommand::from("{mode}", "{toggle_mode}"),
47            ],
48        );
49
50        out
51    }
52}
53
54#[derive(Debug, Clone, Serialize, Deserialize)]
55pub struct PageCommand {
56    pub label: String,
57    pub command: String,
58}
59
60impl PageCommand {
61    fn from(label: &str, command: &str) -> Self {
62        Self {
63            label: label.to_string(),
64            command: command.to_string(),
65        }
66    }
67}
68
69impl ConfigItem<'_> for PageCommandsConfig {
70    type Struct = PageCommandsConfig;
71    const FILE_NAME: &'static str = "page_commands.yml";
72}