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 = [
304 "syn", 304 "syn",
305] 305]
306 306
307[[package]]
308name = "dunce"
309version = "1.0.3"
310source = "registry+https://github.com/rust-lang/crates.io-index"
311checksum = "0bd4b30a6560bbd9b4620f4de34c3f14f60848e58a9b7216801afcb4c7b31c3c"
312
307[[package]] 313[[package]]
308name = "dyn-clone" 314name = "dyn-clone"
309version = "1.0.10" 315version = "1.0.10"
@@ -331,43 +337,6 @@ dependencies = [
331 "cfg-if", 337 "cfg-if",
332] 338]
333 339
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
371[[package]] 340[[package]]
372name = "exr" 341name = "exr"
373version = "1.5.2" 342version = "1.5.2"
@@ -445,6 +414,16 @@ dependencies = [
445 "percent-encoding", 414 "percent-encoding",
446] 415]
447 416
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
448[[package]] 427[[package]]
449name = "futures" 428name = "futures"
450version = "0.3.25" 429version = "0.3.25"
@@ -509,16 +488,6 @@ dependencies = [
509 "slab", 488 "slab",
510] 489]
511 490
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
522[[package]] 491[[package]]
523name = "getrandom" 492name = "getrandom"
524version = "0.2.8" 493version = "0.2.8"
@@ -1107,6 +1076,12 @@ dependencies = [
1107 "miniz_oxide", 1076 "miniz_oxide",
1108] 1077]
1109 1078
1079[[package]]
1080name = "ppv-lite86"
1081version = "0.2.17"
1082source = "registry+https://github.com/rust-lang/crates.io-index"
1083checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de"
1084
1110[[package]] 1085[[package]]
1111name = "proc-macro2" 1086name = "proc-macro2"
1112version = "1.0.49" 1087version = "1.0.49"
@@ -1125,6 +1100,36 @@ dependencies = [
1125 "proc-macro2", 1100 "proc-macro2",
1126] 1101]
1127 1102
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
1128[[package]] 1133[[package]]
1129name = "rayon" 1134name = "rayon"
1130version = "1.6.1" 1135version = "1.6.1"
@@ -1211,6 +1216,15 @@ dependencies = [
1211 "bytemuck", 1216 "bytemuck",
1212] 1217]
1213 1218
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
1214[[package]] 1228[[package]]
1215name = "ryu" 1229name = "ryu"
1216version = "1.0.12" 1230version = "1.0.12"
@@ -1590,12 +1604,6 @@ dependencies = [
1590 "unsafe-any", 1604 "unsafe-any",
1591] 1605]
1592 1606
1593[[package]]
1594name = "typenum"
1595version = "1.16.0"
1596source = "registry+https://github.com/rust-lang/crates.io-index"
1597checksum = "497961ef93d974e23eb6f433eb5fe1b7930b659f06d12dec6fc44a8f554c0bba"
1598
1599[[package]] 1607[[package]]
1600name = "unicode-bidi" 1608name = "unicode-bidi"
1601version = "0.3.8" 1609version = "0.3.8"
@@ -1661,12 +1669,6 @@ version = "0.2.15"
1661source = "registry+https://github.com/rust-lang/crates.io-index" 1669source = "registry+https://github.com/rust-lang/crates.io-index"
1662checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426" 1670checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426"
1663 1671
1664[[package]]
1665name = "version_check"
1666version = "0.9.4"
1667source = "registry+https://github.com/rust-lang/crates.io-index"
1668checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f"
1669
1670[[package]] 1672[[package]]
1671name = "viuer" 1673name = "viuer"
1672version = "0.6.2" 1674version = "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}
36futures = {version = "0.3", default-features = false} 36futures = {version = "0.3", default-features = false}
37reqwest = {version = "0.11", default-features = false} 37reqwest = {version = "0.11", default-features = false}
38serde_json = {version = "1.0", default-features = false} 38serde_json = {version = "1.0", default-features = false}
39execute = {version = "0.2", default-features = false} 39run_script = { version = "0.10", default-features = false}
40clipboard = {version = "0.5"} 40clipboard = {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};
9use std::{io::Stdout, thread}; 9use std::{
10 io::Stdout,
11 env,
12 thread,
13};
14use run_script::ScriptOptions;
10use tui::{backend::CrosstermBackend, Terminal}; 15use tui::{backend::CrosstermBackend, Terminal};
11use tui_additions::framework::Framework; 16use tui_additions::framework::Framework;
12 17
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};
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
16pub fn text_command(command: &[&str]) -> Option<String> { 21pub 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";