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 = [
326 "syn", 326 "syn",
327] 327]
328 328
329[[package]]
330name = "dunce"
331version = "1.0.3"
332source = "registry+https://github.com/rust-lang/crates.io-index"
333checksum = "0bd4b30a6560bbd9b4620f4de34c3f14f60848e58a9b7216801afcb4c7b31c3c"
334
335[[package]] 329[[package]]
336name = "dyn-clone" 330name = "dyn-clone"
337version = "1.0.10" 331version = "1.0.10"
@@ -458,16 +452,6 @@ dependencies = [
458 "percent-encoding", 452 "percent-encoding",
459] 453]
460 454
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
471[[package]] 455[[package]]
472name = "futures" 456name = "futures"
473version = "0.3.26" 457version = "0.3.26"
@@ -1136,12 +1120,6 @@ dependencies = [
1136 "miniz_oxide", 1120 "miniz_oxide",
1137] 1121]
1138 1122
1139[[package]]
1140name = "ppv-lite86"
1141version = "0.2.17"
1142source = "registry+https://github.com/rust-lang/crates.io-index"
1143checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de"
1144
1145[[package]] 1123[[package]]
1146name = "proc-macro2" 1124name = "proc-macro2"
1147version = "1.0.51" 1125version = "1.0.51"
@@ -1160,36 +1138,6 @@ dependencies = [
1160 "proc-macro2", 1138 "proc-macro2",
1161] 1139]
1162 1140
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
1193[[package]] 1141[[package]]
1194name = "rayon" 1142name = "rayon"
1195version = "1.6.1" 1143version = "1.6.1"
@@ -1267,15 +1215,6 @@ dependencies = [
1267 "bytemuck", 1215 "bytemuck",
1268] 1216]
1269 1217
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
1279[[package]] 1218[[package]]
1280name = "rustix" 1219name = "rustix"
1281version = "0.36.8" 1220version = "0.36.8"
@@ -2005,7 +1944,6 @@ dependencies = [
2005 "home", 1944 "home",
2006 "invidious", 1945 "invidious",
2007 "reqwest", 1946 "reqwest",
2008 "run_script",
2009 "serde", 1947 "serde",
2010 "serde_json", 1948 "serde_json",
2011 "serde_yaml", 1949 "serde_yaml",
Cargo.toml +3 −3
@@ -16,9 +16,10 @@ exclude = ["/docs", "/LICENSE"]
16# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 16# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
17 17
18[features] 18[features]
19default = ["sixel", "halfblock"] 19default = ["sixel", "halfblock", "clipboard"]
20sixel = ["viuer/sixel"] 20sixel = ["viuer/sixel"]
21halfblock = ["viuer"] 21halfblock = ["viuer"]
22clipboard = ["dep:clipboard"]
22 23
23[dependencies] 24[dependencies]
24serde = {version = "1.0", default-features = false, features = ["derive"]} 25serde = {version = "1.0", default-features = false, features = ["derive"]}
@@ -36,8 +37,7 @@ tokio = {version = "1.21", default-features = false}
36futures = {version = "0.3", default-features = false} 37futures = {version = "0.3", default-features = false}
37reqwest = {version = "0.11", default-features = false} 38reqwest = {version = "0.11", default-features = false}
38serde_json = {version = "1.0", default-features = false} 39serde_json = {version = "1.0", default-features = false}
39run_script = { version = "0.10", default-features = false} 40clipboard = {version = "0.5", optional = true}
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"]}
43# invidious = {path = "../../Rust/Packages/invidious", default-features = false, features = ["reqwest"]} 43# 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};
1use std::{ 4use std::{
2 error::Error, 5 error::Error,
3 fs::{self, OpenOptions}, 6 fs::{self, OpenOptions},
4 io::Write, 7 io::Write,
5}; 8};
6
7use super::serde::{BorderTypeSerde, ColorSerde, ColorVariantSerde};
8use crate::global::traits::{ConfigTrait, EXTENSION};
9use home::home_dir;
10use serde::{Deserialize, Serialize};
11use tui::{style::Color, widgets::BorderType}; 9use tui::{style::Color, widgets::BorderType};
12use typemap::Key; 10use typemap::Key;
13 11
src/config/commandbindings.rs +25 −28
@@ -3,10 +3,7 @@ use serde::{Deserialize, Serialize};
3use std::collections::HashMap; 3use std::collections::HashMap;
4use typemap::Key; 4use typemap::Key;
5 5
6use crate::global::{ 6use crate::global::{structs::*, traits::ConfigTrait};
7 structs::{ChannelDisplayPage, ChannelDisplayPageType, MainMenuPage, Page, SingleItemPage},
8 traits::ConfigTrait,
9};
10 7
11use super::serde::KeyCodeSerde; 8use super::serde::KeyCodeSerde;
12 9
@@ -179,9 +176,9 @@ fn global_default() -> HashMap<KeyCodeSerde, HashMap<u8, String>> {
179 176
180fn search_default() -> HashMap<KeyCodeSerde, HashMap<u8, String>> { 177fn search_default() -> HashMap<KeyCodeSerde, HashMap<u8, String>> {
181 HashMap::from([ 178 HashMap::from([
182 (KeyCodeSerde::Char('a'), HashMap::from([(2, String::from("run ${terminal-emulator} mpv '${hover-url}' --no-video"))])), 179 (KeyCodeSerde::Char('a'), HashMap::from([(2, String::from("parrun ${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"))])), 180 (KeyCodeSerde::Char('A'), HashMap::from([(1, String::from("parrun ${terminal-emulator} mpv '${hover-url}' --no-video --loop-playlist=inf --shuffle"))])),
184 (KeyCodeSerde::Char('p'), HashMap::from([(2, String::from("run mpv '${hover-url}'"))])), 181 (KeyCodeSerde::Char('p'), HashMap::from([(2, String::from("parrun mpv '${hover-url}'"))])),
185 ]) 182 ])
186} 183}
187 184
@@ -191,41 +188,41 @@ fn channel_main_default() -> HashMap<KeyCodeSerde, HashMap<u8, String>> {
191 188
192fn channel_playlists_default() -> HashMap<KeyCodeSerde, HashMap<u8, String>> { 189fn channel_playlists_default() -> HashMap<KeyCodeSerde, HashMap<u8, String>> {
193 HashMap::from([ 190 HashMap::from([
194 (KeyCodeSerde::Char('a'), HashMap::from([(2, String::from("run ${terminal-emulator} mpv '${hover-url}' --no-video"))])), 191 (KeyCodeSerde::Char('a'), HashMap::from([(2, String::from("parrun ${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"))])), 192 (KeyCodeSerde::Char('A'), HashMap::from([(1, String::from("parrun ${terminal-emulator} mpv '${hover-url}' --no-video --loop-playlist=inf --shuffle"))])),
196 (KeyCodeSerde::Char('p'), HashMap::from([(2, String::from("run mpv '${hover-url}'"))])), 193 (KeyCodeSerde::Char('p'), HashMap::from([(2, String::from("parrun mpv '${hover-url}'"))])),
197 ]) 194 ])
198} 195}
199 196
200fn channel_videos_default() -> HashMap<KeyCodeSerde, HashMap<u8, String>> { 197fn channel_videos_default() -> HashMap<KeyCodeSerde, HashMap<u8, String>> {
201 HashMap::from([ 198 HashMap::from([
202 (KeyCodeSerde::Char('a'), HashMap::from([(2, String::from("run ${terminal-emulator} mpv '${hover-url}' --no-video"))])), 199 (KeyCodeSerde::Char('a'), HashMap::from([(2, String::from("parrun ${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"))])), 200 (KeyCodeSerde::Char('A'), HashMap::from([(1, String::from("parrun ${terminal-emulator} mpv '${hover-url}' --no-video --loop-playlist=inf --shuffle"))])),
204 (KeyCodeSerde::Char('p'), HashMap::from([(2, String::from("run mpv '${hover-url}'"))])), 201 (KeyCodeSerde::Char('p'), HashMap::from([(2, String::from("parrun mpv '${hover-url}'"))])),
205 ]) 202 ])
206} 203}
207 204
208fn playlist_default() -> HashMap<KeyCodeSerde, HashMap<u8, String>> { 205fn playlist_default() -> HashMap<KeyCodeSerde, HashMap<u8, String>> {
209 HashMap::from([ 206 HashMap::from([
210 (KeyCodeSerde::Char('a'), HashMap::from([(2, String::from("run ${terminal-emulator} mpv '${hover-url}' --no-video"))])), 207 (KeyCodeSerde::Char('a'), HashMap::from([(2, String::from("parrun ${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"))])), 208 (KeyCodeSerde::Char('A'), HashMap::from([(1, String::from("parrun ${terminal-emulator} mpv '${hover-url}' --no-video --loop-playlist=inf --shuffle"))])),
212 (KeyCodeSerde::Char('p'), HashMap::from([(2, String::from("run mpv '${hover-url}'"))])), 209 (KeyCodeSerde::Char('p'), HashMap::from([(2, String::from("parrun mpv '${hover-url}'"))])),
213 ]) 210 ])
214} 211}
215 212
216fn popular_default() -> HashMap<KeyCodeSerde, HashMap<u8, String>> { 213fn popular_default() -> HashMap<KeyCodeSerde, HashMap<u8, String>> {
217 HashMap::from([ 214 HashMap::from([
218 (KeyCodeSerde::Char('a'), HashMap::from([(2, String::from("run ${terminal-emulator} mpv '${hover-url}' --no-video"))])), 215 (KeyCodeSerde::Char('a'), HashMap::from([(2, String::from("parrun ${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"))])), 216 (KeyCodeSerde::Char('A'), HashMap::from([(1, String::from("parrun ${terminal-emulator} mpv '${hover-url}' --no-video --loop-playlist=inf --shuffle"))])),
220 (KeyCodeSerde::Char('p'), HashMap::from([(2, String::from("run mpv '${hover-url}'"))])), 217 (KeyCodeSerde::Char('p'), HashMap::from([(2, String::from("parrun mpv '${hover-url}'"))])),
221 ]) 218 ])
222} 219}
223 220
224fn trending_default() -> HashMap<KeyCodeSerde, HashMap<u8, String>> { 221fn trending_default() -> HashMap<KeyCodeSerde, HashMap<u8, String>> {
225 HashMap::from([ 222 HashMap::from([
226 (KeyCodeSerde::Char('a'), HashMap::from([(2, String::from("run ${terminal-emulator} mpv '${hover-url}' --no-video"))])), 223 (KeyCodeSerde::Char('a'), HashMap::from([(2, String::from("parrun ${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"))])), 224 (KeyCodeSerde::Char('A'), HashMap::from([(1, String::from("parrun ${terminal-emulator} mpv '${hover-url}' --no-video --loop-playlist=inf --shuffle"))])),
228 (KeyCodeSerde::Char('p'), HashMap::from([(2, String::from("run mpv '${hover-url}'"))])), 225 (KeyCodeSerde::Char('p'), HashMap::from([(2, String::from("parrun mpv '${hover-url}'"))])),
229 ]) 226 ])
230} 227}
231 228
@@ -235,9 +232,9 @@ fn video_default() -> HashMap<KeyCodeSerde, HashMap<u8, String>> {
235 232
236fn watchhistory_default() -> HashMap<KeyCodeSerde, HashMap<u8, String>> { 233fn watchhistory_default() -> HashMap<KeyCodeSerde, HashMap<u8, String>> {
237 HashMap::from([ 234 HashMap::from([
238 (KeyCodeSerde::Char('a'), HashMap::from([(2, String::from("run ${terminal-emulator} mpv '${hover-url}' --no-video"))])), 235 (KeyCodeSerde::Char('a'), HashMap::from([(2, String::from("parrun ${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"))])), 236 (KeyCodeSerde::Char('A'), HashMap::from([(1, String::from("parrun ${terminal-emulator} mpv '${hover-url}' --no-video --loop-playlist=inf --shuffle"))])),
240 (KeyCodeSerde::Char('p'), HashMap::from([(2, String::from("run mpv '${hover-url}'"))])) 237 (KeyCodeSerde::Char('p'), HashMap::from([(2, String::from("parrun mpv '${hover-url}'"))]))
241 ]) 238 ])
242} 239}
243 240
@@ -247,8 +244,8 @@ fn subscriptions_default() -> HashMap<KeyCodeSerde, HashMap<u8, String>> {
247 244
248fn library_default() -> HashMap<KeyCodeSerde, HashMap<u8, String>> { 245fn library_default() -> HashMap<KeyCodeSerde, HashMap<u8, String>> {
249 HashMap::from([ 246 HashMap::from([
250 (KeyCodeSerde::Char('a'), HashMap::from([(2, String::from("run ${terminal-emulator} mpv '${hover-url}' --no-video"))])), 247 (KeyCodeSerde::Char('a'), HashMap::from([(2, String::from("parrun ${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"))])), 248 (KeyCodeSerde::Char('A'), HashMap::from([(1, String::from("parrun ${terminal-emulator} mpv '${hover-url}' --no-video --loop-playlist=inf --shuffle"))])),
252 (KeyCodeSerde::Char('p'), HashMap::from([(2, String::from("run mpv '${hover-url}'"))])) 249 (KeyCodeSerde::Char('p'), HashMap::from([(2, String::from("parrun mpv '${hover-url}'"))]))
253 ]) 250 ])
254} 251}
src/config/commands.rs +24 −24
@@ -94,16 +94,16 @@ fn video_default() -> Vec<HashMap<String, String>> {
94 )]), 94 )]),
95 HashMap::from([( 95 HashMap::from([(
96 String::from("Play video"), 96 String::from("Play video"),
97 String::from("run ${video-player} '${embed-url}'"), 97 String::from("parrun ${video-player} '${embed-url}'"),
98 )]), 98 )]),
99 HashMap::from([( 99 HashMap::from([(
100 String::from("Play audio"), 100 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"),
102 )]), 102 )]),
103 HashMap::from([( 103 HashMap::from([(
104 String::from("Play audio (loop)"), 104 String::from("Play audio (loop)"),
105 String::from( 105 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",
107 ), 107 ),
108 )]), 108 )]),
109 HashMap::from([( 109 HashMap::from([(
@@ -112,7 +112,7 @@ fn video_default() -> Vec<HashMap<String, String>> {
112 )]), 112 )]),
113 HashMap::from([( 113 HashMap::from([(
114 String::from("Open in browser"), 114 String::from("Open in browser"),
115 String::from("run ${browser} '${url}'"), 115 String::from("parrun ${browser} '${url}'"),
116 )]), 116 )]),
117 HashMap::from([( 117 HashMap::from([(
118 String::from("Toggle bookmark"), 118 String::from("Toggle bookmark"),
@@ -120,11 +120,11 @@ fn video_default() -> Vec<HashMap<String, String>> {
120 )]), 120 )]),
121 HashMap::from([( 121 HashMap::from([(
122 String::from("Save video to library"), 122 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'")
124 )]), 124 )]),
125 HashMap::from([( 125 HashMap::from([(
126 String::from("Save audio to library"), 126 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'")
128 )]), 128 )]),
129 HashMap::from([( 129 HashMap::from([(
130 String::from("Mode: ${provider}"), 130 String::from("Mode: ${provider}"),
@@ -141,15 +141,15 @@ fn saved_video_default() -> Vec<HashMap<String, String>> {
141 )]), 141 )]),
142 HashMap::from([( 142 HashMap::from([(
143 String::from("[Offline] Play saved file"), 143 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"),
145 )]), 145 )]),
146 HashMap::from([( 146 HashMap::from([(
147 String::from("[Offline] Play saved file (audio)"), 147 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'"),
149 )]), 149 )]),
150 HashMap::from([( 150 HashMap::from([(
151 String::from("[Offline] Play saved file (audio loop)"), 151 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'"),
153 )]), 153 )]),
154 HashMap::from([( 154 HashMap::from([(
155 String::from("View channel"), 155 String::from("View channel"),
@@ -157,7 +157,7 @@ fn saved_video_default() -> Vec<HashMap<String, String>> {
157 )]), 157 )]),
158 HashMap::from([( 158 HashMap::from([(
159 String::from("Open in browser"), 159 String::from("Open in browser"),
160 String::from("run ${browser} '${url}'"), 160 String::from("parrun ${browser} '${url}'"),
161 )]), 161 )]),
162 HashMap::from([( 162 HashMap::from([(
163 String::from("Toggle bookmark"), 163 String::from("Toggle bookmark"),
@@ -165,11 +165,11 @@ fn saved_video_default() -> Vec<HashMap<String, String>> {
165 )]), 165 )]),
166 HashMap::from([( 166 HashMap::from([(
167 String::from("Redownload video to library"), 167 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'"),
169 )]), 169 )]),
170 HashMap::from([( 170 HashMap::from([(
171 String::from("Redownload audio to library"), 171 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'")
173 )]), 173 )]),
174 HashMap::from([( 174 HashMap::from([(
175 String::from("Delete saved file"), 175 String::from("Delete saved file"),
@@ -187,15 +187,15 @@ fn playlist_default() -> Vec<HashMap<String, String>> {
187 )]), 187 )]),
188 HashMap::from([( 188 HashMap::from([(
189 String::from("Play all (videos)"), 189 String::from("Play all (videos)"),
190 String::from("run ${video-player} ${all-videos}"), 190 String::from("parrun ${video-player} ${all-videos}"),
191 )]), 191 )]),
192 HashMap::from([( 192 HashMap::from([(
193 String::from("Play all (audio)"), 193 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"),
195 )]), 195 )]),
196 HashMap::from([( 196 HashMap::from([(
197 String::from("Shuffle play all (audio loop)"), 197 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"),
199 )]), 199 )]),
200 HashMap::from([( 200 HashMap::from([(
201 String::from("View channel"), 201 String::from("View channel"),
@@ -203,7 +203,7 @@ fn playlist_default() -> Vec<HashMap<String, String>> {
203 )]), 203 )]),
204 HashMap::from([( 204 HashMap::from([(
205 String::from("Open in browser"), 205 String::from("Open in browser"),
206 String::from("run ${browser} '${url}'"), 206 String::from("parrun ${browser} '${url}'"),
207 )]), 207 )]),
208 HashMap::from([( 208 HashMap::from([(
209 String::from("Toggle bookmark"), 209 String::from("Toggle bookmark"),
@@ -211,11 +211,11 @@ fn playlist_default() -> Vec<HashMap<String, String>> {
211 )]), 211 )]),
212 HashMap::from([( 212 HashMap::from([(
213 String::from("Save playlist videos to library"), 213 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'\"'\"")
215 )]), 215 )]),
216 HashMap::from([( 216 HashMap::from([(
217 String::from("Save playlist audio to library"), 217 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'\"'\"")
219 )]), 219 )]),
220 HashMap::from([( 220 HashMap::from([(
221 String::from("Mode: ${provider}"), 221 String::from("Mode: ${provider}"),
@@ -233,15 +233,15 @@ fn saved_playlist_default() -> Vec<HashMap<String, String>> {
233 )]), 233 )]),
234 HashMap::from([( 234 HashMap::from([(
235 String::from("[Offline] Play all (videos)"), 235 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"),
237 )]), 237 )]),
238 HashMap::from([( 238 HashMap::from([(
239 String::from("[Offline] Play all (audio)"), 239 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'"),
241 )]), 241 )]),
242 HashMap::from([( 242 HashMap::from([(
243 String::from("[Offline] Shuffle play all (audio loop)"), 243 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'"),
245 )]), 245 )]),
246 HashMap::from([( 246 HashMap::from([(
247 String::from("View channel"), 247 String::from("View channel"),
@@ -249,7 +249,7 @@ fn saved_playlist_default() -> Vec<HashMap<String, String>> {
249 )]), 249 )]),
250 HashMap::from([( 250 HashMap::from([(
251 String::from("Open in browser"), 251 String::from("Open in browser"),
252 String::from("run ${browser} '${url}'"), 252 String::from("parrun ${browser} '${url}'"),
253 )]), 253 )]),
254 HashMap::from([( 254 HashMap::from([(
255 String::from("Toggle bookmark"), 255 String::from("Toggle bookmark"),
@@ -257,11 +257,11 @@ fn saved_playlist_default() -> Vec<HashMap<String, String>> {
257 )]), 257 )]),
258 HashMap::from([( 258 HashMap::from([(
259 String::from("Redownload playlist videos to library"), 259 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'\"'\"")
261 )]), 261 )]),
262 HashMap::from([( 262 HashMap::from([(
263 String::from("Redownload playlist audio to library"), 263 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'\"'\"")
265 )]), 265 )]),
266 HashMap::from([( 266 HashMap::from([(
267 String::from("Delete saved files"), 267 String::from("Delete saved files"),
src/config/main.rs +7
@@ -27,6 +27,8 @@ pub struct MainConfig {
27 pub image_index: usize, 27 pub image_index: usize,
28 #[serde(default = "provider_default")] 28 #[serde(default = "provider_default")]
29 pub provider: Provider, 29 pub provider: Provider,
30 #[serde(default = "shell_default")]
31 pub shell: String,
30 #[serde(default = "default_env")] 32 #[serde(default = "default_env")]
31 pub env: HashMap<String, String>, 33 pub env: HashMap<String, String>,
32} 34}
@@ -48,6 +50,7 @@ impl Default for MainConfig {
48 refresh_after_modifying_search_filters: refresh_after_modifying_search_filters_default( 50 refresh_after_modifying_search_filters: refresh_after_modifying_search_filters_default(
49 ), 51 ),
50 provider: provider_default(), 52 provider: provider_default(),
53 shell: shell_default(),
51 54
52 env: default_env(), 55 env: default_env(),
53 } 56 }
@@ -155,3 +158,7 @@ fn default_env() -> HashMap<String, String> {
155 ), 158 ),
156 ]) 159 ])
157} 160}
161
162fn shell_default() -> String {
163 String::from("sh")
164}
src/config/pages.rs +2 −7
@@ -1,13 +1,8 @@
1use crate::{ 1use crate::{global::traits::ConfigTrait, items::*};
2 global::traits::ConfigTrait,
3 items::{
4 ChannelDisplay, ItemList, MessageBar, PageButton, SearchBar, SearchFilter, SingleItem,
5 },
6};
7use serde::{Deserialize, Serialize}; 2use serde::{Deserialize, Serialize};
8use std::slice; 3use std::slice;
9use tui::layout::Constraint; 4use tui::layout::Constraint;
10use tui_additions::framework::{Framework, FrameworkItem, Row, RowItem, State}; 5use tui_additions::framework::*;
11use typemap::Key; 6use typemap::Key;
12 7
13/// Minimum screen dimention for the tui to display without panicking, stored in `data.state` 8/// 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::{ 1use crate::global::{structs::Message, traits::*};
2 structs::Message,
3 traits::{AsUrlString, ConfigTrait, SearchFilterItem},
4};
5use serde::{Deserialize, Serialize}; 2use serde::{Deserialize, Serialize};
6use typemap::Key; 3use typemap::Key;
7 4
src/global/functions/command_capture.rs +6 −5
@@ -1,13 +1,14 @@
1use super::{apply_envs, get_clipboard}; 1use crate::global::{functions::*, structs::*};
2use crate::{ 2
3 config::KeyBindingsConfig, 3#[cfg(feature = "clipboard")]
4 global::structs::{KeyAction, Message, Status, Task, Tasks}, 4use crate::config::*;
5}; 5
6use crossterm::event::{KeyCode, KeyEvent}; 6use crossterm::event::{KeyCode, KeyEvent};
7use tui_additions::framework::FrameworkClean; 7use tui_additions::framework::FrameworkClean;
8 8
9/// handles key input when the user is entering commands 9/// handles key input when the user is entering commands
10pub fn command_capture(framework: &mut FrameworkClean, key: KeyEvent) -> bool { 10pub fn command_capture(framework: &mut FrameworkClean, key: KeyEvent) -> bool {
11 #[cfg(feature = "clipboard")]
11 if framework 12 if framework
12 .data 13 .data
13 .global 14 .global
src/global/functions/fake_rand.rs +1 −1
@@ -1,5 +1,5 @@
1use chrono::Utc; 1use chrono::Utc;
2use std::ops::{Add, Rem, Sub}; 2use std::ops::*;
3 3
4/// generate a random number between range 4/// generate a random number between range
5pub fn fake_rand_range<T>(from: T, to: T) -> T 5pub fn fake_rand_range<T>(from: T, to: T) -> T
src/global/functions/mod.rs +2
@@ -15,7 +15,9 @@ mod command_capture;
15pub use command_capture::command_capture; 15pub use command_capture::command_capture;
16mod fake_rand; 16mod fake_rand;
17pub use fake_rand::*; 17pub use fake_rand::*;
18#[cfg(feature = "clipboard")]
18mod clipboard; 19mod clipboard;
20#[cfg(feature = "clipboard")]
19pub use self::clipboard::*; 21pub use self::clipboard::*;
20mod from_url; 22mod from_url;
21pub use from_url::*; 23pub use from_url::*;
src/global/functions/run_command.rs +34 −22
@@ -1,25 +1,19 @@
1use crate::{ 1use crate::{
2 config::Search, 2 config::*,
3 global::{ 3 global::{functions::*, structs::*, traits::*},
4 structs::{
5 ChannelDisplayPage, ChannelDisplayPageType, Item, Library, MainMenuPage, Message, Page,
6 SingleItemPage, Status, Task, Tasks,
7 },
8 traits::Collection,
9 },
10 load_configs, 4 load_configs,
11}; 5};
12use home::home_dir; 6use home::home_dir;
13use run_script::ScriptOptions; 7use std::{
14use std::{env, error::Error, fs, io::Stdout, thread}; 8 env,
9 error::Error,
10 fs,
11 io::Stdout,
12 process::{Command, Stdio},
13};
15use tui::{backend::CrosstermBackend, Terminal}; 14use tui::{backend::CrosstermBackend, Terminal};
16use tui_additions::framework::Framework; 15use tui_additions::framework::Framework;
17 16
18use super::{
19 fake_rand_range, from_channel_url, from_playlist_url, from_video_url, set_clipboard,
20 update_provider,
21};
22
23/// runs text command - command from the command line (not TUI) which response is just a string 17/// runs text command - command from the command line (not TUI) which response is just a string
24pub fn text_command(command: &str) -> Option<String> { 18pub fn text_command(command: &str) -> Option<String> {
25 match command 19 match command
@@ -313,22 +307,39 @@ pub fn run_single_command(
313 env!("CARGO_PKG_VERSION") 307 env!("CARGO_PKG_VERSION")
314 )); 308 ));
315 } 309 }
316 ["run"] => { 310 ["run"] | ["parrun"] => {
317 *framework.data.global.get_mut::<Message>().unwrap() = 311 *framework.data.global.get_mut::<Message>().unwrap() =
318 Message::Message(String::from("Usage: run [command]")); 312 Message::Message(String::from("Usage: run/parrun [command]"));
319 } 313 }
320 ["run", ..] => { 314 ["run", ..] => {
321 let command = command[1..].join(" "); 315 let command = command[1..].join(" ");
322 *framework.data.global.get_mut::<Message>().unwrap() = 316 *framework.data.global.get_mut::<Message>().unwrap() =
323 Message::Success(command.clone()); 317 Message::Success(command.clone());
324 thread::spawn(move || { 318 if let Ok(mut child) =
325 run_script::run(&command, &Vec::new(), &ScriptOptions::new()).unwrap(); 319 Command::new(&framework.data.global.get::<MainConfig>().unwrap().shell)
326 }); 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();
327 } 337 }
328 ["copy"] | ["cp"] => { 338 ["copy"] | ["cp"] => {
329 *framework.data.global.get_mut::<Message>().unwrap() = 339 *framework.data.global.get_mut::<Message>().unwrap() =
330 Message::Message(String::from("Usage: copy [text]")); 340 Message::Message(String::from("Usage: copy [text]"));
331 } 341 }
342 #[cfg(feature = "clipboard")]
332 ["copy", ..] | ["cp", ..] => { 343 ["copy", ..] | ["cp", ..] => {
333 set_clipboard(command[1..].join(" ")); 344 set_clipboard(command[1..].join(" "));
334 *framework.data.global.get_mut::<Message>().unwrap() = 345 *framework.data.global.get_mut::<Message>().unwrap() =
@@ -390,7 +401,7 @@ const HELP_MSG: &str = "\x1b[32mYouTube TUI commands\x1b[0m
390 \x1b[33mloadpage watchhistory\x1b[0m Loads the watch history page 401 \x1b[33mloadpage watchhistory\x1b[0m Loads the watch history page
391 \x1b[33mloadpage subscriptions\x1b[0m Loads the subscriptions page 402 \x1b[33mloadpage subscriptions\x1b[0m Loads the subscriptions page
392 \x1b[33mloadpage bookmarks\x1b[0m Loads the bookmarks page 403 \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
394 \x1b[33mloadpage search [query]\x1b[0m Loads the search page with the given query 405 \x1b[33mloadpage search [query]\x1b[0m Loads the search page with the given query
395 \x1b[33mloadpage video [identifier]\x1b[0m Loads the video item page 406 \x1b[33mloadpage video [identifier]\x1b[0m Loads the video item page
396 \x1b[33mloadpage playlist [identifier]\x1b[0m Loads the playlist item page 407 \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
405 \x1b[33mreload configs\x1b[0m Reload all config files 416 \x1b[33mreload configs\x1b[0m Reload all config files
406 \x1b[33mflush\x1b[0m Run all tasks in queue immediately 417 \x1b[33mflush\x1b[0m Run all tasks in queue immediately
407 \x1b[33mquit\x1b[0m Immediately exit 418 \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`)
409 \x1b[33mcopy [text]\x1b[0m Copies text to clipboard 421 \x1b[33mcopy [text]\x1b[0m Copies text to clipboard
410 422
411\x1b[91mLIBRARY:\x1b[0m 423\x1b[91mLIBRARY:\x1b[0m
src/global/functions/singleitem_load.rs +2 −6
@@ -1,10 +1,6 @@
1use std::error::Error; 1use crate::{config::MainConfig, global::functions::download_all_images, global::structs::Item};
2
3use invidious::reqwest::blocking::Client; 2use invidious::reqwest::blocking::Client;
4 3use std::error::Error;
5use crate::{config::MainConfig, global::structs::Item};
6
7use super::download_all_images;
8 4
9pub fn load_playlist( 5pub fn load_playlist(
10 client: &Client, 6 client: &Client,
src/global/functions/update_provider.rs +7 −13
@@ -1,13 +1,7 @@
1use std::env; 1use std::env;
2use tui_additions::framework::FrameworkData; 2use tui_additions::framework::FrameworkData;
3 3
4use crate::{ 4use crate::{config::*, global::structs::*};
5 config::{MainConfig, Provider},
6 global::structs::{
7 ChannelDisplayPage, ChannelDisplayPageType, MainMenuPage, Page, SingleItemPage, StateEnvs,
8 Status,
9 },
10};
11 5
12use super::set_envs; 6use super::set_envs;
13 7
@@ -115,13 +109,13 @@ pub fn update_provider(data: &mut FrameworkData) {
115 Provider::YouTube => { 109 Provider::YouTube => {
116 format!( 110 format!(
117 "https://www.youtube.com/channel/{}", 111 "https://www.youtube.com/channel/{}",
118 env::var("channel-id").unwrap() 112 env::var("channel-id").unwrap_or(String::from("env_not_found"))
119 ) 113 )
120 } 114 }
121 Provider::Invidious => format!( 115 Provider::Invidious => format!(
122 "{}/channel/{}", 116 "{}/channel/{}",
123 mainconfig.invidious_instance, 117 mainconfig.invidious_instance,
124 env::var("channel-id").unwrap() 118 env::var("channel-id").unwrap_or(String::from("env_not_found"))
125 ), 119 ),
126 }, 120 },
127 ), 121 ),
@@ -142,13 +136,13 @@ pub fn update_provider(data: &mut FrameworkData) {
142 String::from("all-videos"), 136 String::from("all-videos"),
143 match status.provider { 137 match status.provider {
144 Provider::YouTube => env::var("all-ids") 138 Provider::YouTube => env::var("all-ids")
145 .unwrap() 139 .unwrap_or(String::from("env_not_found"))
146 .split(' ') 140 .split(' ')
147 .map(|id| format!("'https://youtu.be/{id}'")) 141 .map(|id| format!("'https://youtu.be/{id}'"))
148 .collect::<Vec<_>>() 142 .collect::<Vec<_>>()
149 .join(" "), 143 .join(" "),
150 Provider::Invidious => env::var("all-ids") 144 Provider::Invidious => env::var("all-ids")
151 .unwrap() 145 .unwrap_or(String::from("env_not_found"))
152 .split(' ') 146 .split(' ')
153 .map(|id| format!("'{}/watch?v={id}'", mainconfig.invidious_instance,)) 147 .map(|id| format!("'{}/watch?v={id}'", mainconfig.invidious_instance,))
154 .collect::<Vec<_>>() 148 .collect::<Vec<_>>()
@@ -160,12 +154,12 @@ pub fn update_provider(data: &mut FrameworkData) {
160 match status.provider { 154 match status.provider {
161 Provider::YouTube => format!( 155 Provider::YouTube => format!(
162 "https://www.youtube.com/channel/{}", 156 "https://www.youtube.com/channel/{}",
163 env::var("channel-id").unwrap() 157 env::var("channel-id").unwrap_or(String::from("env_not_found"))
164 ), 158 ),
165 Provider::Invidious => format!( 159 Provider::Invidious => format!(
166 "{}/channel/{}", 160 "{}/channel/{}",
167 mainconfig.invidious_instance, 161 mainconfig.invidious_instance,
168 env::var("channel-id").unwrap() 162 env::var("channel-id").unwrap_or(String::from("env_not_found"))
169 ), 163 ),
170 }, 164 },
171 ), 165 ),
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::*;
2use invidious::structs::{ 2use invidious::structs::{
3 channel::Channel, 3 channel::Channel, hidden::*, universal::Playlist as FullPlaylist, video::Video,
4 hidden::{
5 ChannelVideo, Playlist, PlaylistItem, PopularItem, SearchItem, SearchItemTransition,
6 TrendingVideo,
7 },
8 universal::Playlist as FullPlaylist,
9 video::Video,
10}; 4};
11use serde::{Deserialize, Serialize}; 5use serde::{Deserialize, Serialize};
12use std::fmt::Display; 6use std::fmt::Display;
src/global/structs/page.rs +1 −1
@@ -1,6 +1,6 @@
1use std::fmt::Debug; 1use std::fmt::Debug;
2 2
3use crate::config::{PageConfig, PagesConfig, Search}; 3use crate::config::*;
4use tui_additions::framework::Framework; 4use tui_additions::framework::Framework;
5use typemap::Key; 5use typemap::Key;
6 6
src/global/structs/tasks.rs +9 −4
@@ -1,9 +1,8 @@
1use crate::{ 1use crate::{
2 config::{AppearanceConfig, MainConfig, MinDimentions}, 2 config::*,
3 global::functions::{clear_envs, run_command, set_envs, update_provider}, 3 global::{functions::*, structs::*},
4}; 4};
5 5
6use super::{message::Message, page::Page, status::Status, StateEnvs};
7use std::{error::Error, io::Stdout, mem}; 6use std::{error::Error, io::Stdout, mem};
8use tui::{ 7use tui::{
9 backend::CrosstermBackend, layout::Alignment, style::Style, widgets::Paragraph, Frame, Terminal, 8 backend::CrosstermBackend, layout::Alignment, style::Style, widgets::Paragraph, Frame, Terminal,
@@ -187,7 +186,13 @@ impl TaskQueue {
187 RenderTask::None => {} 186 RenderTask::None => {}
188 } 187 }
189 188
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 {
191 update_provider(&mut framework.data); 196 update_provider(&mut framework.data);
192 } 197 }
193 198
src/global/structs/watchhistory.rs +1 −3
@@ -1,6 +1,4 @@
1use crate::global::traits::Collection; 1use crate::global::{structs::Item, traits::Collection};
2
3use super::Item;
4use serde::{Deserialize, Serialize}; 2use serde::{Deserialize, Serialize};
5use typemap::Key; 3use typemap::Key;
6 4
src/global/traits/collection.rs +1 −2
@@ -1,3 +1,4 @@
1use crate::global::structs::Item;
1use home::home_dir; 2use home::home_dir;
2use serde::{de::DeserializeOwned, Serialize}; 3use serde::{de::DeserializeOwned, Serialize};
3use std::{ 4use std::{
@@ -7,8 +8,6 @@ use std::{
7}; 8};
8use typemap::Key; 9use typemap::Key;
9 10
10use crate::global::structs::Item;
11
12pub trait Collection 11pub trait Collection
13where 12where
14 Self: Default + Clone + Serialize + DeserializeOwned + Key, 13 Self: Default + Clone + Serialize + DeserializeOwned + Key,
src/init.rs +2 −11
@@ -1,15 +1,6 @@
1use crate::{ 1use crate::{
2 config::{ 2 config::*,
3 AppearanceConfig, CommandBindings, CommandBindingsSerde, CommandsConfig, 3 global::{functions::*, structs::*, traits::*},
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 },
13}; 4};
14use home::home_dir; 5use home::home_dir;
15use std::{error::Error, fs, io::Stdout}; 6use std::{error::Error, fs, io::Stdout};
src/items/channeldisplay.rs +2 −8
@@ -1,13 +1,7 @@
1use super::ItemInfo; 1use super::ItemInfo;
2use crate::{ 2use crate::{
3 config::{AppearanceConfig, KeyBindingsConfig, MainConfig, Provider}, 3 config::*,
4 global::{ 4 global::{functions::*, structs::*},
5 functions::{download_all_images, set_envs},
6 structs::{
7 ChannelDisplayPageType, InvidiousClient, Item, KeyAction, Message, Page,
8 SingleItemPage, StateEnvs, Status, Task, Tasks,
9 },
10 },
11}; 5};
12use tui::{ 6use tui::{
13 layout::{Constraint, Rect}, 7 layout::{Constraint, Rect},
src/items/iteminfo.rs +2 −4
@@ -7,10 +7,7 @@ use tui_additions::framework::FrameworkItem;
7#[cfg(any(feature = "sixel", feature = "halfblock"))] 7#[cfg(any(feature = "sixel", feature = "halfblock"))]
8use viuer::{print_from_file, Config}; 8use viuer::{print_from_file, Config};
9 9
10use crate::{ 10use crate::{config::*, global::structs::*};
11 config::{AppearanceConfig, MainConfig},
12 global::structs::{Item, Status, Task, Tasks},
13};
14 11
15/// an item info displays info of any `Item`s 12/// an item info displays info of any `Item`s
16#[derive(Clone)] 13#[derive(Clone)]
@@ -74,6 +71,7 @@ impl FrameworkItem for ItemInfo {
74 } as u32), 71 } as u32),
75 x: area.x, 72 x: area.x,
76 y: area.y as i16, 73 y: area.y as i16,
74 #[cfg(not(any(feature = "sixel", feature = "halfblock")))]
77 use_sixel: main_config.images.use_sixels(), 75 use_sixel: main_config.images.use_sixels(),
78 ..Default::default() 76 ..Default::default()
79 }; 77 };
src/items/itemlist.rs +5 −14
@@ -1,5 +1,10 @@
1use std::error::Error; 1use std::error::Error;
2 2
3use crate::{
4 config::*,
5 global::{functions::*, structs::*},
6 items::ItemInfo,
7};
3use home::home_dir; 8use home::home_dir;
4use tui::{ 9use tui::{
5 layout::{Constraint, Rect}, 10 layout::{Constraint, Rect},
@@ -10,20 +15,6 @@ use tui_additions::{
10 widgets::{Grid, TextList}, 15 widgets::{Grid, TextList},
11}; 16};
12 17
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
27/// An item list displays a list of items 18/// An item list displays a list of items
28// 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 19// 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
29#[derive(Clone)] 20#[derive(Clone)]
src/items/messagebar.rs +1 −4
@@ -1,7 +1,4 @@
1use crate::{ 1use crate::{config::*, global::structs::*};
2 config::{AppearanceConfig, MainConfig},
3 global::structs::{Message, Status},
4};
5use tui::{ 2use tui::{
6 layout::Rect, 3 layout::Rect,
7 style::Style, 4 style::Style,
src/items/pagebutton.rs +1 −6
@@ -1,9 +1,4 @@
1use crate::{ 1use crate::{config::AppearanceConfig, global::structs::*};
2 config::AppearanceConfig,
3 global::structs::{
4 ChannelDisplayPage, ChannelDisplayPageType, MainMenuPage, Message, Page, Task, Tasks,
5 },
6};
7use tui::{ 2use tui::{
8 layout::Alignment, 3 layout::Alignment,
9 style::Style, 4 style::Style,
src/items/searchbar.rs +6 −7
@@ -1,12 +1,10 @@
1use std::error::Error; 1use std::error::Error;
2 2
3use crate::{ 3use crate::{config::*, global::structs::*};
4 config::{AppearanceConfig, KeyBindingsConfig, Search}, 4
5 global::{ 5#[cfg(feature = "clipboard")]
6 functions::get_clipboard, 6use crate::global::functions::*;
7 structs::{KeyAction, Message, Page, Task, Tasks}, 7
8 },
9};
10use crossterm::event::KeyCode; 8use crossterm::event::KeyCode;
11use tui::{ 9use tui::{
12 layout::Alignment, 10 layout::Alignment,
@@ -80,6 +78,7 @@ impl FrameworkItem for SearchBar {
80 _info: tui_additions::framework::ItemInfo, 78 _info: tui_additions::framework::ItemInfo,
81 ) -> Result<(), Box<dyn Error>> { 79 ) -> Result<(), Box<dyn Error>> {
82 // pasting clipboard content 80 // pasting clipboard content
81 #[cfg(feature = "clipboard")]
83 if framework 82 if framework
84 .data 83 .data
85 .global 84 .global
src/items/searchfilters.rs +2 −5
@@ -1,9 +1,6 @@
1use crate::{ 1use crate::{
2 config::{AppearanceConfig, KeyBindingsConfig, MainConfig, Search, SearchFilters}, 2 config::*,
3 global::{ 3 global::{functions::popup_area, structs::*},
4 functions::popup_area,
5 structs::{KeyAction, Message, Page, Status, Task, Tasks},
6 },
7}; 4};
8use tui::{ 5use tui::{
9 layout::{Alignment, Constraint, Rect}, 6 layout::{Alignment, Constraint, Rect},
src/items/singleitem.rs +24 −18
@@ -2,15 +2,8 @@ use std::fs;
2 2
3use super::ItemInfo; 3use super::ItemInfo;
4use crate::{ 4use crate::{
5 config::{AppearanceConfig, CommandsConfig, KeyBindingsConfig, MainConfig, Provider}, 5 config::*,
6 global::{ 6 global::{functions::*, structs::*, traits::Collection},
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 },
14}; 7};
15use home::home_dir; 8use home::home_dir;
16use tui::{ 9use tui::{
@@ -73,10 +66,14 @@ pub struct SinglePlaylistItem {
73impl SingleVideoItem { 66impl SingleVideoItem {
74 pub fn new(commands: &CommandsConfig, mainconfig: &MainConfig, id: &str) -> Self { 67 pub fn new(commands: &CommandsConfig, mainconfig: &MainConfig, id: &str) -> Self {
75 let saved = (|| -> Option<()> { 68 let saved = (|| -> Option<()> {
76 fs::read_dir(home_dir().unwrap().join(mainconfig.env.get("save-path")?.replacen("~/", "", 1))) 69 fs::read_dir(
77 .ok()? 70 home_dir()
78 .filter_map(|entry| Some(entry.ok()?.path().file_stem()?.to_os_string())) 71 .unwrap()
79 .find(|stem| stem.as_os_str().to_str().unwrap_or_default().contains(id))?; 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))?;
80 Some(()) 77 Some(())
81 })() 78 })()
82 .is_some(); 79 .is_some();
@@ -196,12 +193,21 @@ impl SingleVideoItem {
196} 193}
197 194
198impl SinglePlaylistItem { 195impl 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 {
200 let saved = (|| -> Option<()> { 202 let saved = (|| -> Option<()> {
201 fs::read_dir(home_dir().unwrap().join(mainconfig.env.get("save-path")?.replacen("~/", "", 1))) 203 fs::read_dir(
202 .ok()? 204 home_dir()
203 .filter_map(|entry| Some(entry.ok()?.path().file_stem()?.to_os_string())) 205 .unwrap()
204 .find(|stem| stem.as_os_str().to_str().unwrap_or_default().contains(id))?; 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))?;
205 Some(()) 211 Some(())
206 })() 212 })()
207 .is_some(); 213 .is_some();
src/run.rs +2 −7
@@ -7,13 +7,8 @@ use tui_additions::{
7}; 7};
8 8
9use crate::{ 9use crate::{
10 config::{CommandBindings, KeyBindingsConfig, MainConfig}, 10 config::*,
11 global::{ 11 global::{functions::*, structs::*},
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 },
17}; 12};
18 13
19/// the main event loop of the program 14/// the main event loop of the program