Commit 964b7d9b87

964b7d9b87bf209c4b9a74d5dcd2a160cf0f671c

parent: af1b4fe68d

Unsigned

Siriusmart <71584876+Siriusmart@users.noreply.github.com> · 2023-01-12 19:45 UTC

fixed running commands with pipes `|` and cp

Layout: unified · split

Cargo.lock +62 −60
@@ -304,6 +304,12 @@ dependencies = [
304304 "syn",
305305]
306306
307[[package]]
308name = "dunce"
309version = "1.0.3"
310source = "registry+https://github.com/rust-lang/crates.io-index"
311checksum = "0bd4b30a6560bbd9b4620f4de34c3f14f60848e58a9b7216801afcb4c7b31c3c"
312
307313[[package]]
308314name = "dyn-clone"
309315version = "1.0.10"
@@ -331,43 +337,6 @@ dependencies = [
331337 "cfg-if",
332338]
333339
334[[package]]
335name = "execute"
336version = "0.2.11"
337source = "registry+https://github.com/rust-lang/crates.io-index"
338checksum = "313431b1c5e3a6ec9b864333defee57d2ddb50de77abab419e4baedb6cdff292"
339dependencies = [
340 "execute-command-macro",
341 "execute-command-tokens",
342 "generic-array",
343]
344
345[[package]]
346name = "execute-command-macro"
347version = "0.1.8"
348source = "registry+https://github.com/rust-lang/crates.io-index"
349checksum = "a5fbc65a0cf735106743f4c38c9a3671c1e734b5c2c20d21a3c93c696daa3157"
350dependencies = [
351 "execute-command-macro-impl",
352]
353
354[[package]]
355name = "execute-command-macro-impl"
356version = "0.1.8"
357source = "registry+https://github.com/rust-lang/crates.io-index"
358checksum = "5109f6bc9cd57feda665da326f3f6c57e0498c8fe9f7d12d7b8abc96719ca91b"
359dependencies = [
360 "execute-command-tokens",
361 "quote",
362 "syn",
363]
364
365[[package]]
366name = "execute-command-tokens"
367version = "0.1.6"
368source = "registry+https://github.com/rust-lang/crates.io-index"
369checksum = "8ba569491c70ec8471e34aa7e9c0b9e82bb5d2464c0398442d17d3c4af814e5a"
370
371340[[package]]
372341name = "exr"
373342version = "1.5.2"
@@ -445,6 +414,16 @@ dependencies = [
445414 "percent-encoding",
446415]
447416
417[[package]]
418name = "fsio"
419version = "0.4.0"
420source = "registry+https://github.com/rust-lang/crates.io-index"
421checksum = "dad0ce30be0cc441b325c5d705c8b613a0ca0d92b6a8953d41bd236dc09a36d0"
422dependencies = [
423 "dunce",
424 "rand",
425]
426
448427[[package]]
449428name = "futures"
450429version = "0.3.25"
@@ -509,16 +488,6 @@ dependencies = [
509488 "slab",
510489]
511490
512[[package]]
513name = "generic-array"
514version = "0.14.6"
515source = "registry+https://github.com/rust-lang/crates.io-index"
516checksum = "bff49e947297f3312447abdca79f45f4738097cc82b06e72054d2223f601f1b9"
517dependencies = [
518 "typenum",
519 "version_check",
520]
521
522491[[package]]
523492name = "getrandom"
524493version = "0.2.8"
@@ -1107,6 +1076,12 @@ dependencies = [
11071076 "miniz_oxide",
11081077]
11091078
1079[[package]]
1080name = "ppv-lite86"
1081version = "0.2.17"
1082source = "registry+https://github.com/rust-lang/crates.io-index"
1083checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de"
1084
11101085[[package]]
11111086name = "proc-macro2"
11121087version = "1.0.49"
@@ -1125,6 +1100,36 @@ dependencies = [
11251100 "proc-macro2",
11261101]
11271102
1103[[package]]
1104name = "rand"
1105version = "0.8.5"
1106source = "registry+https://github.com/rust-lang/crates.io-index"
1107checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404"
1108dependencies = [
1109 "libc",
1110 "rand_chacha",
1111 "rand_core",
1112]
1113
1114[[package]]
1115name = "rand_chacha"
1116version = "0.3.1"
1117source = "registry+https://github.com/rust-lang/crates.io-index"
1118checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88"
1119dependencies = [
1120 "ppv-lite86",
1121 "rand_core",
1122]
1123
1124[[package]]
1125name = "rand_core"
1126version = "0.6.4"
1127source = "registry+https://github.com/rust-lang/crates.io-index"
1128checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c"
1129dependencies = [
1130 "getrandom",
1131]
1132
11281133[[package]]
11291134name = "rayon"
11301135version = "1.6.1"
@@ -1211,6 +1216,15 @@ dependencies = [
12111216 "bytemuck",
12121217]
12131218
1219[[package]]
1220name = "run_script"
1221version = "0.10.0"
1222source = "registry+https://github.com/rust-lang/crates.io-index"
1223checksum = "7fdc55b3a7ad58e02de47eaf7a854c6791c8421da48ff296c152317d3beaf230"
1224dependencies = [
1225 "fsio",
1226]
1227
12141228[[package]]
12151229name = "ryu"
12161230version = "1.0.12"
@@ -1590,12 +1604,6 @@ dependencies = [
15901604 "unsafe-any",
15911605]
15921606
1593[[package]]
1594name = "typenum"
1595version = "1.16.0"
1596source = "registry+https://github.com/rust-lang/crates.io-index"
1597checksum = "497961ef93d974e23eb6f433eb5fe1b7930b659f06d12dec6fc44a8f554c0bba"
1598
15991607[[package]]
16001608name = "unicode-bidi"
16011609version = "0.3.8"
@@ -1661,12 +1669,6 @@ version = "0.2.15"
16611669source = "registry+https://github.com/rust-lang/crates.io-index"
16621670checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426"
16631671
1664[[package]]
1665name = "version_check"
1666version = "0.9.4"
1667source = "registry+https://github.com/rust-lang/crates.io-index"
1668checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f"
1669
16701672[[package]]
16711673name = "viuer"
16721674version = "0.6.2"
@@ -1949,11 +1951,11 @@ dependencies = [
19491951 "clipboard",
19501952 "crossterm",
19511953 "dyn-clone",
1952 "execute",
19531954 "futures",
19541955 "home",
19551956 "invidious",
19561957 "reqwest",
1958 "run_script",
19571959 "serde",
19581960 "serde_json",
19591961 "serde_yaml",
Cargo.toml +1 −1
@@ -36,7 +36,7 @@ tokio = {version = "1.21", default-features = false}
3636futures = {version = "0.3", default-features = false}
3737reqwest = {version = "0.11", default-features = false}
3838serde_json = {version = "1.0", default-features = false}
39execute = {version = "0.2", default-features = false}
39run_script = { version = "0.10", default-features = false}
4040clipboard = {version = "0.5"}
4141
4242# 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::{
66 },
77 load_configs,
88};
9use std::{io::Stdout, thread};
9use std::{
10 io::Stdout,
11 env,
12 thread,
13};
14use run_script::ScriptOptions;
1015use tui::{backend::CrosstermBackend, Terminal};
1116use tui_additions::framework::Framework;
1217
13use super::{fake_rand_range, from_channel_url, from_playlist_url, from_video_url};
18use super::{fake_rand_range, from_channel_url, from_playlist_url, from_video_url, set_clipboard};
1419
1520/// runs text command - command from the command line (not TUI) which response is just a string
1621pub fn text_command(command: &[&str]) -> Option<String> {
@@ -243,15 +248,25 @@ pub fn run_command(
243248 false
244249 }
245250 ["run", ..] => {
246 let command = &command[1..].join(" ");
251 let command = command[1..].join(" ");
247252 *framework.data.global.get_mut::<Message>().unwrap() =
248253 Message::Success(command.clone());
249 let mut command = execute::command(command);
250254 thread::spawn(move || {
251 let _ = command.output();
255 run_script::run(&command, &Vec::new(), &ScriptOptions::new()).unwrap();
252256 });
253257 false
254258 }
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 }
255270 _ => {
256271 *framework.data.global.get_mut::<Message>().unwrap() =
257272 Message::Error(format!("Unknown command: `{}`", command.join(" ")));
@@ -322,14 +337,15 @@ const HELP_MSG: &str = "\x1b[32mYouTube TUI commands\x1b[0m
322337 \x1b[33mflush\x1b[0m Run all tasks in queue immediately
323338 \x1b[33mquit\x1b[0m Immediately exit
324339 \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
325341
326342\x1b[91mALT:\x1b[0m
327343\x1b[37malts links back to the original command\x1b[30m
328
329344 \x1b[33m[page] (additional options)\x1b[0m `loadpage [page]`
330345 \x1b[33mback\x1b[0m `history back`
331346 \x1b[33mr\x1b[0m `reload`
332347 \x1b[33mreload/r config/configs\x1b[0m `reload configs`
333348 \x1b[33mq, exit, x\x1b[0m `quit`
349 \x1b[33mcp [text]\x1b[0m `copy [text]`
334350
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";