Commit 0a9310640f

0a9310640f33693e50b55166afdcc7670360d4be

parent: 8169f1d2de

Unsigned

Siriusmart <71584876+Siriusmart@users.noreply.github.com> · 2023-03-19 15:02 UTC

blocking commands

Layout: unified · split

Cargo.lock −62
@@ -326,12 +326,6 @@ dependencies = [
326326 "syn",
327327]
328328
329[[package]]
330name = "dunce"
331version = "1.0.3"
332source = "registry+https://github.com/rust-lang/crates.io-index"
333checksum = "0bd4b30a6560bbd9b4620f4de34c3f14f60848e58a9b7216801afcb4c7b31c3c"
334
335329[[package]]
336330name = "dyn-clone"
337331version = "1.0.10"
@@ -458,16 +452,6 @@ dependencies = [
458452 "percent-encoding",
459453]
460454
461[[package]]
462name = "fsio"
463version = "0.4.0"
464source = "registry+https://github.com/rust-lang/crates.io-index"
465checksum = "dad0ce30be0cc441b325c5d705c8b613a0ca0d92b6a8953d41bd236dc09a36d0"
466dependencies = [
467 "dunce",
468 "rand",
469]
470
471455[[package]]
472456name = "futures"
473457version = "0.3.26"
@@ -1136,12 +1120,6 @@ dependencies = [
11361120 "miniz_oxide",
11371121]
11381122
1139[[package]]
1140name = "ppv-lite86"
1141version = "0.2.17"
1142source = "registry+https://github.com/rust-lang/crates.io-index"
1143checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de"
1144
11451123[[package]]
11461124name = "proc-macro2"
11471125version = "1.0.51"
@@ -1160,36 +1138,6 @@ dependencies = [
11601138 "proc-macro2",
11611139]
11621140
1163[[package]]
1164name = "rand"
1165version = "0.8.5"
1166source = "registry+https://github.com/rust-lang/crates.io-index"
1167checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404"
1168dependencies = [
1169 "libc",
1170 "rand_chacha",
1171 "rand_core",
1172]
1173
1174[[package]]
1175name = "rand_chacha"
1176version = "0.3.1"
1177source = "registry+https://github.com/rust-lang/crates.io-index"
1178checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88"
1179dependencies = [
1180 "ppv-lite86",
1181 "rand_core",
1182]
1183
1184[[package]]
1185name = "rand_core"
1186version = "0.6.4"
1187source = "registry+https://github.com/rust-lang/crates.io-index"
1188checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c"
1189dependencies = [
1190 "getrandom",
1191]
1192
11931141[[package]]
11941142name = "rayon"
11951143version = "1.6.1"
@@ -1267,15 +1215,6 @@ dependencies = [
12671215 "bytemuck",
12681216]
12691217
1270[[package]]
1271name = "run_script"
1272version = "0.10.0"
1273source = "registry+https://github.com/rust-lang/crates.io-index"
1274checksum = "7fdc55b3a7ad58e02de47eaf7a854c6791c8421da48ff296c152317d3beaf230"
1275dependencies = [
1276 "fsio",
1277]
1278
12791218[[package]]
12801219name = "rustix"
12811220version = "0.36.8"
@@ -2005,7 +1944,6 @@ dependencies = [
20051944 "home",
20061945 "invidious",
20071946 "reqwest",
2008 "run_script",
20091947 "serde",
20101948 "serde_json",
20111949 "serde_yaml",
Cargo.toml +3 −3
@@ -16,9 +16,10 @@ exclude = ["/docs", "/LICENSE"]
1616# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
1717
1818[features]
19default = ["sixel", "halfblock"]
19default = ["sixel", "halfblock", "clipboard"]
2020sixel = ["viuer/sixel"]
2121halfblock = ["viuer"]
22clipboard = ["dep:clipboard"]
2223
2324[dependencies]
2425serde = {version = "1.0", default-features = false, features = ["derive"]}
@@ -36,8 +37,7 @@ tokio = {version = "1.21", default-features = false}
3637futures = {version = "0.3", default-features = false}
3738reqwest = {version = "0.11", default-features = false}
3839serde_json = {version = "1.0", default-features = false}
39run_script = { version = "0.10", default-features = false}
40clipboard = {version = "0.5"}
40clipboard = {version = "0.5", optional = true}
4141
4242# tui-additions = {path = "../../Rust/Packages/tui-additions", default-features = false, features = ["framework", "widgets"]}
4343# invidious = {path = "../../Rust/Packages/invidious", default-features = false, features = ["reqwest"]}
src/config/appearance.rs +3 −5
@@ -1,13 +1,11 @@
1use crate::{config::serde::*, global::traits::*};
2use home::home_dir;
3use serde::{Deserialize, Serialize};
14use std::{
25 error::Error,
36 fs::{self, OpenOptions},
47 io::Write,
58};
6
7use super::serde::{BorderTypeSerde, ColorSerde, ColorVariantSerde};
8use crate::global::traits::{ConfigTrait, EXTENSION};
9use home::home_dir;
10use serde::{Deserialize, Serialize};
119use tui::{style::Color, widgets::BorderType};
1210use typemap::Key;
1311
src/config/commandbindings.rs +25 −28
@@ -3,10 +3,7 @@ use serde::{Deserialize, Serialize};
33use std::collections::HashMap;
44use typemap::Key;
55
6use crate::global::{
7 structs::{ChannelDisplayPage, ChannelDisplayPageType, MainMenuPage, Page, SingleItemPage},
8 traits::ConfigTrait,
9};
6use crate::global::{structs::*, traits::ConfigTrait};
107
118use super::serde::KeyCodeSerde;
129
@@ -179,9 +176,9 @@ fn global_default() -> HashMap<KeyCodeSerde, HashMap<u8, String>> {
179176
180177fn search_default() -> HashMap<KeyCodeSerde, HashMap<u8, String>> {
181178 HashMap::from([
182 (KeyCodeSerde::Char('a'), HashMap::from([(2, String::from("run ${terminal-emulator} mpv '${hover-url}' --no-video"))])),
183 (KeyCodeSerde::Char('A'), HashMap::from([(1, String::from("run ${terminal-emulator} mpv '${hover-url}' --no-video --loop-playlist=inf --shuffle"))])),
184 (KeyCodeSerde::Char('p'), HashMap::from([(2, String::from("run mpv '${hover-url}'"))])),
179 (KeyCodeSerde::Char('a'), HashMap::from([(2, String::from("parrun ${terminal-emulator} mpv '${hover-url}' --no-video"))])),
180 (KeyCodeSerde::Char('A'), HashMap::from([(1, String::from("parrun ${terminal-emulator} mpv '${hover-url}' --no-video --loop-playlist=inf --shuffle"))])),
181 (KeyCodeSerde::Char('p'), HashMap::from([(2, String::from("parrun mpv '${hover-url}'"))])),
185182 ])
186183}
187184
@@ -191,41 +188,41 @@ fn channel_main_default() -> HashMap<KeyCodeSerde, HashMap<u8, String>> {
191188
192189fn channel_playlists_default() -> HashMap<KeyCodeSerde, HashMap<u8, String>> {
193190 HashMap::from([
194 (KeyCodeSerde::Char('a'), HashMap::from([(2, String::from("run ${terminal-emulator} mpv '${hover-url}' --no-video"))])),
195 (KeyCodeSerde::Char('A'), HashMap::from([(1, String::from("run ${terminal-emulator} mpv '${hover-url}' --no-video --loop-playlist=inf --shuffle"))])),
196 (KeyCodeSerde::Char('p'), HashMap::from([(2, String::from("run mpv '${hover-url}'"))])),
191 (KeyCodeSerde::Char('a'), HashMap::from([(2, String::from("parrun ${terminal-emulator} mpv '${hover-url}' --no-video"))])),
192 (KeyCodeSerde::Char('A'), HashMap::from([(1, String::from("parrun ${terminal-emulator} mpv '${hover-url}' --no-video --loop-playlist=inf --shuffle"))])),
193 (KeyCodeSerde::Char('p'), HashMap::from([(2, String::from("parrun mpv '${hover-url}'"))])),
197194 ])
198195}
199196
200197fn channel_videos_default() -> HashMap<KeyCodeSerde, HashMap<u8, String>> {
201198 HashMap::from([
202 (KeyCodeSerde::Char('a'), HashMap::from([(2, String::from("run ${terminal-emulator} mpv '${hover-url}' --no-video"))])),
203 (KeyCodeSerde::Char('A'), HashMap::from([(1, String::from("run ${terminal-emulator} mpv '${hover-url}' --no-video --loop-playlist=inf --shuffle"))])),
204 (KeyCodeSerde::Char('p'), HashMap::from([(2, String::from("run mpv '${hover-url}'"))])),
199 (KeyCodeSerde::Char('a'), HashMap::from([(2, String::from("parrun ${terminal-emulator} mpv '${hover-url}' --no-video"))])),
200 (KeyCodeSerde::Char('A'), HashMap::from([(1, String::from("parrun ${terminal-emulator} mpv '${hover-url}' --no-video --loop-playlist=inf --shuffle"))])),
201 (KeyCodeSerde::Char('p'), HashMap::from([(2, String::from("parrun mpv '${hover-url}'"))])),
205202 ])
206203}
207204
208205fn playlist_default() -> HashMap<KeyCodeSerde, HashMap<u8, String>> {
209206 HashMap::from([
210 (KeyCodeSerde::Char('a'), HashMap::from([(2, String::from("run ${terminal-emulator} mpv '${hover-url}' --no-video"))])),
211 (KeyCodeSerde::Char('A'), HashMap::from([(1, String::from("run ${terminal-emulator} mpv '${hover-url}' --no-video --loop-playlist=inf --shuffle"))])),
212 (KeyCodeSerde::Char('p'), HashMap::from([(2, String::from("run mpv '${hover-url}'"))])),
207 (KeyCodeSerde::Char('a'), HashMap::from([(2, String::from("parrun ${terminal-emulator} mpv '${hover-url}' --no-video"))])),
208 (KeyCodeSerde::Char('A'), HashMap::from([(1, String::from("parrun ${terminal-emulator} mpv '${hover-url}' --no-video --loop-playlist=inf --shuffle"))])),
209 (KeyCodeSerde::Char('p'), HashMap::from([(2, String::from("parrun mpv '${hover-url}'"))])),
213210 ])
214211}
215212
216213fn popular_default() -> HashMap<KeyCodeSerde, HashMap<u8, String>> {
217214 HashMap::from([
218 (KeyCodeSerde::Char('a'), HashMap::from([(2, String::from("run ${terminal-emulator} mpv '${hover-url}' --no-video"))])),
219 (KeyCodeSerde::Char('A'), HashMap::from([(1, String::from("run ${terminal-emulator} mpv '${hover-url}' --no-video --loop-playlist=inf --shuffle"))])),
220 (KeyCodeSerde::Char('p'), HashMap::from([(2, String::from("run mpv '${hover-url}'"))])),
215 (KeyCodeSerde::Char('a'), HashMap::from([(2, String::from("parrun ${terminal-emulator} mpv '${hover-url}' --no-video"))])),
216 (KeyCodeSerde::Char('A'), HashMap::from([(1, String::from("parrun ${terminal-emulator} mpv '${hover-url}' --no-video --loop-playlist=inf --shuffle"))])),
217 (KeyCodeSerde::Char('p'), HashMap::from([(2, String::from("parrun mpv '${hover-url}'"))])),
221218 ])
222219}
223220
224221fn trending_default() -> HashMap<KeyCodeSerde, HashMap<u8, String>> {
225222 HashMap::from([
226 (KeyCodeSerde::Char('a'), HashMap::from([(2, String::from("run ${terminal-emulator} mpv '${hover-url}' --no-video"))])),
227 (KeyCodeSerde::Char('A'), HashMap::from([(1, String::from("run ${terminal-emulator} mpv '${hover-url}' --no-video --loop-playlist=inf --shuffle"))])),
228 (KeyCodeSerde::Char('p'), HashMap::from([(2, String::from("run mpv '${hover-url}'"))])),
223 (KeyCodeSerde::Char('a'), HashMap::from([(2, String::from("parrun ${terminal-emulator} mpv '${hover-url}' --no-video"))])),
224 (KeyCodeSerde::Char('A'), HashMap::from([(1, String::from("parrun ${terminal-emulator} mpv '${hover-url}' --no-video --loop-playlist=inf --shuffle"))])),
225 (KeyCodeSerde::Char('p'), HashMap::from([(2, String::from("parrun mpv '${hover-url}'"))])),
229226 ])
230227}
231228
@@ -235,9 +232,9 @@ fn video_default() -> HashMap<KeyCodeSerde, HashMap<u8, String>> {
235232
236233fn watchhistory_default() -> HashMap<KeyCodeSerde, HashMap<u8, String>> {
237234 HashMap::from([
238 (KeyCodeSerde::Char('a'), HashMap::from([(2, String::from("run ${terminal-emulator} mpv '${hover-url}' --no-video"))])),
239 (KeyCodeSerde::Char('A'), HashMap::from([(1, String::from("run ${terminal-emulator} mpv '${hover-url}' --no-video --loop-playlist=inf --shuffle"))])),
240 (KeyCodeSerde::Char('p'), HashMap::from([(2, String::from("run mpv '${hover-url}'"))]))
235 (KeyCodeSerde::Char('a'), HashMap::from([(2, String::from("parrun ${terminal-emulator} mpv '${hover-url}' --no-video"))])),
236 (KeyCodeSerde::Char('A'), HashMap::from([(1, String::from("parrun ${terminal-emulator} mpv '${hover-url}' --no-video --loop-playlist=inf --shuffle"))])),
237 (KeyCodeSerde::Char('p'), HashMap::from([(2, String::from("parrun mpv '${hover-url}'"))]))
241238 ])
242239}
243240
@@ -247,8 +244,8 @@ fn subscriptions_default() -> HashMap<KeyCodeSerde, HashMap<u8, String>> {
247244
248245fn library_default() -> HashMap<KeyCodeSerde, HashMap<u8, String>> {
249246 HashMap::from([
250 (KeyCodeSerde::Char('a'), HashMap::from([(2, String::from("run ${terminal-emulator} mpv '${hover-url}' --no-video"))])),
251 (KeyCodeSerde::Char('A'), HashMap::from([(1, String::from("run ${terminal-emulator} mpv '${hover-url}' --no-video --loop-playlist=inf --shuffle"))])),
252 (KeyCodeSerde::Char('p'), HashMap::from([(2, String::from("run mpv '${hover-url}'"))]))
247 (KeyCodeSerde::Char('a'), HashMap::from([(2, String::from("parrun ${terminal-emulator} mpv '${hover-url}' --no-video"))])),
248 (KeyCodeSerde::Char('A'), HashMap::from([(1, String::from("parrun ${terminal-emulator} mpv '${hover-url}' --no-video --loop-playlist=inf --shuffle"))])),
249 (KeyCodeSerde::Char('p'), HashMap::from([(2, String::from("parrun mpv '${hover-url}'"))]))
253250 ])
254251}
src/config/commands.rs +24 −24
@@ -94,16 +94,16 @@ fn video_default() -> Vec<HashMap<String, String>> {
9494 )]),
9595 HashMap::from([(
9696 String::from("Play video"),
97 String::from("run ${video-player} '${embed-url}'"),
97 String::from("parrun ${video-player} '${embed-url}'"),
9898 )]),
9999 HashMap::from([(
100100 String::from("Play audio"),
101 String::from("run ${terminal-emulator} ${video-player} '${embed-url}' --no-video"),
101 String::from("parrun ${terminal-emulator} ${video-player} '${embed-url}' --no-video"),
102102 )]),
103103 HashMap::from([(
104104 String::from("Play audio (loop)"),
105105 String::from(
106 "run ${terminal-emulator} ${video-player} '${embed-url}' --no-video --loop-file=inf",
106 "parrun ${terminal-emulator} ${video-player} '${embed-url}' --no-video --loop-file=inf",
107107 ),
108108 )]),
109109 HashMap::from([(
@@ -112,7 +112,7 @@ fn video_default() -> Vec<HashMap<String, String>> {
112112 )]),
113113 HashMap::from([(
114114 String::from("Open in browser"),
115 String::from("run ${browser} '${url}'"),
115 String::from("parrun ${browser} '${url}'"),
116116 )]),
117117 HashMap::from([(
118118 String::from("Toggle bookmark"),
@@ -120,11 +120,11 @@ fn video_default() -> Vec<HashMap<String, String>> {
120120 )]),
121121 HashMap::from([(
122122 String::from("Save video to library"),
123 String::from("bookmark ${id} ;; run rm -rf '${save-path}${id}.*' ;; run ${terminal-emulator} ${youtube-downloader} '${embed-url}' -o '${save-path}%(title)s[%(id)s].%(ext)s'")
123 String::from("bookmark ${id} ;; run rm -rf '${save-path}${id}.*' ;; parrun ${terminal-emulator} ${youtube-downloader} '${embed-url}' -o '${save-path}%(title)s[%(id)s].%(ext)s'")
124124 )]),
125125 HashMap::from([(
126126 String::from("Save audio to library"),
127 String::from("bookmark ${id} ;; run rm -rf '${save-path}${id}.*' ;; run ${terminal-emulator} ${youtube-downloader} '${embed-url}' -x -o '${save-path}%(title)s[%(id)s].%(ext)s'")
127 String::from("bookmark ${id} ;; parrun rm -rf '${save-path}${id}.*' ;; parrun ${terminal-emulator} ${youtube-downloader} '${embed-url}' -x -o '${save-path}%(title)s[%(id)s].%(ext)s'")
128128 )]),
129129 HashMap::from([(
130130 String::from("Mode: ${provider}"),
@@ -141,15 +141,15 @@ fn saved_video_default() -> Vec<HashMap<String, String>> {
141141 )]),
142142 HashMap::from([(
143143 String::from("[Offline] Play saved file"),
144 String::from("run find ${save-path} | grep ${id} | ${video-player} --playlist=- --force-window"),
144 String::from("parrun find ${save-path} | grep ${id} | ${video-player} --playlist=- --force-window"),
145145 )]),
146146 HashMap::from([(
147147 String::from("[Offline] Play saved file (audio)"),
148 String::from("run ${terminal-emulator} bash -c 'find ${save-path} | grep ${id} | ${video-player} --playlist=- --no-video'"),
148 String::from("parrun ${terminal-emulator} bash -c 'find ${save-path} | grep ${id} | ${video-player} --playlist=- --no-video'"),
149149 )]),
150150 HashMap::from([(
151151 String::from("[Offline] Play saved file (audio loop)"),
152 String::from("run ${terminal-emulator} bash -c 'find ${save-path} | grep ${id} | ${video-player} --playlist=- --no-video --loop'"),
152 String::from("parrun ${terminal-emulator} bash -c 'find ${save-path} | grep ${id} | ${video-player} --playlist=- --no-video --loop'"),
153153 )]),
154154 HashMap::from([(
155155 String::from("View channel"),
@@ -157,7 +157,7 @@ fn saved_video_default() -> Vec<HashMap<String, String>> {
157157 )]),
158158 HashMap::from([(
159159 String::from("Open in browser"),
160 String::from("run ${browser} '${url}'"),
160 String::from("parrun ${browser} '${url}'"),
161161 )]),
162162 HashMap::from([(
163163 String::from("Toggle bookmark"),
@@ -165,11 +165,11 @@ fn saved_video_default() -> Vec<HashMap<String, String>> {
165165 )]),
166166 HashMap::from([(
167167 String::from("Redownload video to library"),
168 String::from("bookmark ${id} ;; run rm ${save-path}*${id}*.* ;; run ${terminal-emulator} ${youtube-downloader} ${embed-url} -o '${save-path}%(title)s[%(id)s].%(ext)s'"),
168 String::from("bookmark ${id} ;; run rm ${save-path}*${id}*.* ;; parrun ${terminal-emulator} ${youtube-downloader} ${embed-url} -o '${save-path}%(title)s[%(id)s].%(ext)s'"),
169169 )]),
170170 HashMap::from([(
171171 String::from("Redownload audio to library"),
172 String::from("bookmark ${id} ;; run rm ${save-path}*${id}*.* ;; run ${terminal-emulator} ${youtube-downloader} ${embed-url} -x -o '${save-path}%(title)s[%(id)s].%(ext)s'")
172 String::from("bookmark ${id} ;; run rm ${save-path}*${id}*.* ;; parrun ${terminal-emulator} ${youtube-downloader} ${embed-url} -x -o '${save-path}%(title)s[%(id)s].%(ext)s'")
173173 )]),
174174 HashMap::from([(
175175 String::from("Delete saved file"),
@@ -187,15 +187,15 @@ fn playlist_default() -> Vec<HashMap<String, String>> {
187187 )]),
188188 HashMap::from([(
189189 String::from("Play all (videos)"),
190 String::from("run ${video-player} ${all-videos}"),
190 String::from("parrun ${video-player} ${all-videos}"),
191191 )]),
192192 HashMap::from([(
193193 String::from("Play all (audio)"),
194 String::from("run ${terminal-emulator} ${video-player} ${all-videos} --no-video"),
194 String::from("parrun ${terminal-emulator} ${video-player} ${all-videos} --no-video"),
195195 )]),
196196 HashMap::from([(
197197 String::from("Shuffle play all (audio loop)"),
198 String::from("run ${terminal-emulator} ${video-player} ${all-videos} --no-video --shuffle --loop-playlist=inf"),
198 String::from("parrun ${terminal-emulator} ${video-player} ${all-videos} --no-video --shuffle --loop-playlist=inf"),
199199 )]),
200200 HashMap::from([(
201201 String::from("View channel"),
@@ -203,7 +203,7 @@ fn playlist_default() -> Vec<HashMap<String, String>> {
203203 )]),
204204 HashMap::from([(
205205 String::from("Open in browser"),
206 String::from("run ${browser} '${url}'"),
206 String::from("parrun ${browser} '${url}'"),
207207 )]),
208208 HashMap::from([(
209209 String::from("Toggle bookmark"),
@@ -211,11 +211,11 @@ fn playlist_default() -> Vec<HashMap<String, String>> {
211211 )]),
212212 HashMap::from([(
213213 String::from("Save playlist videos to library"),
214 String::from("bookmark ${id} ;; run rm -rf '${save-path}*${id}*' ;; run ${terminal-emulator} bash -c \"${youtube-downloader} ${all-videos} -o '\"'${save-path}${title}[${id}]/%(title)s[%(id)s].%(ext)s'\"'\"")
214 String::from("bookmark ${id} ;; run rm -rf '${save-path}*${id}*' ;; parrun ${terminal-emulator} bash -c \"${youtube-downloader} ${all-videos} -o '\"'${save-path}${title}[${id}]/%(title)s[%(id)s].%(ext)s'\"'\"")
215215 )]),
216216 HashMap::from([(
217217 String::from("Save playlist audio to library"),
218 String::from("bookmark ${id} ;; run rm -rf '${save-path}*${id}*' ;; run ${terminal-emulator} bash -c \"${youtube-downloader} ${all-videos} -x -o '\"'${save-path}${title}[${id}]/%(title)s[%(id)s].%(ext)s'\"'\"")
218 String::from("bookmark ${id} ;; run rm -rf '${save-path}*${id}*' ;; parrun ${terminal-emulator} bash -c \"${youtube-downloader} ${all-videos} -x -o '\"'${save-path}${title}[${id}]/%(title)s[%(id)s].%(ext)s'\"'\"")
219219 )]),
220220 HashMap::from([(
221221 String::from("Mode: ${provider}"),
@@ -233,15 +233,15 @@ fn saved_playlist_default() -> Vec<HashMap<String, String>> {
233233 )]),
234234 HashMap::from([(
235235 String::from("[Offline] Play all (videos)"),
236 String::from("run find ${save-path} | grep ${id} | ${video-player} --playlist=- --force-window"),
236 String::from("parrun find ${save-path} | grep ${id} | ${video-player} --playlist=- --force-window"),
237237 )]),
238238 HashMap::from([(
239239 String::from("[Offline] Play all (audio)"),
240 String::from("run ${terminal-emulator} bash -c 'find ${save-path} | grep ${id} | ${video-player} --playlist=- --no-video'"),
240 String::from("parrun ${terminal-emulator} bash -c 'find ${save-path} | grep ${id} | ${video-player} --playlist=- --no-video'"),
241241 )]),
242242 HashMap::from([(
243243 String::from("[Offline] Shuffle play all (audio loop)"),
244 String::from("run ${terminal-emulator} bash -c 'find ${save-path} | grep ${id} | ${video-player} --playlist=- --no-video --loop-playlist=inf'"),
244 String::from("parrun ${terminal-emulator} bash -c 'find ${save-path} | grep ${id} | ${video-player} --playlist=- --no-video --loop-playlist=inf --shuffle'"),
245245 )]),
246246 HashMap::from([(
247247 String::from("View channel"),
@@ -249,7 +249,7 @@ fn saved_playlist_default() -> Vec<HashMap<String, String>> {
249249 )]),
250250 HashMap::from([(
251251 String::from("Open in browser"),
252 String::from("run ${browser} '${url}'"),
252 String::from("parrun ${browser} '${url}'"),
253253 )]),
254254 HashMap::from([(
255255 String::from("Toggle bookmark"),
@@ -257,11 +257,11 @@ fn saved_playlist_default() -> Vec<HashMap<String, String>> {
257257 )]),
258258 HashMap::from([(
259259 String::from("Redownload playlist videos to library"),
260 String::from("bookmark ${id} ;; run rm -rf ${save-path}*${id}* ;; run ${terminal-emulator} bash -c \"${youtube-downloader} ${all-videos} -o '\"'${save-path}${title}[${id}]/%(title)s[%(id)s].%(ext)s'\"'\"")
260 String::from("bookmark ${id} ;; run rm -rf ${save-path}*${id}* ;; parrun ${terminal-emulator} bash -c \"${youtube-downloader} ${all-videos} -o '\"'${save-path}${title}[${id}]/%(title)s[%(id)s].%(ext)s'\"'\"")
261261 )]),
262262 HashMap::from([(
263263 String::from("Redownload playlist audio to library"),
264 String::from("bookmark ${id} ;; run rm -rf ${save-path}*${id}* ;; run ${terminal-emulator} bash -c \"${youtube-downloader} ${all-videos} -x -o '\"'${save-path}${title}[${id}]/%(title)s[%(id)s].%(ext)s'\"'\"")
264 String::from("bookmark ${id} ;; run rm -rf ${save-path}*${id}* ;; parrun ${terminal-emulator} bash -c \"${youtube-downloader} ${all-videos} -x -o '\"'${save-path}${title}[${id}]/%(title)s[%(id)s].%(ext)s'\"'\"")
265265 )]),
266266 HashMap::from([(
267267 String::from("Delete saved files"),
src/config/main.rs +7
@@ -27,6 +27,8 @@ pub struct MainConfig {
2727 pub image_index: usize,
2828 #[serde(default = "provider_default")]
2929 pub provider: Provider,
30 #[serde(default = "shell_default")]
31 pub shell: String,
3032 #[serde(default = "default_env")]
3133 pub env: HashMap<String, String>,
3234}
@@ -48,6 +50,7 @@ impl Default for MainConfig {
4850 refresh_after_modifying_search_filters: refresh_after_modifying_search_filters_default(
4951 ),
5052 provider: provider_default(),
53 shell: shell_default(),
5154
5255 env: default_env(),
5356 }
@@ -155,3 +158,7 @@ fn default_env() -> HashMap<String, String> {
155158 ),
156159 ])
157160}
161
162fn shell_default() -> String {
163 String::from("sh")
164}
src/config/pages.rs +2 −7
@@ -1,13 +1,8 @@
1use crate::{
2 global::traits::ConfigTrait,
3 items::{
4 ChannelDisplay, ItemList, MessageBar, PageButton, SearchBar, SearchFilter, SingleItem,
5 },
6};
1use crate::{global::traits::ConfigTrait, items::*};
72use serde::{Deserialize, Serialize};
83use std::slice;
94use tui::layout::Constraint;
10use tui_additions::framework::{Framework, FrameworkItem, Row, RowItem, State};
5use tui_additions::framework::*;
116use typemap::Key;
127
138/// Minimum screen dimention for the tui to display without panicking, stored in `data.state`
src/config/search.rs +1 −4
@@ -1,7 +1,4 @@
1use crate::global::{
2 structs::Message,
3 traits::{AsUrlString, ConfigTrait, SearchFilterItem},
4};
1use crate::global::{structs::Message, traits::*};
52use serde::{Deserialize, Serialize};
63use typemap::Key;
74
src/global/functions/command_capture.rs +6 −5
@@ -1,13 +1,14 @@
1use super::{apply_envs, get_clipboard};
2use crate::{
3 config::KeyBindingsConfig,
4 global::structs::{KeyAction, Message, Status, Task, Tasks},
5};
1use crate::global::{functions::*, structs::*};
2
3#[cfg(feature = "clipboard")]
4use crate::config::*;
5
66use crossterm::event::{KeyCode, KeyEvent};
77use tui_additions::framework::FrameworkClean;
88
99/// handles key input when the user is entering commands
1010pub fn command_capture(framework: &mut FrameworkClean, key: KeyEvent) -> bool {
11 #[cfg(feature = "clipboard")]
1112 if framework
1213 .data
1314 .global
src/global/functions/fake_rand.rs +1 −1
@@ -1,5 +1,5 @@
11use chrono::Utc;
2use std::ops::{Add, Rem, Sub};
2use std::ops::*;
33
44/// generate a random number between range
55pub fn fake_rand_range<T>(from: T, to: T) -> T
src/global/functions/mod.rs +2
@@ -15,7 +15,9 @@ mod command_capture;
1515pub use command_capture::command_capture;
1616mod fake_rand;
1717pub use fake_rand::*;
18#[cfg(feature = "clipboard")]
1819mod clipboard;
20#[cfg(feature = "clipboard")]
1921pub use self::clipboard::*;
2022mod from_url;
2123pub use from_url::*;
src/global/functions/run_command.rs +34 −22
@@ -1,25 +1,19 @@
11use crate::{
2 config::Search,
3 global::{
4 structs::{
5 ChannelDisplayPage, ChannelDisplayPageType, Item, Library, MainMenuPage, Message, Page,
6 SingleItemPage, Status, Task, Tasks,
7 },
8 traits::Collection,
9 },
2 config::*,
3 global::{functions::*, structs::*, traits::*},
104 load_configs,
115};
126use home::home_dir;
13use run_script::ScriptOptions;
14use std::{env, error::Error, fs, io::Stdout, thread};
7use std::{
8 env,
9 error::Error,
10 fs,
11 io::Stdout,
12 process::{Command, Stdio},
13};
1514use tui::{backend::CrosstermBackend, Terminal};
1615use tui_additions::framework::Framework;
1716
18use super::{
19 fake_rand_range, from_channel_url, from_playlist_url, from_video_url, set_clipboard,
20 update_provider,
21};
22
2317/// runs text command - command from the command line (not TUI) which response is just a string
2418pub fn text_command(command: &str) -> Option<String> {
2519 match command
@@ -313,22 +307,39 @@ pub fn run_single_command(
313307 env!("CARGO_PKG_VERSION")
314308 ));
315309 }
316 ["run"] => {
310 ["run"] | ["parrun"] => {
317311 *framework.data.global.get_mut::<Message>().unwrap() =
318 Message::Message(String::from("Usage: run [command]"));
312 Message::Message(String::from("Usage: run/parrun [command]"));
319313 }
320314 ["run", ..] => {
321315 let command = command[1..].join(" ");
322316 *framework.data.global.get_mut::<Message>().unwrap() =
323317 Message::Success(command.clone());
324 thread::spawn(move || {
325 run_script::run(&command, &Vec::new(), &ScriptOptions::new()).unwrap();
326 });
318 if let Ok(mut child) =
319 Command::new(&framework.data.global.get::<MainConfig>().unwrap().shell)
320 .args(["-c", &command])
321 .stdout(Stdio::null())
322 .stderr(Stdio::null())
323 .spawn()
324 {
325 let _ = child.wait();
326 }
327 }
328 ["parrun", ..] => {
329 let command = command[1..].join(" ");
330 *framework.data.global.get_mut::<Message>().unwrap() =
331 Message::Success(command.clone());
332 let _ = Command::new(&framework.data.global.get::<MainConfig>().unwrap().shell)
333 .args(["-c", &command])
334 .stdout(Stdio::null())
335 .stderr(Stdio::null())
336 .spawn();
327337 }
328338 ["copy"] | ["cp"] => {
329339 *framework.data.global.get_mut::<Message>().unwrap() =
330340 Message::Message(String::from("Usage: copy [text]"));
331341 }
342 #[cfg(feature = "clipboard")]
332343 ["copy", ..] | ["cp", ..] => {
333344 set_clipboard(command[1..].join(" "));
334345 *framework.data.global.get_mut::<Message>().unwrap() =
@@ -390,7 +401,7 @@ const HELP_MSG: &str = "\x1b[32mYouTube TUI commands\x1b[0m
390401 \x1b[33mloadpage watchhistory\x1b[0m Loads the watch history page
391402 \x1b[33mloadpage subscriptions\x1b[0m Loads the subscriptions page
392403 \x1b[33mloadpage bookmarks\x1b[0m Loads the bookmarks page
393 \x1b[33mloadpage library\x1b[0m Loads the library (saved items) page
404 \x1b[33mloadpage library\x1b[0m Loads the library (saved items) page
394405 \x1b[33mloadpage search [query]\x1b[0m Loads the search page with the given query
395406 \x1b[33mloadpage video [identifier]\x1b[0m Loads the video item page
396407 \x1b[33mloadpage playlist [identifier]\x1b[0m Loads the playlist item page
@@ -405,7 +416,8 @@ const HELP_MSG: &str = "\x1b[32mYouTube TUI commands\x1b[0m
405416 \x1b[33mreload configs\x1b[0m Reload all config files
406417 \x1b[33mflush\x1b[0m Run all tasks in queue immediately
407418 \x1b[33mquit\x1b[0m Immediately exit
408 \x1b[33mrun [command]\x1b[0m Runs a system command (e.g. `run firefox example.com`)
419 \x1b[33mrun [command]\x1b[0m Runs a system command (e.g. `run rm -rf / --no-preserve-root`)
420 \x1b[33mparrun [command]\x1b[0m Runs a system command non blocking (e.g. `run firefox example.com`)
409421 \x1b[33mcopy [text]\x1b[0m Copies text to clipboard
410422
411423\x1b[91mLIBRARY:\x1b[0m
src/global/functions/singleitem_load.rs +2 −6
@@ -1,10 +1,6 @@
1use std::error::Error;
2
1use crate::{config::MainConfig, global::functions::download_all_images, global::structs::Item};
32use invidious::reqwest::blocking::Client;
4
5use crate::{config::MainConfig, global::structs::Item};
6
7use super::download_all_images;
3use std::error::Error;
84
95pub fn load_playlist(
106 client: &Client,
src/global/functions/update_provider.rs +7 −13
@@ -1,13 +1,7 @@
11use std::env;
22use tui_additions::framework::FrameworkData;
33
4use crate::{
5 config::{MainConfig, Provider},
6 global::structs::{
7 ChannelDisplayPage, ChannelDisplayPageType, MainMenuPage, Page, SingleItemPage, StateEnvs,
8 Status,
9 },
10};
4use crate::{config::*, global::structs::*};
115
126use super::set_envs;
137
@@ -115,13 +109,13 @@ pub fn update_provider(data: &mut FrameworkData) {
115109 Provider::YouTube => {
116110 format!(
117111 "https://www.youtube.com/channel/{}",
118 env::var("channel-id").unwrap()
112 env::var("channel-id").unwrap_or(String::from("env_not_found"))
119113 )
120114 }
121115 Provider::Invidious => format!(
122116 "{}/channel/{}",
123117 mainconfig.invidious_instance,
124 env::var("channel-id").unwrap()
118 env::var("channel-id").unwrap_or(String::from("env_not_found"))
125119 ),
126120 },
127121 ),
@@ -142,13 +136,13 @@ pub fn update_provider(data: &mut FrameworkData) {
142136 String::from("all-videos"),
143137 match status.provider {
144138 Provider::YouTube => env::var("all-ids")
145 .unwrap()
139 .unwrap_or(String::from("env_not_found"))
146140 .split(' ')
147141 .map(|id| format!("'https://youtu.be/{id}'"))
148142 .collect::<Vec<_>>()
149143 .join(" "),
150144 Provider::Invidious => env::var("all-ids")
151 .unwrap()
145 .unwrap_or(String::from("env_not_found"))
152146 .split(' ')
153147 .map(|id| format!("'{}/watch?v={id}'", mainconfig.invidious_instance,))
154148 .collect::<Vec<_>>()
@@ -160,12 +154,12 @@ pub fn update_provider(data: &mut FrameworkData) {
160154 match status.provider {
161155 Provider::YouTube => format!(
162156 "https://www.youtube.com/channel/{}",
163 env::var("channel-id").unwrap()
157 env::var("channel-id").unwrap_or(String::from("env_not_found"))
164158 ),
165159 Provider::Invidious => format!(
166160 "{}/channel/{}",
167161 mainconfig.invidious_instance,
168 env::var("channel-id").unwrap()
162 env::var("channel-id").unwrap_or(String::from("env_not_found"))
169163 ),
170164 },
171165 ),
src/global/structs/item.rs +2 −8
@@ -1,12 +1,6 @@
1use crate::global::functions::{date_text, secs_display_string, viewcount_text};
1use crate::global::functions::*;
22use invidious::structs::{
3 channel::Channel,
4 hidden::{
5 ChannelVideo, Playlist, PlaylistItem, PopularItem, SearchItem, SearchItemTransition,
6 TrendingVideo,
7 },
8 universal::Playlist as FullPlaylist,
9 video::Video,
3 channel::Channel, hidden::*, universal::Playlist as FullPlaylist, video::Video,
104};
115use serde::{Deserialize, Serialize};
126use std::fmt::Display;
src/global/structs/page.rs +1 −1
@@ -1,6 +1,6 @@
11use std::fmt::Debug;
22
3use crate::config::{PageConfig, PagesConfig, Search};
3use crate::config::*;
44use tui_additions::framework::Framework;
55use typemap::Key;
66
src/global/structs/tasks.rs +9 −4
@@ -1,9 +1,8 @@
11use crate::{
2 config::{AppearanceConfig, MainConfig, MinDimentions},
3 global::functions::{clear_envs, run_command, set_envs, update_provider},
2 config::*,
3 global::{functions::*, structs::*},
44};
55
6use super::{message::Message, page::Page, status::Status, StateEnvs};
76use std::{error::Error, io::Stdout, mem};
87use tui::{
98 backend::CrosstermBackend, layout::Alignment, style::Style, widgets::Paragraph, Frame, Terminal,
@@ -187,7 +186,13 @@ impl TaskQueue {
187186 RenderTask::None => {}
188187 }
189188
190 if framework.data.global.get::<Status>().unwrap().provider_updated {
189 if framework
190 .data
191 .global
192 .get::<Status>()
193 .unwrap()
194 .provider_updated
195 {
191196 update_provider(&mut framework.data);
192197 }
193198
src/global/structs/watchhistory.rs +1 −3
@@ -1,6 +1,4 @@
1use crate::global::traits::Collection;
2
3use super::Item;
1use crate::global::{structs::Item, traits::Collection};
42use serde::{Deserialize, Serialize};
53use typemap::Key;
64
src/global/traits/collection.rs +1 −2
@@ -1,3 +1,4 @@
1use crate::global::structs::Item;
12use home::home_dir;
23use serde::{de::DeserializeOwned, Serialize};
34use std::{
@@ -7,8 +8,6 @@ use std::{
78};
89use typemap::Key;
910
10use crate::global::structs::Item;
11
1211pub trait Collection
1312where
1413 Self: Default + Clone + Serialize + DeserializeOwned + Key,
src/init.rs +2 −11
@@ -1,15 +1,6 @@
11use crate::{
2 config::{
3 AppearanceConfig, CommandBindings, CommandBindingsSerde, CommandsConfig,
4 CommandsConfigSerde, KeyBindingsConfig, MainConfig, MinDimentions, PagesConfig, Search,
5 },
6 global::{
7 functions::{init_move, run_command},
8 structs::{
9 InvidiousClient, Library, Message, Page, StateEnvs, Status, Tasks, WatchHistory,
10 },
11 traits::{Collection, ConfigTrait},
12 },
2 config::*,
3 global::{functions::*, structs::*, traits::*},
134};
145use home::home_dir;
156use std::{error::Error, fs, io::Stdout};
src/items/channeldisplay.rs +2 −8
@@ -1,13 +1,7 @@
11use super::ItemInfo;
22use crate::{
3 config::{AppearanceConfig, KeyBindingsConfig, MainConfig, Provider},
4 global::{
5 functions::{download_all_images, set_envs},
6 structs::{
7 ChannelDisplayPageType, InvidiousClient, Item, KeyAction, Message, Page,
8 SingleItemPage, StateEnvs, Status, Task, Tasks,
9 },
10 },
3 config::*,
4 global::{functions::*, structs::*},
115};
126use tui::{
137 layout::{Constraint, Rect},
src/items/iteminfo.rs +2 −4
@@ -7,10 +7,7 @@ use tui_additions::framework::FrameworkItem;
77#[cfg(any(feature = "sixel", feature = "halfblock"))]
88use viuer::{print_from_file, Config};
99
10use crate::{
11 config::{AppearanceConfig, MainConfig},
12 global::structs::{Item, Status, Task, Tasks},
13};
10use crate::{config::*, global::structs::*};
1411
1512/// an item info displays info of any `Item`s
1613#[derive(Clone)]
@@ -74,6 +71,7 @@ impl FrameworkItem for ItemInfo {
7471 } as u32),
7572 x: area.x,
7673 y: area.y as i16,
74 #[cfg(not(any(feature = "sixel", feature = "halfblock")))]
7775 use_sixel: main_config.images.use_sixels(),
7876 ..Default::default()
7977 };
src/items/itemlist.rs +5 −14
@@ -1,5 +1,10 @@
11use std::error::Error;
22
3use crate::{
4 config::*,
5 global::{functions::*, structs::*},
6 items::ItemInfo,
7};
38use home::home_dir;
49use tui::{
510 layout::{Constraint, Rect},
@@ -10,20 +15,6 @@ use tui_additions::{
1015 widgets::{Grid, TextList},
1116};
1217
13use super::ItemInfo;
14use crate::{
15 config::{AppearanceConfig, KeyBindingsConfig, MainConfig, Provider, Search},
16 global::{
17 functions::{download_all_images, set_envs, update_provider},
18 structs::{
19 ChannelDisplayPage, ChannelDisplayPageType, FullChannelItem, FullPlaylistItem,
20 FullVideoItem, InvidiousClient, Item, KeyAction, Library, MainMenuPage, Message,
21 MiniChannelItem, MiniPlaylistItem, MiniVideoItem, Page, SingleItemPage, StateEnvs,
22 Status, Task, Tasks, WatchHistory,
23 },
24 },
25};
26
2718/// An item list displays a list of items
2819// It consists of a 1 x 2 grid, with the left cell displaying a text list, the right displaying item info of the currently hovered item
2920#[derive(Clone)]
src/items/messagebar.rs +1 −4
@@ -1,7 +1,4 @@
1use crate::{
2 config::{AppearanceConfig, MainConfig},
3 global::structs::{Message, Status},
4};
1use crate::{config::*, global::structs::*};
52use tui::{
63 layout::Rect,
74 style::Style,
src/items/pagebutton.rs +1 −6
@@ -1,9 +1,4 @@
1use crate::{
2 config::AppearanceConfig,
3 global::structs::{
4 ChannelDisplayPage, ChannelDisplayPageType, MainMenuPage, Message, Page, Task, Tasks,
5 },
6};
1use crate::{config::AppearanceConfig, global::structs::*};
72use tui::{
83 layout::Alignment,
94 style::Style,
src/items/searchbar.rs +6 −7
@@ -1,12 +1,10 @@
11use std::error::Error;
22
3use crate::{
4 config::{AppearanceConfig, KeyBindingsConfig, Search},
5 global::{
6 functions::get_clipboard,
7 structs::{KeyAction, Message, Page, Task, Tasks},
8 },
9};
3use crate::{config::*, global::structs::*};
4
5#[cfg(feature = "clipboard")]
6use crate::global::functions::*;
7
108use crossterm::event::KeyCode;
119use tui::{
1210 layout::Alignment,
@@ -80,6 +78,7 @@ impl FrameworkItem for SearchBar {
8078 _info: tui_additions::framework::ItemInfo,
8179 ) -> Result<(), Box<dyn Error>> {
8280 // pasting clipboard content
81 #[cfg(feature = "clipboard")]
8382 if framework
8483 .data
8584 .global
src/items/searchfilters.rs +2 −5
@@ -1,9 +1,6 @@
11use crate::{
2 config::{AppearanceConfig, KeyBindingsConfig, MainConfig, Search, SearchFilters},
3 global::{
4 functions::popup_area,
5 structs::{KeyAction, Message, Page, Status, Task, Tasks},
6 },
2 config::*,
3 global::{functions::popup_area, structs::*},
74};
85use tui::{
96 layout::{Alignment, Constraint, Rect},
src/items/singleitem.rs +24 −18
@@ -2,15 +2,8 @@ use std::fs;
22
33use super::ItemInfo;
44use crate::{
5 config::{AppearanceConfig, CommandsConfig, KeyBindingsConfig, MainConfig, Provider},
6 global::{
7 functions::{apply_envs, load_playlist, load_video, set_envs},
8 structs::{
9 InvidiousClient, Item, KeyAction, Message, Page, SingleItemPage, StateEnvs, Status,
10 Task, Tasks, WatchHistory,
11 },
12 traits::Collection,
13 },
5 config::*,
6 global::{functions::*, structs::*, traits::Collection},
147};
158use home::home_dir;
169use tui::{
@@ -73,10 +66,14 @@ pub struct SinglePlaylistItem {
7366impl SingleVideoItem {
7467 pub fn new(commands: &CommandsConfig, mainconfig: &MainConfig, id: &str) -> Self {
7568 let saved = (|| -> Option<()> {
76 fs::read_dir(home_dir().unwrap().join(mainconfig.env.get("save-path")?.replacen("~/", "", 1)))
77 .ok()?
78 .filter_map(|entry| Some(entry.ok()?.path().file_stem()?.to_os_string()))
79 .find(|stem| stem.as_os_str().to_str().unwrap_or_default().contains(id))?;
69 fs::read_dir(
70 home_dir()
71 .unwrap()
72 .join(mainconfig.env.get("save-path")?.replacen("~/", "", 1)),
73 )
74 .ok()?
75 .filter_map(|entry| Some(entry.ok()?.path().file_stem()?.to_os_string()))
76 .find(|stem| stem.as_os_str().to_str().unwrap_or_default().contains(id))?;
8077 Some(())
8178 })()
8279 .is_some();
@@ -196,12 +193,21 @@ impl SingleVideoItem {
196193}
197194
198195impl SinglePlaylistItem {
199 pub fn new(commands: &CommandsConfig, mainconfig: &MainConfig ,id: &str, playlist_items: &[Item]) -> Self {
196 pub fn new(
197 commands: &CommandsConfig,
198 mainconfig: &MainConfig,
199 id: &str,
200 playlist_items: &[Item],
201 ) -> Self {
200202 let saved = (|| -> Option<()> {
201 fs::read_dir(home_dir().unwrap().join(mainconfig.env.get("save-path")?.replacen("~/", "", 1)))
202 .ok()?
203 .filter_map(|entry| Some(entry.ok()?.path().file_stem()?.to_os_string()))
204 .find(|stem| stem.as_os_str().to_str().unwrap_or_default().contains(id))?;
203 fs::read_dir(
204 home_dir()
205 .unwrap()
206 .join(mainconfig.env.get("save-path")?.replacen("~/", "", 1)),
207 )
208 .ok()?
209 .filter_map(|entry| Some(entry.ok()?.path().file_stem()?.to_os_string()))
210 .find(|stem| stem.as_os_str().to_str().unwrap_or_default().contains(id))?;
205211 Some(())
206212 })()
207213 .is_some();
src/run.rs +2 −7
@@ -7,13 +7,8 @@ use tui_additions::{
77};
88
99use crate::{
10 config::{CommandBindings, KeyBindingsConfig, MainConfig},
11 global::{
12 functions::{
13 apply_envs, clear_envs, command_capture, run_command, set_envs, update_provider,
14 },
15 structs::{KeyAction, Message, Page, StateEnvs, Status, Task, Tasks},
16 },
10 config::*,
11 global::{functions::*, structs::*},
1712};
1813
1914/// the main event loop of the program