src/global/functions/run_command.rs

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