Commit 964b7d9b87
Unsigned
Layout: unified · split
Cargo.lock +62 −60
| @@ -304,6 +304,12 @@ dependencies = [ | |||
| 304 | "syn", | 304 | "syn", |
| 305 | ] | 305 | ] |
| 306 | 306 | ||
| 307 | [[package]] | ||
| 308 | name = "dunce" | ||
| 309 | version = "1.0.3" | ||
| 310 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 311 | checksum = "0bd4b30a6560bbd9b4620f4de34c3f14f60848e58a9b7216801afcb4c7b31c3c" | ||
| 312 | |||
| 307 | [[package]] | 313 | [[package]] |
| 308 | name = "dyn-clone" | 314 | name = "dyn-clone" |
| 309 | version = "1.0.10" | 315 | version = "1.0.10" |
| @@ -331,43 +337,6 @@ dependencies = [ | |||
| 331 | "cfg-if", | 337 | "cfg-if", |
| 332 | ] | 338 | ] |
| 333 | 339 | ||
| 334 | [[package]] | ||
| 335 | name = "execute" | ||
| 336 | version = "0.2.11" | ||
| 337 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 338 | checksum = "313431b1c5e3a6ec9b864333defee57d2ddb50de77abab419e4baedb6cdff292" | ||
| 339 | dependencies = [ | ||
| 340 | "execute-command-macro", | ||
| 341 | "execute-command-tokens", | ||
| 342 | "generic-array", | ||
| 343 | ] | ||
| 344 | |||
| 345 | [[package]] | ||
| 346 | name = "execute-command-macro" | ||
| 347 | version = "0.1.8" | ||
| 348 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 349 | checksum = "a5fbc65a0cf735106743f4c38c9a3671c1e734b5c2c20d21a3c93c696daa3157" | ||
| 350 | dependencies = [ | ||
| 351 | "execute-command-macro-impl", | ||
| 352 | ] | ||
| 353 | |||
| 354 | [[package]] | ||
| 355 | name = "execute-command-macro-impl" | ||
| 356 | version = "0.1.8" | ||
| 357 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 358 | checksum = "5109f6bc9cd57feda665da326f3f6c57e0498c8fe9f7d12d7b8abc96719ca91b" | ||
| 359 | dependencies = [ | ||
| 360 | "execute-command-tokens", | ||
| 361 | "quote", | ||
| 362 | "syn", | ||
| 363 | ] | ||
| 364 | |||
| 365 | [[package]] | ||
| 366 | name = "execute-command-tokens" | ||
| 367 | version = "0.1.6" | ||
| 368 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 369 | checksum = "8ba569491c70ec8471e34aa7e9c0b9e82bb5d2464c0398442d17d3c4af814e5a" | ||
| 370 | |||
| 371 | [[package]] | 340 | [[package]] |
| 372 | name = "exr" | 341 | name = "exr" |
| 373 | version = "1.5.2" | 342 | version = "1.5.2" |
| @@ -445,6 +414,16 @@ dependencies = [ | |||
| 445 | "percent-encoding", | 414 | "percent-encoding", |
| 446 | ] | 415 | ] |
| 447 | 416 | ||
| 417 | [[package]] | ||
| 418 | name = "fsio" | ||
| 419 | version = "0.4.0" | ||
| 420 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 421 | checksum = "dad0ce30be0cc441b325c5d705c8b613a0ca0d92b6a8953d41bd236dc09a36d0" | ||
| 422 | dependencies = [ | ||
| 423 | "dunce", | ||
| 424 | "rand", | ||
| 425 | ] | ||
| 426 | |||
| 448 | [[package]] | 427 | [[package]] |
| 449 | name = "futures" | 428 | name = "futures" |
| 450 | version = "0.3.25" | 429 | version = "0.3.25" |
| @@ -509,16 +488,6 @@ dependencies = [ | |||
| 509 | "slab", | 488 | "slab", |
| 510 | ] | 489 | ] |
| 511 | 490 | ||
| 512 | [[package]] | ||
| 513 | name = "generic-array" | ||
| 514 | version = "0.14.6" | ||
| 515 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 516 | checksum = "bff49e947297f3312447abdca79f45f4738097cc82b06e72054d2223f601f1b9" | ||
| 517 | dependencies = [ | ||
| 518 | "typenum", | ||
| 519 | "version_check", | ||
| 520 | ] | ||
| 521 | |||
| 522 | [[package]] | 491 | [[package]] |
| 523 | name = "getrandom" | 492 | name = "getrandom" |
| 524 | version = "0.2.8" | 493 | version = "0.2.8" |
| @@ -1107,6 +1076,12 @@ dependencies = [ | |||
| 1107 | "miniz_oxide", | 1076 | "miniz_oxide", |
| 1108 | ] | 1077 | ] |
| 1109 | 1078 | ||
| 1079 | [[package]] | ||
| 1080 | name = "ppv-lite86" | ||
| 1081 | version = "0.2.17" | ||
| 1082 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 1083 | checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de" | ||
| 1084 | |||
| 1110 | [[package]] | 1085 | [[package]] |
| 1111 | name = "proc-macro2" | 1086 | name = "proc-macro2" |
| 1112 | version = "1.0.49" | 1087 | version = "1.0.49" |
| @@ -1125,6 +1100,36 @@ dependencies = [ | |||
| 1125 | "proc-macro2", | 1100 | "proc-macro2", |
| 1126 | ] | 1101 | ] |
| 1127 | 1102 | ||
| 1103 | [[package]] | ||
| 1104 | name = "rand" | ||
| 1105 | version = "0.8.5" | ||
| 1106 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 1107 | checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" | ||
| 1108 | dependencies = [ | ||
| 1109 | "libc", | ||
| 1110 | "rand_chacha", | ||
| 1111 | "rand_core", | ||
| 1112 | ] | ||
| 1113 | |||
| 1114 | [[package]] | ||
| 1115 | name = "rand_chacha" | ||
| 1116 | version = "0.3.1" | ||
| 1117 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 1118 | checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" | ||
| 1119 | dependencies = [ | ||
| 1120 | "ppv-lite86", | ||
| 1121 | "rand_core", | ||
| 1122 | ] | ||
| 1123 | |||
| 1124 | [[package]] | ||
| 1125 | name = "rand_core" | ||
| 1126 | version = "0.6.4" | ||
| 1127 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 1128 | checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" | ||
| 1129 | dependencies = [ | ||
| 1130 | "getrandom", | ||
| 1131 | ] | ||
| 1132 | |||
| 1128 | [[package]] | 1133 | [[package]] |
| 1129 | name = "rayon" | 1134 | name = "rayon" |
| 1130 | version = "1.6.1" | 1135 | version = "1.6.1" |
| @@ -1211,6 +1216,15 @@ dependencies = [ | |||
| 1211 | "bytemuck", | 1216 | "bytemuck", |
| 1212 | ] | 1217 | ] |
| 1213 | 1218 | ||
| 1219 | [[package]] | ||
| 1220 | name = "run_script" | ||
| 1221 | version = "0.10.0" | ||
| 1222 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 1223 | checksum = "7fdc55b3a7ad58e02de47eaf7a854c6791c8421da48ff296c152317d3beaf230" | ||
| 1224 | dependencies = [ | ||
| 1225 | "fsio", | ||
| 1226 | ] | ||
| 1227 | |||
| 1214 | [[package]] | 1228 | [[package]] |
| 1215 | name = "ryu" | 1229 | name = "ryu" |
| 1216 | version = "1.0.12" | 1230 | version = "1.0.12" |
| @@ -1590,12 +1604,6 @@ dependencies = [ | |||
| 1590 | "unsafe-any", | 1604 | "unsafe-any", |
| 1591 | ] | 1605 | ] |
| 1592 | 1606 | ||
| 1593 | [[package]] | ||
| 1594 | name = "typenum" | ||
| 1595 | version = "1.16.0" | ||
| 1596 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 1597 | checksum = "497961ef93d974e23eb6f433eb5fe1b7930b659f06d12dec6fc44a8f554c0bba" | ||
| 1598 | |||
| 1599 | [[package]] | 1607 | [[package]] |
| 1600 | name = "unicode-bidi" | 1608 | name = "unicode-bidi" |
| 1601 | version = "0.3.8" | 1609 | version = "0.3.8" |
| @@ -1661,12 +1669,6 @@ version = "0.2.15" | |||
| 1661 | source = "registry+https://github.com/rust-lang/crates.io-index" | 1669 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| 1662 | checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426" | 1670 | checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426" |
| 1663 | 1671 | ||
| 1664 | [[package]] | ||
| 1665 | name = "version_check" | ||
| 1666 | version = "0.9.4" | ||
| 1667 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 1668 | checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" | ||
| 1669 | |||
| 1670 | [[package]] | 1672 | [[package]] |
| 1671 | name = "viuer" | 1673 | name = "viuer" |
| 1672 | version = "0.6.2" | 1674 | version = "0.6.2" |
| @@ -1949,11 +1951,11 @@ dependencies = [ | |||
| 1949 | "clipboard", | 1951 | "clipboard", |
| 1950 | "crossterm", | 1952 | "crossterm", |
| 1951 | "dyn-clone", | 1953 | "dyn-clone", |
| 1952 | "execute", | ||
| 1953 | "futures", | 1954 | "futures", |
| 1954 | "home", | 1955 | "home", |
| 1955 | "invidious", | 1956 | "invidious", |
| 1956 | "reqwest", | 1957 | "reqwest", |
| 1958 | "run_script", | ||
| 1957 | "serde", | 1959 | "serde", |
| 1958 | "serde_json", | 1960 | "serde_json", |
| 1959 | "serde_yaml", | 1961 | "serde_yaml", |
Cargo.toml +1 −1
| @@ -36,7 +36,7 @@ tokio = {version = "1.21", default-features = false} | |||
| 36 | futures = {version = "0.3", default-features = false} | 36 | futures = {version = "0.3", default-features = false} |
| 37 | reqwest = {version = "0.11", default-features = false} | 37 | reqwest = {version = "0.11", default-features = false} |
| 38 | serde_json = {version = "1.0", default-features = false} | 38 | serde_json = {version = "1.0", default-features = false} |
| 39 | execute = {version = "0.2", default-features = false} | 39 | run_script = { version = "0.10", default-features = false} |
| 40 | clipboard = {version = "0.5"} | 40 | clipboard = {version = "0.5"} |
| 41 | 41 | ||
| 42 | # tui-additions = {path = "../../Rust/Packages/tui-additions", default-features = false, features = ["framework", "widgets"]} | 42 | # tui-additions = {path = "../../Rust/Packages/tui-additions", default-features = false, features = ["framework", "widgets"]} |
src/global/functions/run_command.rs +23 −7
| @@ -6,11 +6,16 @@ use crate::{ | |||
| 6 | }, | 6 | }, |
| 7 | load_configs, | 7 | load_configs, |
| 8 | }; | 8 | }; |
| 9 | use std::{io::Stdout, thread}; | 9 | use std::{ |
| 10 | io::Stdout, | ||
| 11 | env, | ||
| 12 | thread, | ||
| 13 | }; | ||
| 14 | use run_script::ScriptOptions; | ||
| 10 | use tui::{backend::CrosstermBackend, Terminal}; | 15 | use tui::{backend::CrosstermBackend, Terminal}; |
| 11 | use tui_additions::framework::Framework; | 16 | use tui_additions::framework::Framework; |
| 12 | 17 | ||
| 13 | use super::{fake_rand_range, from_channel_url, from_playlist_url, from_video_url}; | 18 | use super::{fake_rand_range, from_channel_url, from_playlist_url, from_video_url, set_clipboard}; |
| 14 | 19 | ||
| 15 | /// runs text command - command from the command line (not TUI) which response is just a string | 20 | /// runs text command - command from the command line (not TUI) which response is just a string |
| 16 | pub fn text_command(command: &[&str]) -> Option<String> { | 21 | pub fn text_command(command: &[&str]) -> Option<String> { |
| @@ -243,15 +248,25 @@ pub fn run_command( | |||
| 243 | false | 248 | false |
| 244 | } | 249 | } |
| 245 | ["run", ..] => { | 250 | ["run", ..] => { |
| 246 | let command = &command[1..].join(" "); | 251 | let command = command[1..].join(" "); |
| 247 | *framework.data.global.get_mut::<Message>().unwrap() = | 252 | *framework.data.global.get_mut::<Message>().unwrap() = |
| 248 | Message::Success(command.clone()); | 253 | Message::Success(command.clone()); |
| 249 | let mut command = execute::command(command); | ||
| 250 | thread::spawn(move || { | 254 | thread::spawn(move || { |
| 251 | let _ = command.output(); | 255 | run_script::run(&command, &Vec::new(), &ScriptOptions::new()).unwrap(); |
| 252 | }); | 256 | }); |
| 253 | false | 257 | false |
| 254 | } | 258 | } |
| 259 | ["copy"] | ["cp"] => { | ||
| 260 | *framework.data.global.get_mut::<Message>().unwrap() = | ||
| 261 | Message::Message(String::from("Usage: copy [text]")); | ||
| 262 | false | ||
| 263 | } | ||
| 264 | ["copy", ..] | ["cp", ..] => { | ||
| 265 | set_clipboard(command[1..].join(" ")); | ||
| 266 | *framework.data.global.get_mut::<Message>().unwrap() = | ||
| 267 | Message::Success(String::from("Copied to clipboad")); | ||
| 268 | false | ||
| 269 | } | ||
| 255 | _ => { | 270 | _ => { |
| 256 | *framework.data.global.get_mut::<Message>().unwrap() = | 271 | *framework.data.global.get_mut::<Message>().unwrap() = |
| 257 | Message::Error(format!("Unknown command: `{}`", command.join(" "))); | 272 | Message::Error(format!("Unknown command: `{}`", command.join(" "))); |
| @@ -322,14 +337,15 @@ const HELP_MSG: &str = "\x1b[32mYouTube TUI commands\x1b[0m | |||
| 322 | \x1b[33mflush\x1b[0m Run all tasks in queue immediately | 337 | \x1b[33mflush\x1b[0m Run all tasks in queue immediately |
| 323 | \x1b[33mquit\x1b[0m Immediately exit | 338 | \x1b[33mquit\x1b[0m Immediately exit |
| 324 | \x1b[33mrun [command]\x1b[0m Runs a system command (e.g. `run firefox example.com`) | 339 | \x1b[33mrun [command]\x1b[0m Runs a system command (e.g. `run firefox example.com`) |
| 340 | \x1b[33mcopy [text]\x1b[0m Copies text to clipboard | ||
| 325 | 341 | ||
| 326 | \x1b[91mALT:\x1b[0m | 342 | \x1b[91mALT:\x1b[0m |
| 327 | \x1b[37malts links back to the original command\x1b[30m | 343 | \x1b[37malts links back to the original command\x1b[30m |
| 328 | |||
| 329 | \x1b[33m[page] (additional options)\x1b[0m `loadpage [page]` | 344 | \x1b[33m[page] (additional options)\x1b[0m `loadpage [page]` |
| 330 | \x1b[33mback\x1b[0m `history back` | 345 | \x1b[33mback\x1b[0m `history back` |
| 331 | \x1b[33mr\x1b[0m `reload` | 346 | \x1b[33mr\x1b[0m `reload` |
| 332 | \x1b[33mreload/r config/configs\x1b[0m `reload configs` | 347 | \x1b[33mreload/r config/configs\x1b[0m `reload configs` |
| 333 | \x1b[33mq, exit, x\x1b[0m `quit` | 348 | \x1b[33mq, exit, x\x1b[0m `quit` |
| 349 | \x1b[33mcp [text]\x1b[0m `copy [text]` | ||
| 334 | 350 | ||
| 335 | \x1b[37mOnly load page commands and informational commands can be used from command line, the rest can only be used in (`:`) command mode inside the TUI.\x1b[0m"; | 351 | \x1b[37mOnly load page and informational commands can be used from command line, the rest can only be used in (`:`) command mode inside the TUI.\x1b[0m"; |