src/config/commands_remap.rs
79 lines · 2877 bytes
1use serde::{Deserialize, Serialize};
2use std::collections::HashMap;
3use typemap::Key;
4
5use crate::global::traits::ConfigTrait;
6
7#[derive(Serialize, Deserialize, Clone)]
8pub struct CommandsRemapConfig(pub HashMap<String, String>);
9
10impl ConfigTrait for CommandsRemapConfig {
11 const LABEL: &'static str = "cmdefine";
12}
13
14impl Key for CommandsRemapConfig {
15 type Value = Self;
16}
17
18impl Default for CommandsRemapConfig {
19 fn default() -> Self {
20 Self(HashMap::from([
21 ("h".to_string(), "help".to_string()),
22 ("v".to_string(), "version".to_string()),
23 ("cp".to_string(), "copy".to_string()),
24 ("print".to_string(), "echo".to_string()),
25 ("popular".to_string(), "loadpage popular".to_string()),
26 ("trending".to_string(), "loadpage trending".to_string()),
27 (
28 "watchhistory".to_string(),
29 "loadpage watchhistory".to_string(),
30 ),
31 ("feed".to_string(), "loadpage feed".to_string()),
32 ("bookmarks".to_string(), "loadpage bookmarks".to_string()),
33 ("library".to_string(), "loadpage library".to_string()),
34 ("search".to_string(), "loadpage search".to_string()),
35 ("channel".to_string(), "loadpage channel".to_string()),
36 ("video".to_string(), "loadpage video".to_string()),
37 ("playlist".to_string(), "loadpage playlist".to_string()),
38 ("back".to_string(), "history back".to_string()),
39 ("r".to_string(), "reload".to_string()),
40 ("rc".to_string(), "reload configs".to_string()),
41 ("q".to_string(), "quit".to_string()),
42 ("x".to_string(), "quit".to_string()),
43 ("exit".to_string(), "quit".to_string()),
44 ("sub".to_string(), "sync".to_string()),
45 (
46 "tpause".to_string(),
47 "mpv tprop pause ;; echo success Toggled player pause".to_string(),
48 ),
49 (
50 "pause".to_string(),
51 "mpv sprop pause yes ;; echo mpv Player paused".to_string(),
52 ),
53 (
54 "resume".to_string(),
55 "mpv sprop pause no ;; echo mpv Player resumed".to_string(),
56 ),
57 (
58 "back".to_string(),
59 "mpv playlist-previous ;; echo mpv Skipped".to_string(),
60 ),
61 (
62 "next".to_string(),
63 "mpv playlist-next ;; echo mpv Skipped".to_string(),
64 ),
65 ]))
66 }
67}
68
69impl CommandsRemapConfig {
70 pub fn get(&self, cmd: &[&str]) -> Option<String> {
71 for i in (0..cmd.len() + 1).rev() {
72 if let Some(remapped) = self.0.get(&cmd[0..i].join(" ")) {
73 return Some(format!("{remapped} {}", cmd[i..cmd.len()].join(" ")));
74 }
75 }
76
77 None
78 }
79}