src/global/functions/run_command.rs
773 lines · 32216 bytes
6 symbols in this file
1use crate::{
2 config::{serde::KeyCodeSerde, *},
3 global::{functions::*, structs::*, traits::*},
4 load_configs,
5};
6use crossterm::event::{KeyEvent, KeyModifiers};
7use ratatui::{backend::CrosstermBackend, Terminal};
8use std::{
9 env,
10 error::Error,
11 fs,
12 io::Stdout,
13 process::{Command, Stdio},
14 sync::Arc,
15};
16use tui_additions::framework::Framework;
17
18/// runs text command - command from the command line (not TUI) which response is just a string
19pub fn text_command(command: &str) -> Option<String> {
20 let command_parts: Vec<&str> = command.split_ascii_whitespace().collect();
21
22 match command_parts.as_slice() {
23 ["help"] => Some(help_msg(
24 &CommandsRemapConfig::load(WriteConfig::Dont).unwrap(),
25 )),
26 ["version"] => Some(format!(
27 "{} {}",
28 env!("CARGO_PKG_NAME"),
29 env!("CARGO_PKG_VERSION")
30 )),
31 ["loadpage", page, ..] => {
32 // Validate loadpage commands from command line to prevent hanging in raw screen
33 match *page {
34 "popular" | "trending" | "watchhistory" | "feed" | "library" => {
35 if command_parts.len() != 2 {
36 return Some(format!("Usage: `loadpage {}`", page));
37 }
38 None // Let it proceed to TUI
39 }
40 "channel" | "video" | "playlist" => {
41 if command_parts.len() != 3 {
42 return Some(format!("Usage: `loadpage {} {{id/url}}`", page));
43 }
44 None // Let it proceed to TUI
45 }
46 "search" => {
47 if command_parts.len() < 3 {
48 return Some("Usage: `loadpage search {query}`".to_string());
49 }
50 None // Let it proceed to TUI
51 }
52 _ => Some(format!("Unknown page: `{}`", page)),
53 }
54 }
55 _ => {
56 // Check if this is a remapped command that would become a loadpage command
57 if let Some(remapped_cmd) = CommandsRemapConfig::load(WriteConfig::Dont)
58 .unwrap()
59 .get(&command_parts)
60 {
61 // If it remaps to a loadpage command, validate it
62 if remapped_cmd.starts_with("loadpage ") {
63 let remapped_parts: Vec<&str> = remapped_cmd.split_ascii_whitespace().collect();
64 if remapped_parts.len() >= 2 {
65 let page = remapped_parts[1];
66 match page {
67 "popular" | "trending" | "watchhistory" | "feed" | "library" => {
68 if command_parts.len() != 1 {
69 return Some(format!("Usage: `{}`", command_parts[0]));
70 }
71 }
72 "channel" | "video" | "playlist" => {
73 if command_parts.len() != 2 {
74 return Some(format!(
75 "Usage: `{} {{id/url}}`",
76 command_parts[0]
77 ));
78 }
79 }
80 "search" => {
81 if command_parts.len() < 2 {
82 return Some(format!(
83 "Usage: `{} {{query}}`",
84 command_parts[0]
85 ));
86 }
87 }
88 _ => {}
89 }
90 }
91 }
92 }
93 None
94 }
95 }
96}
97
98pub fn run_command(
99 command: &str,
100 framework: &mut Framework,
101 terminal: &mut Terminal<CrosstermBackend<Stdout>>,
102) {
103 command.split(";;").for_each(|single_command| {
104 run_single_command(
105 &single_command
106 .trim()
107 .split_ascii_whitespace()
108 .collect::<Vec<_>>(),
109 framework,
110 terminal,
111 )
112 });
113}
114
115/// runs a command in the TUI, returns true if its a loadpage command, false if not
116pub fn run_single_command(
117 command: &[&str],
118 framework: &mut Framework,
119 terminal: &mut Terminal<CrosstermBackend<Stdout>>,
120) {
121 // match a command splitted by space to a bunch of avaliable commands
122 match command {
123 [] => {}
124 ["bookmark", id] => match LocalStore::get_info(id) {
125 Some(item) => {
126 let library = framework.data.global.get_mut::<Library>().unwrap();
127 let _ = library.push(item);
128 *framework.data.global.get_mut::<Message>().unwrap() =
129 Message::Success(String::from("Bookmark added"))
130 }
131 None => {
132 *framework.data.global.get_mut::<Message>().unwrap() =
133 Message::Error(format!("Unknown item: {id}"))
134 }
135 },
136 ["unmark", id] => {
137 let library = framework.data.global.get_mut::<Library>().unwrap();
138
139 if library.remove(id) {
140 *framework.data.global.get_mut::<Message>().unwrap() =
141 Message::Success(String::from("Bookmark removed"))
142 } else {
143 *framework.data.global.get_mut::<Message>().unwrap() =
144 Message::Error(String::from("No item with that ID found"))
145 }
146 }
147 ["togglemark", id] => {
148 let library = framework.data.global.get_mut::<Library>().unwrap();
149 if library.remove(id) {
150 *framework.data.global.get_mut::<Message>().unwrap() =
151 Message::Success(String::from("Bookmark removed"))
152 } else {
153 run_single_command(&["bookmark", id], framework, terminal);
154 }
155 }
156 ["rmcache", id] => {
157 let res = LocalStore::rm_cache(id);
158 let data = paths::data_dir();
159 let _ = fs::remove_file(
160 data.join("info")
161 .join(id)
162 .with_extension("json"),
163 );
164 let _ = fs::remove_file(
165 data.join("thumbnails")
166 .join(id),
167 );
168 if res {
169 *framework.data.global.get_mut::<Message>().unwrap() =
170 Message::Success(String::from("Cache cleared"))
171 } else {
172 *framework.data.global.get_mut::<Message>().unwrap() =
173 Message::Error(String::from("Item not in cache, nothing changed"))
174 }
175 }
176 ["help"] => {
177 *framework.data.global.get_mut::<Message>().unwrap() = Message::Message(String::from(
178 "Avaliable commands can be viewed by running `youtube-tui help` in terminal",
179 ));
180 }
181 ["switchprovider"] => {
182 let status = framework.data.global.get_mut::<Status>().unwrap();
183
184 status.provider.rotate();
185 status.provider_updated = true;
186 *framework.data.global.get_mut::<Message>().unwrap() =
187 Message::Success(format!("Provider updated to {}", status.provider.as_str()));
188 update_provider(&mut framework.data);
189 }
190 // loads a given page
191 ["loadpage", page, ..] => {
192 let page = match *page {
193 "popular" => Some(Page::MainMenu(MainMenuPage::Popular)),
194 "trending" => Some(Page::MainMenu(MainMenuPage::Trending)),
195 "watchhistory" => Some(Page::MainMenu(MainMenuPage::History)),
196 "feed" => Some(Page::Feed),
197 "library" => Some(Page::MainMenu(MainMenuPage::Library)),
198 "channel" => {
199 if command.len() != 3 {
200 *framework.data.global.get_mut::<Message>().unwrap() =
201 Message::Message(String::from("Usage: `loadpage channel {id/url}`"));
202 return;
203 }
204
205 match from_channel_url(command[2]) {
206 Ok(id) => Some(Page::ChannelDisplay(ChannelDisplayPage {
207 id,
208 r#type: ChannelDisplayPageType::Main,
209 })),
210 Err(e) => {
211 *framework.data.global.get_mut::<Message>().unwrap() =
212 Message::Error(e);
213 return;
214 }
215 }
216 }
217 "video" => {
218 if command.len() != 3 {
219 *framework.data.global.get_mut::<Message>().unwrap() =
220 Message::Message(String::from("Usage: `loadpage video {id/url}`"));
221 return;
222 }
223
224 match from_video_url(command[2]) {
225 Ok(id) => Some(Page::SingleItem(SingleItemPage::Video(id))),
226 Err(e) => {
227 *framework.data.global.get_mut::<Message>().unwrap() =
228 Message::Error(e);
229 return;
230 }
231 }
232 }
233 "playlist" => {
234 if command.len() != 3 {
235 *framework.data.global.get_mut::<Message>().unwrap() =
236 Message::Message(String::from("Usage: `loadpage playlist {id/url}`"));
237 return;
238 }
239
240 match from_playlist_url(command[2]) {
241 Ok(id) => Some(Page::SingleItem(SingleItemPage::Playlist(id))),
242 Err(e) => {
243 *framework.data.global.get_mut::<Message>().unwrap() =
244 Message::Error(e);
245 return;
246 }
247 }
248 }
249 "search" => {
250 if command.len() == 2 {
251 *framework.data.global.get_mut::<Message>().unwrap() =
252 Message::Message(String::from("Usage: `search {query}`"));
253 return;
254 }
255
256 // search for a query, although the command is matched as an array, the original query can
257 // be reconstructed by joining the string with a space in between
258 let search = framework.data.state.get_mut::<Search>().unwrap();
259 search.query = command[2..].join(" ");
260 let cloned = search.clone();
261 Some(Page::Search(cloned))
262 }
263 _ => {
264 *framework.data.global.get_mut::<Message>().unwrap() =
265 Message::Error(format!("Unknown page: `{page}`"));
266 None
267 }
268 };
269
270 if let Some(page) = page {
271 framework
272 .data
273 .state
274 .get_mut::<Tasks>()
275 .unwrap()
276 .priority
277 .push(Task::LoadPage(page))
278 }
279 }
280 ["history", "back"] | ["back"] => {
281 let _ = framework.revert_last_history();
282 framework
283 .data
284 .state
285 .get_mut::<Tasks>()
286 .unwrap()
287 .priority
288 .push(Task::ClearPage);
289 framework
290 .data
291 .state
292 .get_mut::<Tasks>()
293 .unwrap()
294 .priority
295 .push(Task::RenderAll);
296 run_single_command(&["flush"], framework, terminal);
297 framework
298 .data
299 .global
300 .get_mut::<Status>()
301 .unwrap()
302 .render_image = true;
303 }
304 ["history", "clear"] => {
305 framework.clear_history();
306 }
307 ["flush"] => loop {
308 // runs all stacked actions
309 if let Some(tasks) = framework.data.state.get_mut::<Tasks>().unwrap().pop() {
310 let _res = tasks.run(framework, terminal);
311 continue;
312 }
313 break;
314 },
315 ["reload"] | ["r"] => {
316 framework
317 .data
318 .state
319 .get_mut::<Tasks>()
320 .unwrap()
321 .priority
322 .push(Task::Reload);
323 }
324 ["reload", "configs"] => {
325 *framework.data.global.get_mut::<Message>().unwrap() =
326 match load_configs(&mut framework.split_clean().0) {
327 Ok(()) => Message::Success(String::from("Config files have been reloaded")),
328 Err(e) => Message::Error(e.to_string()),
329 };
330 }
331 ["quit"] => {
332 framework.data.global.get_mut::<Status>().unwrap().exit = true;
333 }
334 ["hello", "world"] => {
335 let index = fake_rand_range(0, HELLO_WORLDS.len() as i64) as usize;
336 *framework.data.global.get_mut::<Message>().unwrap() =
337 Message::Message(format!("Line #{index}: {}", HELLO_WORLDS[index]));
338 }
339 ["version"] => {
340 *framework.data.global.get_mut::<Message>().unwrap() = Message::Message(format!(
341 "{} {}",
342 env!("CARGO_PKG_NAME"),
343 env!("CARGO_PKG_VERSION")
344 ));
345 }
346 ["run", ..] => {
347 let command = command[1..].join(" ");
348 *framework.data.global.get_mut::<Message>().unwrap() =
349 Message::Success(command.clone());
350 let shell = &framework.data.global.get::<MainConfig>().unwrap().shell;
351 let shell_flag = shell_flag(shell);
352 if let Ok(mut child) =
353 Command::new(shell)
354 .args([shell_flag, &command])
355 .stdout(Stdio::null())
356 .stderr(Stdio::null())
357 .spawn()
358 {
359 let _ = child.wait();
360 }
361 }
362 ["parrun", ..] => {
363 let command = command[1..].join(" ");
364 *framework.data.global.get_mut::<Message>().unwrap() =
365 Message::Success(command.clone());
366 let shell = &framework.data.global.get::<MainConfig>().unwrap().shell;
367 let shell_flag = shell_flag(shell);
368 let _ = Command::new(shell)
369 .args([shell_flag, &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
658/// Returns the appropriate shell flag for the given shell command.
659///
660/// On Windows, `cmd` and `cmd.exe` use `/C`, `powershell`/`pwsh` use `-Command`,
661/// and everything else (e.g., bash from Git for Windows) uses `-c`.
662/// On non-Windows platforms, always uses `-c`.
663fn shell_flag(shell: &str) -> &'static str {
664 #[cfg(target_os = "windows")]
665 {
666 let shell_lower = shell.to_lowercase();
667 if shell_lower == "cmd" || shell_lower == "cmd.exe" {
668 "/C"
669 } else if shell_lower.contains("powershell") || shell_lower.contains("pwsh") {
670 "-Command"
671 } else {
672 "-c"
673 }
674 }
675 #[cfg(not(target_os = "windows"))]
676 {
677 let _ = shell;
678 "-c"
679 }
680}
681
682const HELLO_WORLDS: &[&str] = &[
683 "printf(\"Hello World\")",
684 "std::cout << \"Hello World\"",
685 "DISPLAY \"Hello World\". .",
686 "printIn(\"Hello World\")",
687 "disp('Hello World')",
688 "System.Console.WriteLine(\"Hello World\")",
689 "console.lof 'Hello World'",
690 "WriteLn('Hello World')",
691 "print('Hello World')",
692 "main = putStrLn \"Hello World\"",
693 "writeln ('Hello, world.')",
694 "puts 'Hello World'",
695 "print(\"Hello World\")",
696 "db 'Hello World', 10, 0",
697 "cat('Hello World')",
698 "println('Hello World')",
699 "echo \"Hello World\"",
700 "System.out.println(\"Hello World\")",
701 "println('Hello World\")",
702 "printfn \"Hello World\"",
703 "(print \"Hello World\")",
704 "console.log(\"Hello World\")",
705 "BEGIN DISPLAY(\"Hello World\") END.",
706 "print \"Hello World\"",
707 "puts \"Hello World\"",
708 "console.log 'Hello World'",
709 "print *, \"Hello World\"",
710 "<h1>Hello World<\\h1>",
711];
712
713fn help_msg(cmdefines: &CommandsRemapConfig) -> String {
714 format!("\x1b[32mYouTube TUI commands\x1b[0m
715
716\x1b[37mfor more visit https://tui.siri.ws/youtube/commands.html\x1b[0m
717
718\x1b[91mUSAGE:\x1b[0m
719 youtube-tui (command)
720
721\x1b[91mINFORMATIONAL:\x1b[0m
722 \x1b[33mhelp\x1b[0m Display this message
723 \x1b[33mversion\x1b[0m Print version info and exit
724
725\x1b[91mLOADPAGE:
726\x1b[37mloadpage [page] loads the corresponding page\x1b[0m
727 \x1b[33mloadpage popular\x1b[0m Loads the popular videos page
728 \x1b[33mloadpage trending\x1b[0m Loads the trending videos page
729 \x1b[33mloadpage watchhistory\x1b[0m Loads the watch history page
730 \x1b[33mloadpage subscriptions\x1b[0m Loads the subscriptions page
731 \x1b[33mloadpage bookmarks\x1b[0m Loads the bookmarks page
732 \x1b[33mloadpage library\x1b[0m Loads the library (saved items) page
733 \x1b[33mloadpage feed\x1b[0m Loads the library (feed) page
734 \x1b[33mloadpage search [query]\x1b[0m Loads the search page with the given query
735 \x1b[33mloadpage video [identifier]\x1b[0m Loads the video item page
736 \x1b[33mloadpage playlist [identifier]\x1b[0m Loads the playlist item page
737 \x1b[33mloadpage channel [identifier]\x1b[0m Loads the channel item page
738
739\x1b[91mHISTORY:\x1b[0m
740 \x1b[33mhistory back\x1b[0m Revert back to previous state
741 \x1b[33mhistory clear\x1b[0m Clear all previously saved states, making the current state the original
742
743\x1b[91mUTILITY:\x1b[0m
744 \x1b[33mreload\x1b[0m Reloads the current page
745 \x1b[33mreload configs\x1b[0m Reload all config files
746 \x1b[33mflush\x1b[0m Run all tasks in queue immediately
747 \x1b[33mquit\x1b[0m Immediately exit
748 \x1b[33mrun [command]\x1b[0m Runs a system command (e.g. `run rm -rf / --no-preserve-root`)
749 \x1b[33mparrun [command]\x1b[0m Runs a system command non blocking (e.g. `run firefox example.com`)
750 \x1b[33mcopy [text]\x1b[0m Copies text to clipboard
751 \x1b[33mkey [keycode] [keymodifier]\x1b[0m Create a key input event
752 \x1b[33mecho [mode] [message]\x1b[0m Displays a message in message bar, mode: none, success, warn, error, mpv (can be overwritten by mpv player)
753
754\x1b[91mLIBRARY:\x1b[0m
755 \x1b[33mbookmark [id]\x1b[0m Bookmark item with ID (item must be already loaded)
756 \x1b[33munmark [id]\x1b[0m Remove bookmark item with ID
757 \x1b[33mtogglemark [id]\x1b[0m Toggle bookmark status
758 \x1b[33msub/sync [id or url]\x1b[0m Add channel to subscription, or sync an existing channel
759 \x1b[33munsub [id or url]\x1b[0m Remove channel from subscription
760 \x1b[33msyncall\x1b[0m Sync all subscriptions
761
762\x1b[91mMPV:\x1b[0m
763 \x1b[33mmpv prop [label]\x1b[0m Gets mpv property
764 \x1b[33mmpv sprop [label] [value]\x1b[0m Set mpv property
765 \x1b[33mmpv tprop [label] [value]\x1b[0m Toggle a yes/no property
766 \x1b[33mmpv [command]\x1b[0m Runs a libmpv command
767
768\x1b[91mCUSTOM COMMANDS:\x1b[0m
769\x1b[37mdefined in cmdefine.yml\x1b[30m
770{}
771
772\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"))
773}