src/global/functions/run_command.rs

676 lines · 28056 bytes

  1use crate::{
  2    config::{serde::KeyCodeSerde, *},
  3    global::{functions::*, structs::*, traits::*},
  4    load_configs,
  5};
  6use crossterm::event::{KeyEvent, KeyModifiers};
  7use home::home_dir;
  8use ratatui::{backend::CrosstermBackend, Terminal};
  9use std::{
 10    env,
 11    error::Error,
 12    fs,
 13    io::Stdout,
 14    process::{Command, Stdio},
 15    sync::Arc,
 16};
 17use tui_additions::framework::Framework;
 18
 19/// runs text command - command from the command line (not TUI) which response is just a string
 20pub fn text_command(command: &str) -> Option<String> {
 21    match command
 22        .split_ascii_whitespace()
 23        .collect::<Vec<_>>()
 24        .as_slice()
 25    {
 26        ["help"] => Some(help_msg(
 27            &CommandsRemapConfig::load(WriteConfig::Dont).unwrap(),
 28        )),
 29        ["version"] => Some(format!(
 30            "{} {}",
 31            env!("CARGO_PKG_NAME"),
 32            env!("CARGO_PKG_VERSION")
 33        )),
 34        _ => None,
 35    }
 36}
 37
 38pub fn run_command(
 39    command: &str,
 40    framework: &mut Framework,
 41    terminal: &mut Terminal<CrosstermBackend<Stdout>>,
 42) {
 43    command.split(";;").for_each(|single_command| {
 44        run_single_command(
 45            &single_command
 46                .trim()
 47                .split_ascii_whitespace()
 48                .collect::<Vec<_>>(),
 49            framework,
 50            terminal,
 51        )
 52    });
 53}
 54
 55/// runs a command in the TUI, returns true if its a loadpage command, false if not
 56pub fn run_single_command(
 57    command: &[&str],
 58    framework: &mut Framework,
 59    terminal: &mut Terminal<CrosstermBackend<Stdout>>,
 60) {
 61    // match a command splitted by space to a bunch of avaliable commands
 62    match command {
 63        [] => {}
 64        ["bookmark", id] => {
 65            match (|| -> Result<Item, Box<dyn Error>> {
 66                Ok(serde_json::from_str(&fs::read_to_string(
 67                    home_dir()
 68                        .unwrap()
 69                        .join(format!(".cache/youtube-tui/info/{id}.json")),
 70                )?)?)
 71            })() {
 72                Ok(item) => {
 73                    let library = framework.data.global.get_mut::<Library>().unwrap();
 74                    let _ = library.push(item);
 75                    let _ = library.save();
 76                    *framework.data.global.get_mut::<Message>().unwrap() =
 77                        Message::Success(String::from("Bookmark added"))
 78                }
 79                Err(e) => {
 80                    *framework.data.global.get_mut::<Message>().unwrap() =
 81                        Message::Error(format!("Unknown item: {e}"))
 82                }
 83            }
 84        }
 85        ["unmark", id] => {
 86            let library = framework.data.global.get_mut::<Library>().unwrap();
 87
 88            if library.remove(id) {
 89                let _ = library.save();
 90                *framework.data.global.get_mut::<Message>().unwrap() =
 91                    Message::Success(String::from("Bookmark removed"))
 92            } else {
 93                *framework.data.global.get_mut::<Message>().unwrap() =
 94                    Message::Error(String::from("No item with that ID found"))
 95            }
 96        }
 97        ["togglemark", id] => {
 98            let library = framework.data.global.get_mut::<Library>().unwrap();
 99            if library.remove(id) {
100                let _ = library.save();
101                *framework.data.global.get_mut::<Message>().unwrap() =
102                    Message::Success(String::from("Bookmark removed"))
103            } else {
104                run_single_command(&["bookmark", id], framework, terminal);
105            }
106        }
107        ["help"] => {
108            *framework.data.global.get_mut::<Message>().unwrap() = Message::Message(String::from(
109                "Avaliable commands can be viewed by running `youtube-tui help` in terminal",
110            ));
111        }
112        ["switchprovider"] => {
113            let status = framework.data.global.get_mut::<Status>().unwrap();
114
115            status.provider.rotate();
116            status.provider_updated = true;
117            *framework.data.global.get_mut::<Message>().unwrap() =
118                Message::Success(format!("Provider updated to {}", status.provider.as_str()));
119            update_provider(&mut framework.data);
120        }
121        // loads a given page
122        ["loadpage", page, ..] => {
123            let page = match *page {
124                "popular" => Some(Page::MainMenu(MainMenuPage::Popular)),
125                "trending" => Some(Page::MainMenu(MainMenuPage::Trending)),
126                "watchhistory" => Some(Page::MainMenu(MainMenuPage::History)),
127                "feed" => Some(Page::Feed),
128                "library" => Some(Page::MainMenu(MainMenuPage::Library)),
129                "channel" => {
130                    if command.len() == 2 {
131                        *framework.data.global.get_mut::<Message>().unwrap() =
132                            Message::Message(String::from("Usage: `loadpage channel {id/url}`"));
133                        return;
134                    }
135
136                    match from_channel_url(command[2]) {
137                        Ok(id) => Some(Page::ChannelDisplay(ChannelDisplayPage {
138                            id,
139                            r#type: ChannelDisplayPageType::Main,
140                        })),
141                        Err(e) => {
142                            *framework.data.global.get_mut::<Message>().unwrap() =
143                                Message::Error(e);
144                            return;
145                        }
146                    }
147                }
148                "video" => {
149                    if command.len() == 2 {
150                        *framework.data.global.get_mut::<Message>().unwrap() =
151                            Message::Message(String::from("Usage: `loadpage video {id/url}`"));
152                        return;
153                    }
154
155                    match from_video_url(command[2]) {
156                        Ok(id) => Some(Page::SingleItem(SingleItemPage::Video(id))),
157                        Err(e) => {
158                            *framework.data.global.get_mut::<Message>().unwrap() =
159                                Message::Error(e);
160                            return;
161                        }
162                    }
163                }
164                "playlist" => {
165                    if command.len() == 2 {
166                        *framework.data.global.get_mut::<Message>().unwrap() =
167                            Message::Message(String::from("Usage: `loadpage playlist {id/url}`"));
168                        return;
169                    }
170
171                    match from_playlist_url(command[2]) {
172                        Ok(id) => Some(Page::SingleItem(SingleItemPage::Playlist(id))),
173                        Err(e) => {
174                            *framework.data.global.get_mut::<Message>().unwrap() =
175                                Message::Error(e);
176                            return;
177                        }
178                    }
179                }
180                "search" => {
181                    if command.len() == 2 {
182                        *framework.data.global.get_mut::<Message>().unwrap() =
183                            Message::Message(String::from("Usage: `search {query}`"));
184                        return;
185                    }
186
187                    // search for a query, although the command is matched as an array, the original query can
188                    // be reconstructed by joining the string with a space in between
189                    let search = framework.data.state.get_mut::<Search>().unwrap();
190                    search.query = command[2..].join(" ");
191                    let cloned = search.clone();
192                    Some(Page::Search(cloned))
193                }
194                _ => {
195                    *framework.data.global.get_mut::<Message>().unwrap() =
196                        Message::Error(format!("Unknown page: `{page}`"));
197                    None
198                }
199            };
200
201            if let Some(page) = page {
202                framework
203                    .data
204                    .state
205                    .get_mut::<Tasks>()
206                    .unwrap()
207                    .priority
208                    .push(Task::LoadPage(page))
209            }
210        }
211        ["history", "back"] | ["back"] => {
212            let _ = framework.revert_last_history();
213            framework
214                .data
215                .state
216                .get_mut::<Tasks>()
217                .unwrap()
218                .priority
219                .push(Task::ClearPage);
220            framework
221                .data
222                .state
223                .get_mut::<Tasks>()
224                .unwrap()
225                .priority
226                .push(Task::RenderAll);
227            run_single_command(&["flush"], framework, terminal);
228            framework
229                .data
230                .global
231                .get_mut::<Status>()
232                .unwrap()
233                .render_image = true;
234        }
235        ["history", "clear"] => {
236            framework.clear_history();
237        }
238        ["flush"] => loop {
239            // runs all stacked actions
240            if let Some(tasks) = framework.data.state.get_mut::<Tasks>().unwrap().pop() {
241                let _res = tasks.run(framework, terminal);
242                continue;
243            }
244            break;
245        },
246        ["reload"] | ["r"] => {
247            framework
248                .data
249                .state
250                .get_mut::<Tasks>()
251                .unwrap()
252                .priority
253                .push(Task::Reload);
254        }
255        ["reload", "configs"] => {
256            *framework.data.global.get_mut::<Message>().unwrap() =
257                match load_configs(&mut framework.split_clean().0) {
258                    Ok(()) => Message::Success(String::from("Config files have been reloaded")),
259                    Err(e) => Message::Error(e.to_string()),
260                };
261        }
262        ["quit"] => {
263            framework.data.global.get_mut::<Status>().unwrap().exit = true;
264        }
265        ["hello", "world"] => {
266            let index = fake_rand_range(0, HELLO_WORLDS.len() as i64) as usize;
267            *framework.data.global.get_mut::<Message>().unwrap() =
268                Message::Message(format!("Line #{index}: {}", HELLO_WORLDS[index]));
269        }
270        ["version"] => {
271            *framework.data.global.get_mut::<Message>().unwrap() = Message::Message(format!(
272                "{} {}",
273                env!("CARGO_PKG_NAME"),
274                env!("CARGO_PKG_VERSION")
275            ));
276        }
277        ["run", ..] => {
278            let command = command[1..].join(" ");
279            *framework.data.global.get_mut::<Message>().unwrap() =
280                Message::Success(command.clone());
281            if let Ok(mut child) =
282                Command::new(&framework.data.global.get::<MainConfig>().unwrap().shell)
283                    .args(["-c", &command])
284                    .stdout(Stdio::null())
285                    .stderr(Stdio::null())
286                    .spawn()
287            {
288                let _ = child.wait();
289            }
290        }
291        ["parrun", ..] => {
292            let command = command[1..].join(" ");
293            *framework.data.global.get_mut::<Message>().unwrap() =
294                Message::Success(command.clone());
295            let _ = Command::new(&framework.data.global.get::<MainConfig>().unwrap().shell)
296                .args(["-c", &command])
297                .stdout(Stdio::null())
298                .stderr(Stdio::null())
299                .spawn();
300        }
301        #[cfg(feature = "clipboard")]
302        ["copy", ..] => {
303            set_clipboard(command[1..].join(" "));
304            *framework.data.global.get_mut::<Message>().unwrap() =
305                Message::Success(String::from("Copied to clipboad"));
306        }
307        #[cfg(not(feature = "clipboard"))]
308        ["copy", ..] => {
309            *framework.data.global.get_mut::<Message>().unwrap() = Message::Error(String::from(
310                "Feature `clipboard` is disabled and not compiled",
311            ));
312        }
313        ["sync", identifier] => {
314            let id = if identifier.len() == 24 {
315                identifier.to_string()
316            } else {
317                let splitted = identifier.split_once("/channel/");
318
319                match splitted {
320                    Some((_, actual_stuff)) if actual_stuff.len() >= 24 => {
321                        actual_stuff[0..24].to_string()
322                    }
323                    _ => {
324                        *framework.data.global.get_mut::<Message>().unwrap() =
325                            Message::Error(String::from("Invalid identifier: no channel ID found"));
326                        return;
327                    }
328                }
329            };
330
331            *framework.data.global.get_mut::<Message>().unwrap() =
332                Message::Message(String::from("Syncing..."));
333            terminal.draw(|frame| framework.render(frame)).unwrap();
334
335            let mainconfig = framework.data.global.get::<MainConfig>().unwrap();
336            let image_index = mainconfig.image_index;
337            let download_thumbnails = mainconfig.images.display();
338            let syncing = mainconfig.syncing;
339
340            let subscriptions = framework.data.global.get_mut::<Subscriptions>().unwrap();
341
342            let message =
343                match subscriptions.sync_one(&id, image_index, download_thumbnails, &syncing) {
344                    Ok(()) => Message::Success(String::from("Channel synced")),
345                    Err(e) => Message::Error(format!("Sync failed: {e}")),
346                };
347
348            if framework.data.state.get::<Page>().unwrap() == &Page::Feed {
349                let tasks = framework.data.state.get_mut::<Tasks>().unwrap();
350                tasks.priority.push(Task::Reload);
351                // tasks.priority.reload_render = false;
352                tasks.priority.push(Task::Custom(TaskFunction::new(Arc::new(
353                    move |framework| {
354                        *framework.data.global.get_mut::<Message>().unwrap() = message.clone();
355                    },
356                ))));
357                tasks.last.push(Task::RenderAll);
358            } else {
359                *framework.data.global.get_mut::<Message>().unwrap() = message;
360                framework
361                    .data
362                    .state
363                    .get_mut::<Tasks>()
364                    .unwrap()
365                    .priority
366                    .push(Task::RenderAll);
367            }
368        }
369        ["unsub", identifier] => {
370            let id = if identifier.len() == 24 {
371                identifier.to_string()
372            } else {
373                let splitted = identifier.split_once("/channel/");
374
375                match splitted {
376                    Some((_, actual_stuff)) if actual_stuff.len() >= 24 => {
377                        actual_stuff[0..24].to_string()
378                    }
379                    _ => {
380                        *framework.data.global.get_mut::<Message>().unwrap() =
381                            Message::Error(String::from("Invalid identifier: no channel ID found"));
382                        return;
383                    }
384                }
385            };
386
387            let message = if framework
388                .data
389                .global
390                .get_mut::<Subscriptions>()
391                .unwrap()
392                .remove_one(&id)
393            {
394                Message::Success(String::from("Unsubscribed from channel"))
395            } else {
396                Message::Error(String::from("Channel not found in subscriptions"))
397            };
398
399            if framework.data.state.get::<Page>().unwrap() == &Page::Feed {
400                let tasks = framework.data.state.get_mut::<Tasks>().unwrap();
401                tasks.priority.push(Task::Reload);
402                // tasks.priority.reload_render = false;
403                tasks.priority.push(Task::Custom(TaskFunction::new(Arc::new(
404                    move |framework| {
405                        *framework.data.global.get_mut::<Message>().unwrap() = message.clone();
406                    },
407                ))));
408                tasks.last.push(Task::RenderAll);
409            } else {
410                *framework.data.global.get_mut::<Message>().unwrap() = message;
411                framework
412                    .data
413                    .state
414                    .get_mut::<Tasks>()
415                    .unwrap()
416                    .priority
417                    .push(Task::RenderAll);
418            }
419        }
420        ["syncall"] => {
421            *framework.data.global.get_mut::<Message>().unwrap() =
422                Message::Message(String::from("Syncing..."));
423            terminal.draw(|frame| framework.render(frame)).unwrap();
424
425            let mainconfig = framework.data.global.get::<MainConfig>().unwrap();
426            let image_index = mainconfig.image_index;
427            let download_thumbnails = mainconfig.images.display();
428            let syncing = mainconfig.syncing;
429
430            let (success, failed, empty, cached) = framework
431                .data
432                .global
433                .get_mut::<Subscriptions>()
434                .unwrap()
435                .sync(image_index, download_thumbnails, syncing);
436
437            let message = Message::Success(format!(
438                "Subscriptions synced: {success} success{} | {failed} fail | {cached} cached",
439                if empty != 0 {
440                    format!(" (which {empty} empty)")
441                } else {
442                    String::new()
443                }
444            ));
445
446            if framework.data.state.get::<Page>().unwrap() == &Page::Feed {
447                let tasks = framework.data.state.get_mut::<Tasks>().unwrap();
448                tasks.priority.push(Task::Reload);
449                // tasks.priority.reload_render = false;
450                tasks.priority.push(Task::Custom(TaskFunction::new(Arc::new(
451                    move |framework| {
452                        *framework.data.global.get_mut::<Message>().unwrap() = message.clone();
453                    },
454                ))));
455                tasks.last.push(Task::RenderAll);
456            } else {
457                *framework.data.global.get_mut::<Message>().unwrap() = message;
458                framework
459                    .data
460                    .state
461                    .get_mut::<Tasks>()
462                    .unwrap()
463                    .priority
464                    .push(Task::RenderAll);
465            }
466        }
467        ["key", keycode, modifier] => {
468            let (keycodeserde, modifier) =
469                match (|| -> Result<(KeyCodeSerde, u8), Box<dyn Error>> {
470                    Ok((serde_yaml_ng::from_str(keycode)?, modifier.parse()?))
471                })() {
472                    Ok(stuff) => stuff,
473                    Err(e) => {
474                        *framework.data.global.get_mut::<Message>().unwrap() =
475                            Message::Error(format!("Cannot parse keycode: `{e}`"));
476                        return;
477                    }
478                };
479            let keycode = match keycodeserde.to_keycode() {
480                Some(code) => code,
481                None => {
482                    *framework.data.global.get_mut::<Message>().unwrap() =
483                        Message::Error("Unknown keycode".to_string());
484                    return;
485                }
486            };
487            let keymodifier = KeyModifiers::from_bits_truncate(modifier);
488            key_input(KeyEvent::new(keycode, keymodifier), framework, terminal)
489        }
490        #[cfg(feature = "mpv")]
491        ["mpv", "prop", property] => {
492            let res = framework
493                .data
494                .global
495                .get::<MpvWrapper>()
496                .unwrap()
497                .property(property.to_string());
498
499            *framework.data.global.get_mut::<Message>().unwrap() = match res {
500                Some(value) => Message::Message(format!("Value: `{value}`")),
501                None => Message::Error("No such property".to_string()),
502            };
503        }
504        #[cfg(feature = "mpv")]
505        ["mpv", "tprop", property] => {
506            let mpv = framework.data.global.get::<MpvWrapper>().unwrap();
507            let res = mpv.property(property.to_string());
508
509            let toset = match res {
510                Some(value) if value.as_str() == "yes" || value.as_str() == "true" => "no",
511                _ => "yes",
512            };
513
514            let res = mpv.set_property(property.to_string(), toset.to_string());
515            *framework.data.global.get_mut::<Message>().unwrap() = match res {
516                MpvResponse::Copy => Message::Mpv(format!("Set `{property}` to `{toset}`")),
517                MpvResponse::Error(e) => Message::Error(format!("MPV error: {e}")),
518                _ => unreachable!(),
519            };
520        }
521        #[cfg(feature = "mpv")]
522        ["mpv", "sprop", name, ..] => {
523            let value = command[3..].join(" ");
524            let res = framework
525                .data
526                .global
527                .get::<MpvWrapper>()
528                .unwrap()
529                .set_property(name.to_string(), value.clone());
530
531            *framework.data.global.get_mut::<Message>().unwrap() = match res {
532                // MpvResponse::Copy => Message::Mpv(format!("Set `{name}` to `{value}`")),
533                MpvResponse::Copy => return,
534                MpvResponse::Error(e) => Message::Mpv(format!("MPV error: {e}")),
535                _ => unreachable!(),
536            };
537        }
538        #[cfg(feature = "mpv")]
539        ["mpv", name, ..] => {
540            let res = framework.data.global.get::<MpvWrapper>().unwrap().command(
541                name.to_string(),
542                command[2..].iter().map(|s| s.to_string()).collect(),
543            );
544
545            *framework.data.global.get_mut::<Message>().unwrap() = match res {
546                // MpvResponse::Copy => Message::Mpv("MPV player OK.".to_string()),
547                MpvResponse::Copy => return,
548                MpvResponse::Error(e) => Message::Mpv(format!("MPV error: {e}")),
549                _ => unreachable!(),
550            };
551        }
552        #[cfg(not(feature = "mpv"))]
553        ["mpv", ..] => {
554            *framework.data.global.get_mut::<Message>().unwrap() =
555                Message::Error(String::from("Feature `mpv` is disabled and not compiled"));
556        }
557        ["echo", r#type, ..] => {
558            *framework.data.global.get_mut::<Message>().unwrap() = match *r#type {
559                "message" => Message::Message(command[2..].join(" ")),
560                "mpv" => Message::Mpv(command[2..].join(" ")),
561                "success" => Message::Success(command[2..].join(" ")),
562                "error" => Message::Error(command[2..].join(" ")),
563                "none" => Message::None,
564                _ => Message::Error(format!("Unknown type `{}`", r#type)),
565            }
566        }
567        _ => {
568            if let Some(cmd) = framework
569                .data
570                .global
571                .get_mut::<CommandsRemapConfig>()
572                .unwrap()
573                .get(command)
574            {
575                run_command(&cmd, framework, terminal);
576                return;
577            }
578
579            *framework.data.global.get_mut::<Message>().unwrap() =
580                Message::Error(format!("Unknown command: `{}`", command.join(" ")));
581        }
582    }
583}
584
585const HELLO_WORLDS: &[&str] = &[
586    "printf(\"Hello World\")",
587    "std::cout << \"Hello World\"",
588    "DISPLAY \"Hello World\".    .",
589    "printIn(\"Hello World\")",
590    "disp('Hello World')",
591    "System.Console.WriteLine(\"Hello World\")",
592    "console.lof 'Hello World'",
593    "WriteLn('Hello World')",
594    "print('Hello World')",
595    "main = putStrLn \"Hello World\"",
596    "writeln ('Hello, world.')",
597    "puts 'Hello World'",
598    "print(\"Hello World\")",
599    "db    'Hello World', 10, 0",
600    "cat('Hello World')",
601    "println('Hello World')",
602    "echo \"Hello World\"",
603    "System.out.println(\"Hello World\")",
604    "println('Hello World\")",
605    "printfn \"Hello World\"",
606    "(print \"Hello World\")",
607    "console.log(\"Hello World\")",
608    "BEGIN DISPLAY(\"Hello World\") END.",
609    "print \"Hello World\"",
610    "puts \"Hello World\"",
611    "console.log 'Hello World'",
612    "print *, \"Hello World\"",
613    "<h1>Hello World<\\h1>",
614];
615
616fn help_msg(cmdefines: &CommandsRemapConfig) -> String {
617    format!("\x1b[32mYouTube TUI commands\x1b[0m
618
619\x1b[37mfor more visit https://tui.siri.ws/youtube/commands.html\x1b[0m
620
621\x1b[91mUSAGE:\x1b[0m
622    youtube-tui (command)
623
624\x1b[91mINFORMATIONAL:\x1b[0m
625    \x1b[33mhelp\x1b[0m                            Display this message
626    \x1b[33mversion\x1b[0m                         Print version info and exit
627
628\x1b[91mLOADPAGE:
629\x1b[37mloadpage [page] loads the corresponding page\x1b[0m
630    \x1b[33mloadpage popular\x1b[0m                Loads the popular videos page
631    \x1b[33mloadpage trending\x1b[0m               Loads the trending videos page
632    \x1b[33mloadpage watchhistory\x1b[0m           Loads the watch history page
633    \x1b[33mloadpage subscriptions\x1b[0m          Loads the subscriptions page
634    \x1b[33mloadpage bookmarks\x1b[0m              Loads the bookmarks page
635    \x1b[33mloadpage library\x1b[0m                Loads the library (saved items) page
636    \x1b[33mloadpage feed\x1b[0m                   Loads the library (feed) page
637    \x1b[33mloadpage search [query]\x1b[0m         Loads the search page with the given query
638    \x1b[33mloadpage video [identifier]\x1b[0m     Loads the video item page
639    \x1b[33mloadpage playlist [identifier]\x1b[0m  Loads the playlist item page
640    \x1b[33mloadpage channel [identifier]\x1b[0m   Loads the channel item page
641
642\x1b[91mHISTORY:\x1b[0m
643    \x1b[33mhistory back\x1b[0m                    Revert back to previous state
644    \x1b[33mhistory clear\x1b[0m                   Clear all previously saved states, making the current state the original
645
646\x1b[91mUTILITY:\x1b[0m
647    \x1b[33mreload\x1b[0m                          Reloads the current page
648    \x1b[33mreload configs\x1b[0m                  Reload all config files
649    \x1b[33mflush\x1b[0m                           Run all tasks in queue immediately
650    \x1b[33mquit\x1b[0m                            Immediately exit
651    \x1b[33mrun [command]\x1b[0m                   Runs a system command (e.g. `run rm -rf / --no-preserve-root`)
652    \x1b[33mparrun [command]\x1b[0m                Runs a system command non blocking (e.g. `run firefox example.com`)
653    \x1b[33mcopy [text]\x1b[0m                     Copies text to clipboard
654    \x1b[33mkey [keycode] [keymodifier]\x1b[0m     Create a key input event
655    \x1b[33mecho [mode] [message]\x1b[0m           Dispalys a message in message bar, mode: none, success, warn, error, mpv (can be overwritten by mpv player)
656
657\x1b[91mLIBRARY:\x1b[0m
658    \x1b[33mbookmark [id]\x1b[0m                   Bookmark item with ID (item must be already loaded)
659    \x1b[33munmark [id]\x1b[0m                     Remove bookmark item with ID
660    \x1b[33mtogglemark [id]\x1b[0m                 Toggle bookmark status
661    \x1b[33msub/sync [id or url]\x1b[0m            Add channel to subscription, or sync an existing channel
662    \x1b[33munsub [id or url]\x1b[0m               Remove channel from subscription
663    \x1b[33msyncall\x1b[0m                         Sync all subscriptions
664
665\x1b[91mMPV:\x1b[0m
666    \x1b[33mmpv prop [label]\x1b[0m                Gets mpv property
667    \x1b[33mmpv sprop [label] [value]\x1b[0m       Set mpv property
668    \x1b[33mmpv tprop [label] [value]\x1b[0m       Toggle a yes/no property
669    \x1b[33mmpv [command]\x1b[0m                   Runs a libmpv command
670
671\x1b[91mCUSTOM COMMANDS:\x1b[0m
672\x1b[37mdefined in cmdefine.yml\x1b[30m
673{}
674
675\x1b[37mOnly load page and informational commands should be used from command line, the rest can only be used in (`:`) command mode inside the TUI.\x1b[0m", cmdefines.0.iter().map(|(key, value)| format!("   \x1b[33m{: <28}\x1b[0m     `{value}`", key)).collect::<Vec<_>>().join("\n"))
676}