Commit f7dc24b611

f7dc24b6113ac61fba5cfe0a7bd1899fafe5a517

parent: fde98b5a5b

Unsigned

Siriusmart <71584876+Siriusmart@users.noreply.github.com> · 2022-09-25 17:20 UTC

all search items + docs

Layout: unified · split

Cargo.lock +54 −54
@@ -273,9 +273,9 @@ dependencies = [
273 273
274[[package]] 274[[package]]
275name = "exr" 275name = "exr"
276version = "1.5.0" 276version = "1.5.1"
277source = "registry+https://github.com/rust-lang/crates.io-index" 277source = "registry+https://github.com/rust-lang/crates.io-index"
278checksum = "78c26a90d9dd411a3d119d6f55752fb4c134ca243250c32fb9cab7b2561638d2" 278checksum = "c9a7880199e74c6d3fe45579df2f436c5913a71405494cb89d59234d86b47dc5"
279dependencies = [ 279dependencies = [
280 "bit_field", 280 "bit_field",
281 "flume", 281 "flume",
@@ -582,14 +582,13 @@ dependencies = [
582 582
583[[package]] 583[[package]]
584name = "iana-time-zone" 584name = "iana-time-zone"
585version = "0.1.47" 585version = "0.1.50"
586source = "registry+https://github.com/rust-lang/crates.io-index" 586source = "registry+https://github.com/rust-lang/crates.io-index"
587checksum = "4c495f162af0bf17656d0014a0eded5f3cd2f365fdd204548c2869db89359dc7" 587checksum = "fd911b35d940d2bd0bea0f9100068e5b97b51a1cbe13d13382f132e0365257a0"
588dependencies = [ 588dependencies = [
589 "android_system_properties", 589 "android_system_properties",
590 "core-foundation-sys", 590 "core-foundation-sys",
591 "js-sys", 591 "js-sys",
592 "once_cell",
593 "wasm-bindgen", 592 "wasm-bindgen",
594 "winapi 0.3.9", 593 "winapi 0.3.9",
595] 594]
@@ -676,9 +675,9 @@ dependencies = [
676 675
677[[package]] 676[[package]]
678name = "js-sys" 677name = "js-sys"
679version = "0.3.59" 678version = "0.3.60"
680source = "registry+https://github.com/rust-lang/crates.io-index" 679source = "registry+https://github.com/rust-lang/crates.io-index"
681checksum = "258451ab10b34f8af53416d1fdab72c22e805f0c92a1136d59470ec0b11138b2" 680checksum = "49409df3e3bf0856b916e2ceaca09ee28e6871cf7d9ce97a692cacfdb2a25a47"
682dependencies = [ 681dependencies = [
683 "wasm-bindgen", 682 "wasm-bindgen",
684] 683]
@@ -713,15 +712,15 @@ checksum = "03087c2bad5e1034e8cace5926dec053fb3790248370865f5117a7d0213354c8"
713 712
714[[package]] 713[[package]]
715name = "libc" 714name = "libc"
716version = "0.2.132" 715version = "0.2.133"
717source = "registry+https://github.com/rust-lang/crates.io-index" 716source = "registry+https://github.com/rust-lang/crates.io-index"
718checksum = "8371e4e5341c3a96db127eb2465ac681ced4c433e01dd0e938adbef26ba93ba5" 717checksum = "c0f80d65747a3e43d1596c7c5492d95d5edddaabd45a7fcdb02b95f644164966"
719 718
720[[package]] 719[[package]]
721name = "lock_api" 720name = "lock_api"
722version = "0.4.8" 721version = "0.4.9"
723source = "registry+https://github.com/rust-lang/crates.io-index" 722source = "registry+https://github.com/rust-lang/crates.io-index"
724checksum = "9f80bf5aacaf25cbfc8210d1cfb718f2bf3b11c4c54e5afe36c236853a8ec390" 723checksum = "435011366fe56583b16cf956f9df0095b405b82d76425bc8981c0e22e60ec4df"
725dependencies = [ 724dependencies = [
726 "autocfg", 725 "autocfg",
727 "scopeguard", 726 "scopeguard",
@@ -862,9 +861,9 @@ dependencies = [
862 861
863[[package]] 862[[package]]
864name = "once_cell" 863name = "once_cell"
865version = "1.14.0" 864version = "1.15.0"
866source = "registry+https://github.com/rust-lang/crates.io-index" 865source = "registry+https://github.com/rust-lang/crates.io-index"
867checksum = "2f7254b99e31cad77da24b08ebf628882739a608578bb1bcdfc1f9c21260d7c0" 866checksum = "e82dad04139b71a90c080c8463fe0dc7902db5192d939bd0950f074d014339e1"
868 867
869[[package]] 868[[package]]
870name = "openssl" 869name = "openssl"
@@ -992,9 +991,9 @@ dependencies = [
992 991
993[[package]] 992[[package]]
994name = "proc-macro2" 993name = "proc-macro2"
995version = "1.0.43" 994version = "1.0.44"
996source = "registry+https://github.com/rust-lang/crates.io-index" 995source = "registry+https://github.com/rust-lang/crates.io-index"
997checksum = "0a2ca2c61bc9f3d74d2886294ab7b9853abd9c1ad903a3ac7815c58989bb7bab" 996checksum = "7bd7356a8122b6c4a24a82b278680c73357984ca2fc79a0f9fa6dea7dced7c58"
998dependencies = [ 997dependencies = [
999 "unicode-ident", 998 "unicode-ident",
1000] 999]
@@ -1071,9 +1070,9 @@ dependencies = [
1071 1070
1072[[package]] 1071[[package]]
1073name = "reqwest" 1072name = "reqwest"
1074version = "0.11.11" 1073version = "0.11.12"
1075source = "registry+https://github.com/rust-lang/crates.io-index" 1074source = "registry+https://github.com/rust-lang/crates.io-index"
1076checksum = "b75aa69a3f06bbcc66ede33af2af253c6f7a86b1ca0033f60c580a27074fbf92" 1075checksum = "431949c384f4e2ae07605ccaa56d1d9d2ecdb5cadd4f9577ccfab29f2e5149fc"
1077dependencies = [ 1076dependencies = [
1078 "base64", 1077 "base64",
1079 "bytes", 1078 "bytes",
@@ -1087,10 +1086,10 @@ dependencies = [
1087 "hyper-tls", 1086 "hyper-tls",
1088 "ipnet", 1087 "ipnet",
1089 "js-sys", 1088 "js-sys",
1090 "lazy_static 1.4.0",
1091 "log", 1089 "log",
1092 "mime", 1090 "mime",
1093 "native-tls", 1091 "native-tls",
1092 "once_cell",
1094 "percent-encoding", 1093 "percent-encoding",
1095 "pin-project-lite", 1094 "pin-project-lite",
1096 "serde", 1095 "serde",
@@ -1108,9 +1107,9 @@ dependencies = [
1108 1107
1109[[package]] 1108[[package]]
1110name = "rgb" 1109name = "rgb"
1111version = "0.8.33" 1110version = "0.8.34"
1112source = "registry+https://github.com/rust-lang/crates.io-index" 1111source = "registry+https://github.com/rust-lang/crates.io-index"
1113checksum = "c3b221de559e4a29df3b957eec92bc0de6bc8eaf6ca9cfed43e5e1d67ff65a34" 1112checksum = "3603b7d71ca82644f79b5a06d1220e9a58ede60bd32255f698cb1af8838b8db3"
1114dependencies = [ 1113dependencies = [
1115 "bytemuck", 1114 "bytemuck",
1116] 1115]
@@ -1178,18 +1177,18 @@ dependencies = [
1178 1177
1179[[package]] 1178[[package]]
1180name = "serde" 1179name = "serde"
1181version = "1.0.144" 1180version = "1.0.145"
1182source = "registry+https://github.com/rust-lang/crates.io-index" 1181source = "registry+https://github.com/rust-lang/crates.io-index"
1183checksum = "0f747710de3dcd43b88c9168773254e809d8ddbdf9653b84e2554ab219f17860" 1182checksum = "728eb6351430bccb993660dfffc5a72f91ccc1295abaa8ce19b27ebe4f75568b"
1184dependencies = [ 1183dependencies = [
1185 "serde_derive", 1184 "serde_derive",
1186] 1185]
1187 1186
1188[[package]] 1187[[package]]
1189name = "serde_derive" 1188name = "serde_derive"
1190version = "1.0.144" 1189version = "1.0.145"
1191source = "registry+https://github.com/rust-lang/crates.io-index" 1190source = "registry+https://github.com/rust-lang/crates.io-index"
1192checksum = "94ed3a816fb1d101812f83e789f888322c34e291f894f19590dc310963e87a00" 1191checksum = "81fa1584d3d1bcacd84c277a0dfe21f5b0f6accf4a23d04d4c6d61f1af522b4c"
1193dependencies = [ 1192dependencies = [
1194 "proc-macro2", 1193 "proc-macro2",
1195 "quote", 1194 "quote",
@@ -1221,9 +1220,9 @@ dependencies = [
1221 1220
1222[[package]] 1221[[package]]
1223name = "serde_yaml" 1222name = "serde_yaml"
1224version = "0.9.11" 1223version = "0.9.13"
1225source = "registry+https://github.com/rust-lang/crates.io-index" 1224source = "registry+https://github.com/rust-lang/crates.io-index"
1226checksum = "89f31df3f50926cdf2855da5fd8812295c34752cb20438dae42a67f79e021ac3" 1225checksum = "8613d593412a0deb7bbd8de9d908efff5a0cb9ccd8f62c641e7b2ed2f57291d1"
1227dependencies = [ 1226dependencies = [
1228 "indexmap", 1227 "indexmap",
1229 "itoa", 1228 "itoa",
@@ -1318,9 +1317,9 @@ dependencies = [
1318 1317
1319[[package]] 1318[[package]]
1320name = "syn" 1319name = "syn"
1321version = "1.0.99" 1320version = "1.0.100"
1322source = "registry+https://github.com/rust-lang/crates.io-index" 1321source = "registry+https://github.com/rust-lang/crates.io-index"
1323checksum = "58dbef6ec655055e20b86b15a8cc6d439cca19b667537ac6a1369572d151ab13" 1322checksum = "52205623b1b0f064a4e71182c3b18ae902267282930c6d5462c91b859668426e"
1324dependencies = [ 1323dependencies = [
1325 "proc-macro2", 1324 "proc-macro2",
1326 "quote", 1325 "quote",
@@ -1416,9 +1415,9 @@ checksum = "cda74da7e1a664f795bb1f8a87ec406fb89a02522cf6e50620d016add6dbbf5c"
1416 1415
1417[[package]] 1416[[package]]
1418name = "tokio" 1417name = "tokio"
1419version = "1.21.0" 1418version = "1.21.1"
1420source = "registry+https://github.com/rust-lang/crates.io-index" 1419source = "registry+https://github.com/rust-lang/crates.io-index"
1421checksum = "89797afd69d206ccd11fb0ea560a44bbb87731d020670e79416d442919257d42" 1420checksum = "0020c875007ad96677dcc890298f4b942882c5d4eb7cc8f439fc3bf813dc9c95"
1422dependencies = [ 1421dependencies = [
1423 "autocfg", 1422 "autocfg",
1424 "bytes", 1423 "bytes",
@@ -1536,30 +1535,30 @@ checksum = "099b7128301d285f79ddd55b9a83d5e6b9e97c92e0ea0daebee7263e932de992"
1536 1535
1537[[package]] 1536[[package]]
1538name = "unicode-ident" 1537name = "unicode-ident"
1539version = "1.0.3" 1538version = "1.0.4"
1540source = "registry+https://github.com/rust-lang/crates.io-index" 1539source = "registry+https://github.com/rust-lang/crates.io-index"
1541checksum = "c4f5b37a154999a8f3f98cc23a628d850e154479cd94decf3414696e12e31aaf" 1540checksum = "dcc811dc4066ac62f84f11307873c4850cb653bfa9b1719cee2bd2204a4bc5dd"
1542 1541
1543[[package]] 1542[[package]]
1544name = "unicode-normalization" 1543name = "unicode-normalization"
1545version = "0.1.21" 1544version = "0.1.22"
1546source = "registry+https://github.com/rust-lang/crates.io-index" 1545source = "registry+https://github.com/rust-lang/crates.io-index"
1547checksum = "854cbdc4f7bc6ae19c820d44abdc3277ac3e1b2b93db20a636825d9322fb60e6" 1546checksum = "5c5713f0fc4b5db668a2ac63cdb7bb4469d8c9fed047b1d0292cc7b0ce2ba921"
1548dependencies = [ 1547dependencies = [
1549 "tinyvec", 1548 "tinyvec",
1550] 1549]
1551 1550
1552[[package]] 1551[[package]]
1553name = "unicode-segmentation" 1552name = "unicode-segmentation"
1554version = "1.9.0" 1553version = "1.10.0"
1555source = "registry+https://github.com/rust-lang/crates.io-index" 1554source = "registry+https://github.com/rust-lang/crates.io-index"
1556checksum = "7e8820f5d777f6224dc4be3632222971ac30164d4a258d595640799554ebfd99" 1555checksum = "0fdbf052a0783de01e944a6ce7a8cb939e295b1e7be835a1112c3b9a7f047a5a"
1557 1556
1558[[package]] 1557[[package]]
1559name = "unicode-width" 1558name = "unicode-width"
1560version = "0.1.9" 1559version = "0.1.10"
1561source = "registry+https://github.com/rust-lang/crates.io-index" 1560source = "registry+https://github.com/rust-lang/crates.io-index"
1562checksum = "3ed742d4ea2bd1176e236172c8429aaf54486e7ac098db29ffe6529e0ce50973" 1561checksum = "c0edd1e5b14653f783770bce4a4dabb4a5108a5370a5f5d8cfe8710c361f6c8b"
1563 1562
1564[[package]] 1563[[package]]
1565name = "unsafe-any" 1564name = "unsafe-any"
@@ -1572,9 +1571,9 @@ dependencies = [
1572 1571
1573[[package]] 1572[[package]]
1574name = "unsafe-libyaml" 1573name = "unsafe-libyaml"
1575version = "0.2.2" 1574version = "0.2.4"
1576source = "registry+https://github.com/rust-lang/crates.io-index" 1575source = "registry+https://github.com/rust-lang/crates.io-index"
1577checksum = "931179334a56395bcf64ba5e0ff56781381c1a5832178280c7d7f91d1679aeb0" 1576checksum = "c1e5fa573d8ac5f1a856f8d7be41d390ee973daf97c806b2c1a465e4e1406e68"
1578 1577
1579[[package]] 1578[[package]]
1580name = "url" 1579name = "url"
@@ -1635,9 +1634,9 @@ checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423"
1635 1634
1636[[package]] 1635[[package]]
1637name = "wasm-bindgen" 1636name = "wasm-bindgen"
1638version = "0.2.82" 1637version = "0.2.83"
1639source = "registry+https://github.com/rust-lang/crates.io-index" 1638source = "registry+https://github.com/rust-lang/crates.io-index"
1640checksum = "fc7652e3f6c4706c8d9cd54832c4a4ccb9b5336e2c3bd154d5cccfbf1c1f5f7d" 1639checksum = "eaf9f5aceeec8be17c128b2e93e031fb8a4d469bb9c4ae2d7dc1888b26887268"
1641dependencies = [ 1640dependencies = [
1642 "cfg-if", 1641 "cfg-if",
1643 "wasm-bindgen-macro", 1642 "wasm-bindgen-macro",
@@ -1645,9 +1644,9 @@ dependencies = [
1645 1644
1646[[package]] 1645[[package]]
1647name = "wasm-bindgen-backend" 1646name = "wasm-bindgen-backend"
1648version = "0.2.82" 1647version = "0.2.83"
1649source = "registry+https://github.com/rust-lang/crates.io-index" 1648source = "registry+https://github.com/rust-lang/crates.io-index"
1650checksum = "662cd44805586bd52971b9586b1df85cdbbd9112e4ef4d8f41559c334dc6ac3f" 1649checksum = "4c8ffb332579b0557b52d268b91feab8df3615f265d5270fec2a8c95b17c1142"
1651dependencies = [ 1650dependencies = [
1652 "bumpalo", 1651 "bumpalo",
1653 "log", 1652 "log",
@@ -1660,9 +1659,9 @@ dependencies = [
1660 1659
1661[[package]] 1660[[package]]
1662name = "wasm-bindgen-futures" 1661name = "wasm-bindgen-futures"
1663version = "0.4.32" 1662version = "0.4.33"
1664source = "registry+https://github.com/rust-lang/crates.io-index" 1663source = "registry+https://github.com/rust-lang/crates.io-index"
1665checksum = "fa76fb221a1f8acddf5b54ace85912606980ad661ac7a503b4570ffd3a624dad" 1664checksum = "23639446165ca5a5de86ae1d8896b737ae80319560fbaa4c2887b7da6e7ebd7d"
1666dependencies = [ 1665dependencies = [
1667 "cfg-if", 1666 "cfg-if",
1668 "js-sys", 1667 "js-sys",
@@ -1672,9 +1671,9 @@ dependencies = [
1672 1671
1673[[package]] 1672[[package]]
1674name = "wasm-bindgen-macro" 1673name = "wasm-bindgen-macro"
1675version = "0.2.82" 1674version = "0.2.83"
1676source = "registry+https://github.com/rust-lang/crates.io-index" 1675source = "registry+https://github.com/rust-lang/crates.io-index"
1677checksum = "b260f13d3012071dfb1512849c033b1925038373aea48ced3012c09df952c602" 1676checksum = "052be0f94026e6cbc75cdefc9bae13fd6052cdcaf532fa6c45e7ae33a1e6c810"
1678dependencies = [ 1677dependencies = [
1679 "quote", 1678 "quote",
1680 "wasm-bindgen-macro-support", 1679 "wasm-bindgen-macro-support",
@@ -1682,9 +1681,9 @@ dependencies = [
1682 1681
1683[[package]] 1682[[package]]
1684name = "wasm-bindgen-macro-support" 1683name = "wasm-bindgen-macro-support"
1685version = "0.2.82" 1684version = "0.2.83"
1686source = "registry+https://github.com/rust-lang/crates.io-index" 1685source = "registry+https://github.com/rust-lang/crates.io-index"
1687checksum = "5be8e654bdd9b79216c2929ab90721aa82faf65c48cdf08bdc4e7f51357b80da" 1686checksum = "07bc0c051dc5f23e307b13285f9d75df86bfdf816c5721e573dec1f9b8aa193c"
1688dependencies = [ 1687dependencies = [
1689 "proc-macro2", 1688 "proc-macro2",
1690 "quote", 1689 "quote",
@@ -1695,15 +1694,15 @@ dependencies = [
1695 1694
1696[[package]] 1695[[package]]
1697name = "wasm-bindgen-shared" 1696name = "wasm-bindgen-shared"
1698version = "0.2.82" 1697version = "0.2.83"
1699source = "registry+https://github.com/rust-lang/crates.io-index" 1698source = "registry+https://github.com/rust-lang/crates.io-index"
1700checksum = "6598dd0bd3c7d51095ff6531a5b23e02acdc81804e30d8f07afb77b7215a140a" 1699checksum = "1c38c045535d93ec4f0b4defec448e4291638ee608530863b1e2ba115d4fff7f"
1701 1700
1702[[package]] 1701[[package]]
1703name = "web-sys" 1702name = "web-sys"
1704version = "0.3.59" 1703version = "0.3.60"
1705source = "registry+https://github.com/rust-lang/crates.io-index" 1704source = "registry+https://github.com/rust-lang/crates.io-index"
1706checksum = "ed055ab27f941423197eb86b2035720b1a3ce40504df082cac2ecc6ed73335a1" 1705checksum = "bcda906d8be16e728fd5adc5b729afad4e444e106ab28cd1c7256e54fa61510f"
1707dependencies = [ 1706dependencies = [
1708 "js-sys", 1707 "js-sys",
1709 "wasm-bindgen", 1708 "wasm-bindgen",
@@ -1822,6 +1821,7 @@ dependencies = [
1822 "invidious", 1821 "invidious",
1823 "reqwest", 1822 "reqwest",
1824 "serde", 1823 "serde",
1824 "serde_json",
1825 "serde_yaml", 1825 "serde_yaml",
1826 "tokio", 1826 "tokio",
1827 "tui", 1827 "tui",
Cargo.toml +1 −1
@@ -27,5 +27,5 @@ dyn-clone = "1.0"
27tokio = "1.21" 27tokio = "1.21"
28futures = "0.3" 28futures = "0.3"
29reqwest = "0.11" 29reqwest = "0.11"
30# serde_json = "1.0" 30serde_json = "1.0"
31tui-additions = {path = "../../Rust/Packages/tui-additions", default-features = false, features = ["framework", "widgets"]} 31tui-additions = {path = "../../Rust/Packages/tui-additions", default-features = false, features = ["framework", "widgets"]}
README.md +2 −1
@@ -41,10 +41,11 @@ An aesthetically pleasing YouTube TUI written in Rust.
41> 41>
42> - Config files (mostly, more options will be added when I get to that part) 42> - Config files (mostly, more options will be added when I get to that part)
43> - Home and search page 43> - Home and search page
44> - Search fully functional
44> 45>
45> #### To do before release 46> #### To do before release
46> 47>
47> - All pages (video/playlist/channel info) 48> - Item info, channels page
48> - Watch history 49> - Watch history
49> - Basically back to where it is before the rewrite 50> - Basically back to where it is before the rewrite
50 51
src/config/appearance.rs +20 −1
@@ -1,8 +1,10 @@
1use super::{serde::BorderTypeSerde, ConfigTrait}; 1use super::serde::BorderTypeSerde;
2use crate::global::traits::ConfigTrait;
2use serde::{Deserialize, Serialize}; 3use serde::{Deserialize, Serialize};
3use tui::{style::Color, widgets::BorderType}; 4use tui::{style::Color, widgets::BorderType};
4use typemap::Key; 5use typemap::Key;
5 6
7/// `appearance.yml`, impl serde version of AppearanceConfig
6#[derive(Default, Serialize, Deserialize, Clone)] 8#[derive(Default, Serialize, Deserialize, Clone)]
7pub struct AppearanceConfigSerde { 9pub struct AppearanceConfigSerde {
8 #[serde(default)] 10 #[serde(default)]
@@ -11,12 +13,14 @@ pub struct AppearanceConfigSerde {
11 pub colors: ColorsConfig, 13 pub colors: ColorsConfig,
12} 14}
13 15
16/// `appearance.yml`, this struct is stored in `data.global`
14#[derive(Clone)] 17#[derive(Clone)]
15pub struct AppearanceConfig { 18pub struct AppearanceConfig {
16 pub borders: BorderType, 19 pub borders: BorderType,
17 pub colors: ColorsConfig, 20 pub colors: ColorsConfig,
18} 21}
19 22
23/// Includes all configurable colors
20#[derive(Clone, Copy, Serialize, Deserialize)] 24#[derive(Clone, Copy, Serialize, Deserialize)]
21pub struct ColorsConfig { 25pub struct ColorsConfig {
22 #[serde(default = "outline_default")] 26 #[serde(default = "outline_default")]
@@ -39,6 +43,7 @@ pub struct ColorsConfig {
39 pub item_info: ItemInfoColors, 43 pub item_info: ItemInfoColors,
40} 44}
41 45
46/// Colors used by ItemInfo
42#[derive(Clone, Copy, Serialize, Deserialize)] 47#[derive(Clone, Copy, Serialize, Deserialize)]
43pub struct ItemInfoColors { 48pub struct ItemInfoColors {
44 #[serde(default = "tag_default")] 49 #[serde(default = "tag_default")]
@@ -55,6 +60,10 @@ pub struct ItemInfoColors {
55 pub length: Color, 60 pub length: Color,
56 #[serde(default = "published_default")] 61 #[serde(default = "published_default")]
57 pub published: Color, 62 pub published: Color,
63 #[serde(default = "video_count_default")]
64 pub video_count: Color,
65 #[serde(default = "sub_count_default")]
66 pub sub_count: Color,
58} 67}
59 68
60impl Default for ColorsConfig { 69impl Default for ColorsConfig {
@@ -83,6 +92,8 @@ impl Default for ItemInfoColors {
83 viewcount: viewcount_default(), 92 viewcount: viewcount_default(),
84 length: length_default(), 93 length: length_default(),
85 published: published_default(), 94 published: published_default(),
95 video_count: video_count_default(),
96 sub_count: sub_count_default(),
86 } 97 }
87 } 98 }
88} 99}
@@ -165,3 +176,11 @@ fn length_default() -> Color {
165fn published_default() -> Color { 176fn published_default() -> Color {
166 Color::LightMagenta 177 Color::LightMagenta
167} 178}
179
180fn video_count_default() -> Color {
181 Color::Rgb(131, 141, 255)
182}
183
184fn sub_count_default() -> Color {
185 Color::LightYellow
186}
src/config/keybindings.rs +3 −2
@@ -1,5 +1,4 @@
1use super::ConfigTrait; 1use crate::global::{structs::KeyAction, traits::ConfigTrait};
2use crate::global::keyaction::KeyAction;
3use crossterm::event::KeyCode; 2use crossterm::event::KeyCode;
4use serde::{Deserialize, Serialize}; 3use serde::{Deserialize, Serialize};
5use std::collections::HashMap; 4use std::collections::HashMap;
@@ -9,6 +8,7 @@ use typemap::Key;
9// The inner HashMap<u8, KeyAction> gets the action using a u8 representing a key modifier 8// The inner HashMap<u8, KeyAction> gets the action using a u8 representing a key modifier
10// The u8 for each modifier key can be found in https://docs.rs/crossterm/latest/src/crossterm/event.rs.html#587-603 9// The u8 for each modifier key can be found in https://docs.rs/crossterm/latest/src/crossterm/event.rs.html#587-603
11// The sum of u8 for each key modifier would mean having all of those modifiers at the same time 10// The sum of u8 for each key modifier would mean having all of those modifiers at the same time
11/// `keybindings.yml`, contains a hashmap of key + key modifier to action pair
12#[derive(Serialize, Deserialize, Clone)] 12#[derive(Serialize, Deserialize, Clone)]
13pub struct KeyBindingsConfig(pub HashMap<KeyCode, HashMap<u8, KeyAction>>); 13pub struct KeyBindingsConfig(pub HashMap<KeyCode, HashMap<u8, KeyAction>>);
14 14
@@ -60,6 +60,7 @@ impl Default for KeyBindingsConfig {
60 r.insert(2, KeyAction::Reload); 60 r.insert(2, KeyAction::Reload);
61 map.insert(KeyCode::Char('r'), r); 61 map.insert(KeyCode::Char('r'), r);
62 62
63 // vim keybindings
63 let mut h = HashMap::new(); 64 let mut h = HashMap::new();
64 h.insert(0, KeyAction::MoveLeft); 65 h.insert(0, KeyAction::MoveLeft);
65 map.insert(KeyCode::Char('h'), h); 66 map.insert(KeyCode::Char('h'), h);
src/config/main.rs +2 −1
@@ -1,8 +1,9 @@
1use super::ConfigTrait; 1use crate::global::traits::ConfigTrait;
2use serde::{Deserialize, Serialize}; 2use serde::{Deserialize, Serialize};
3use std::collections::HashMap; 3use std::collections::HashMap;
4use typemap::Key; 4use typemap::Key;
5 5
6/// `main.yml`, the main config file
6#[derive(Serialize, Deserialize, Clone)] 7#[derive(Serialize, Deserialize, Clone)]
7pub struct MainConfig { 8pub struct MainConfig {
8 #[serde(default = "invidious_instance_default")] 9 #[serde(default = "invidious_instance_default")]
src/config/mod.rs +1 −2
@@ -1,5 +1,4 @@
1mod configtrait; 1//! Structs for config files, all impl ConfigTrait, config files are stored in `~./config`
2pub use configtrait::*;
3mod main; 2mod main;
4pub use main::*; 3pub use main::*;
5mod appearance; 4mod appearance;
src/config/pages.rs +15 −7
@@ -1,14 +1,15 @@
1use super::ConfigTrait; 1use crate::{
2use crate::items::{ItemList, MessageBar, PageButton, SearchBar, SearchFilter}; 2 global::traits::ConfigTrait,
3 items::{ItemList, MessageBar, PageButton, SearchBar, SearchFilter},
4};
3use serde::{Deserialize, Serialize}; 5use serde::{Deserialize, Serialize};
4use std::slice; 6use std::slice;
5use tui::layout::Constraint; 7use tui::layout::Constraint;
6use tui_additions::framework::{Framework, FrameworkItem, Row, RowItem, State}; 8use tui_additions::framework::{Framework, FrameworkItem, Row, RowItem, State};
7use typemap::Key; 9use typemap::Key;
8 10
9// Minimum screen dimention for the tui to display without panicking, 11/// Minimum screen dimention for the tui to display without panicking, stored in `data.state`
10// is automatically generated from PageConfig 12// is automatically generated from PageConfig
11// will be inserted into `framework.data.state`
12#[derive(Clone, Copy)] 13#[derive(Clone, Copy)]
13pub struct MinDimentions { 14pub struct MinDimentions {
14 pub width: u16, 15 pub width: u16,
@@ -34,6 +35,7 @@ impl Key for MinDimentions {
34 type Value = Self; 35 type Value = Self;
35} 36}
36 37
38/// Layout for all pages
37#[derive(Clone, Serialize, Deserialize)] 39#[derive(Clone, Serialize, Deserialize)]
38pub struct PagesConfig { 40pub struct PagesConfig {
39 #[serde(default = "main_menu_default")] 41 #[serde(default = "main_menu_default")]
@@ -62,6 +64,7 @@ impl Default for PagesConfig {
62// This struct impls Into<State>, the corresponding page is converted into State on page load 64// This struct impls Into<State>, the corresponding page is converted into State on page load
63// Each page has its own minimum width and height, which is automatically determined by the items in the page 65// Each page has its own minimum width and height, which is automatically determined by the items in the page
64// If it doesn't meet the minimum dimentions, a "protective screen" will be shown to prevent panicking 66// If it doesn't meet the minimum dimentions, a "protective screen" will be shown to prevent panicking
67/// Layout for one single page
65#[derive(Clone, Serialize, Deserialize)] 68#[derive(Clone, Serialize, Deserialize)]
66pub struct PageConfig { 69pub struct PageConfig {
67 pub layout: Vec<PageRow>, 70 pub layout: Vec<PageRow>,
@@ -69,6 +72,7 @@ pub struct PageConfig {
69} 72}
70 73
71impl PageConfig { 74impl PageConfig {
75 /// Calculates minimum width for all items to display
72 pub fn min_width(&self) -> u16 { 76 pub fn min_width(&self) -> u16 {
73 self.layout 77 self.layout
74 .iter() 78 .iter()
@@ -81,6 +85,7 @@ impl PageConfig {
81 .unwrap() 85 .unwrap()
82 } 86 }
83 87
88 /// Calculates minimum height for all items to display
84 pub fn min_height(&self) -> u16 { 89 pub fn min_height(&self) -> u16 {
85 self.layout 90 self.layout
86 .iter() 91 .iter()
@@ -93,6 +98,7 @@ impl PageConfig {
93 .sum::<u16>() 98 .sum::<u16>()
94 } 99 }
95 100
101 /// Converts itself into `State` to be used in `Framework`
96 pub fn to_state(&self, framework: &mut Framework) -> State { 102 pub fn to_state(&self, framework: &mut Framework) -> State {
97 State( 103 State(
98 self.layout 104 self.layout
@@ -115,7 +121,7 @@ impl PageConfig {
115 } 121 }
116} 122}
117 123
118// CenteredRow will have its items centered, while NonCenteredRow will align to the left 124/// CenteredRow will have its items centered, while NonCenteredRow will align to the left
119#[derive(Clone, Serialize, Deserialize)] 125#[derive(Clone, Serialize, Deserialize)]
120pub enum PageRow { 126pub enum PageRow {
121 CenteredRow(Vec<PageItems>), 127 CenteredRow(Vec<PageItems>),
@@ -148,6 +154,7 @@ impl PageRow {
148// PageItems will be converted into Box<dyn FrameworkItem> on page load to be used an item in the framework 154// PageItems will be converted into Box<dyn FrameworkItem> on page load to be used an item in the framework
149// Seen https://docs.rs/tui-additions/latest/tui_additions/framework/trait.FrameworkItem.html 155// Seen https://docs.rs/tui-additions/latest/tui_additions/framework/trait.FrameworkItem.html
150// Each item has a minimum width and height for it to render without panicking 156// Each item has a minimum width and height for it to render without panicking
157/// All avaliable items for `PageConfig`
151#[derive(Clone, Copy, Serialize, Deserialize)] 158#[derive(Clone, Copy, Serialize, Deserialize)]
152pub enum PageItems { 159pub enum PageItems {
153 SearchBar, 160 SearchBar,
@@ -159,13 +166,14 @@ pub enum PageItems {
159} 166}
160 167
161impl PageItems { 168impl PageItems {
162 pub fn to_framework_item(&self, framework: &mut Framework) -> Box<dyn FrameworkItem> { 169 /// Converts `Self` into a `FrameworkItem` to be used in `State`
170 pub fn to_framework_item(&self, _framework: &mut Framework) -> Box<dyn FrameworkItem> {
163 match *self { 171 match *self {
164 Self::SearchBar => Box::new(SearchBar::default()), 172 Self::SearchBar => Box::new(SearchBar::default()),
165 Self::Popular => Box::new(PageButton::Popular), 173 Self::Popular => Box::new(PageButton::Popular),
166 Self::Trending => Box::new(PageButton::Trending), 174 Self::Trending => Box::new(PageButton::Trending),
167 Self::MessageBar => Box::new(MessageBar::default()), 175 Self::MessageBar => Box::new(MessageBar::default()),
168 Self::ItemList => Box::new(ItemList::new(framework)), 176 Self::ItemList => Box::new(ItemList::default()),
169 Self::SearchFilters => Box::new(SearchFilter::default()), 177 Self::SearchFilters => Box::new(SearchFilter::default()),
170 } 178 }
171 } 179 }
src/config/search.rs +14 −20
@@ -1,12 +1,12 @@
1use crate::{ 1use crate::global::{
2 config::ConfigTrait, 2 structs::Message,
3 global::{message::Message, traits::asurlstring::AsUrlString}, 3 traits::{AsUrlString, ConfigTrait, SearchFilterItem},
4}; 4};
5use serde::{Deserialize, Serialize}; 5use serde::{Deserialize, Serialize};
6use tui_additions::framework::FrameworkClean;
7use typemap::Key; 6use typemap::Key;
8 7
9// can be turned into URL Params for the search term with filters 8// can be turned into URL Params for the search term with filters
9/// Search query & filters
10#[derive(Clone, Default, Serialize, Deserialize, PartialEq, Eq)] 10#[derive(Clone, Default, Serialize, Deserialize, PartialEq, Eq)]
11pub struct Search { 11pub struct Search {
12 pub query: String, 12 pub query: String,
@@ -34,8 +34,7 @@ impl ToString for Search {
34 } 34 }
35} 35}
36 36
37// Search filters 37/// Search filters, read comments for function docs
38
39#[derive(Default, Clone, Copy, Serialize, Deserialize, PartialEq, Eq)] 38#[derive(Default, Clone, Copy, Serialize, Deserialize, PartialEq, Eq)]
40pub struct SearchFilters { 39pub struct SearchFilters {
41 pub sort: SearchFilterSort, 40 pub sort: SearchFilterSort,
@@ -44,7 +43,12 @@ pub struct SearchFilters {
44 pub r#type: SearchFilterType, 43 pub r#type: SearchFilterType,
45} 44}
46 45
46// These functions are used in the search filter item
47// Think of the ordering of stuff in the popup menu
47impl SearchFilters { 48impl SearchFilters {
49 // This function returns [(Option name, [Options])]
50 // Option name is a string like "sory by" and "type"
51 // Options are the options that you can select like "relevance" and "upload date" for sorting
48 pub fn get_all() -> [(&'static str, Vec<&'static str>); 5] { 52 pub fn get_all() -> [(&'static str, Vec<&'static str>); 5] {
49 [ 53 [
50 (SearchFilterSort::NAME, SearchFilterSort::ordering()), 54 (SearchFilterSort::NAME, SearchFilterSort::ordering()),
@@ -55,6 +59,8 @@ impl SearchFilters {
55 ] 59 ]
56 } 60 }
57 61
62 // uses the index of the selected option name to get the index of the selected option
63 // aka using the hover location of the left textlist to get the hover location of the right text list
58 pub fn get_selected(&self, index: usize) -> usize { 64 pub fn get_selected(&self, index: usize) -> usize {
59 match index { 65 match index {
60 0 => self.sort.selected_index(), 66 0 => self.sort.selected_index(),
@@ -66,8 +72,9 @@ impl SearchFilters {
66 } 72 }
67 } 73 }
68 74
75 // saves the settings for a filter given the index of the option (among other options) and the index of the selected options
76 // v left textlist v right textlist
69 pub fn set_index(&mut self, index_at: usize, set_index: usize, message: &mut Message) { 77 pub fn set_index(&mut self, index_at: usize, set_index: usize, message: &mut Message) {
70 // panic!("function ran");
71 match index_at { 78 match index_at {
72 0 => self.sort = SearchFilterSort::at_index(set_index), 79 0 => self.sort = SearchFilterSort::at_index(set_index),
73 1 => self.date = SearchFilterDate::at_index(set_index), 80 1 => self.date = SearchFilterDate::at_index(set_index),
@@ -86,7 +93,6 @@ impl SearchFilters {
86 93
87 pub fn reset(&mut self, message: &mut Message) { 94 pub fn reset(&mut self, message: &mut Message) {
88 *self = Self::default(); 95 *self = Self::default();
89
90 *message = Message::Success(String::from("Search filters has been reset")); 96 *message = Message::Success(String::from("Search filters has been reset"));
91 } 97 }
92} 98}
@@ -211,18 +217,6 @@ impl AsUrlString for SearchFilterType {
211 const TAG: &'static str = "type"; 217 const TAG: &'static str = "type";
212} 218}
213 219
214pub trait SearchFilterItem
215where
216 Self: Sized,
217{
218 const NAME: &'static str;
219
220 fn option_name(&self) -> &'static str;
221 fn ordering() -> Vec<&'static str>;
222 fn selected_index(&self) -> usize;
223 fn at_index(index: usize) -> Self;
224}
225
226const SORT_ORDERING: [SearchFilterSort; 4] = [ 220const SORT_ORDERING: [SearchFilterSort; 4] = [
227 SearchFilterSort::Relevance, 221 SearchFilterSort::Relevance,
228 SearchFilterSort::Rating, 222 SearchFilterSort::Rating,
src/config/serde.rs +2 −1
@@ -1,8 +1,9 @@
1// Structs that impl Into<WhatEverStruct> because WhatEverStruct does not impl Serde 1//! Structs that impl `Into<T>` because `T` does not impl Serde but is used in config files
2 2
3use serde::{Deserialize, Serialize}; 3use serde::{Deserialize, Serialize};
4use tui::widgets::BorderType; 4use tui::widgets::BorderType;
5 5
6/// `BorderType` but impl `serde`
6#[derive(Serialize, Deserialize, Clone, Copy)] 7#[derive(Serialize, Deserialize, Clone, Copy)]
7pub enum BorderTypeSerde { 8pub enum BorderTypeSerde {
8 Plain, 9 Plain,
src/exit.rs +1
@@ -1,6 +1,7 @@
1use home::home_dir; 1use home::home_dir;
2use std::{error::Error, fs}; 2use std::{error::Error, fs};
3 3
4/// function to run when the app ends
4// exit tasks: 5// exit tasks:
5// - remove `~/.cache` 6// - remove `~/.cache`
6pub fn exit() -> Result<(), Box<dyn Error>> { 7pub fn exit() -> Result<(), Box<dyn Error>> {
src/global/functions/date_text.rs +1 −1
@@ -1,6 +1,6 @@
1use chrono::{Datelike, NaiveDateTime}; 1use chrono::{Datelike, NaiveDateTime};
2 2
3// Convert timestamp into DD/MM/YYYY 3/// Convert timestamp into `DD/MM/YYYY`
4pub fn date_text(timestamp: u64) -> String { 4pub fn date_text(timestamp: u64) -> String {
5 let date = NaiveDateTime::from_timestamp(timestamp as i64, 0).date(); 5 let date = NaiveDateTime::from_timestamp(timestamp as i64, 0).date();
6 format!("{}/{}/{}", date.day(), date.month(), date.year()) 6 format!("{}/{}/{}", date.day(), date.month(), date.year())
src/global/functions/download_all_images.rs +26 −8
@@ -1,4 +1,4 @@
1use crate::global::item::Item; 1use crate::global::structs::Item;
2use futures::future::join_all; 2use futures::future::join_all;
3use std::{error::Error, fs, io::Cursor, thread}; 3use std::{error::Error, fs, io::Cursor, thread};
4use tokio::runtime::Runtime; 4use tokio::runtime::Runtime;
@@ -8,23 +8,41 @@ pub struct DownloadRequest {
8 pub id: String, 8 pub id: String,
9} 9}
10 10
11impl From<&Item> for DownloadRequest { 11impl From<&Item> for Option<DownloadRequest> {
12 fn from(item: &Item) -> Self { 12 fn from(item: &Item) -> Self {
13 match item { 13 Some(match item {
14 Item::MiniVideo(minivideo) => Self { 14 Item::MiniVideo(minivideo) => DownloadRequest {
15 url: minivideo.thumbnail_url.clone(), 15 url: minivideo.thumbnail_url.clone(),
16 id: minivideo.id.clone(), 16 id: minivideo.id.clone(),
17 }, 17 },
18 } 18 Item::MiniPlaylist(miniplaylist) => match &miniplaylist.thumbnail {
19 Some((id, url)) => DownloadRequest {
20 url: url.clone(),
21 id: id.clone(),
22 },
23 None => return None,
24 },
25 Item::MiniChannel(minichannel) => DownloadRequest {
26 url: minichannel.thumbnail_url.clone(),
27 id: minichannel.id.clone(),
28 },
29 Item::Unknown(_) => return None,
30 })
19 } 31 }
20} 32}
21 33
22// Function to download all thumbnails (or just any files) to `~/.cache/thumbnails` with no file exitension (cuz its not needed) 34/// Function to download all thumbnails (or just any files) to `~/.cache/thumbnails` with no file exitension (cuz its not needed)
23pub fn download_all_images(downloads: Vec<DownloadRequest>) { 35pub fn download_all_images(downloads: Vec<Option<DownloadRequest>>) {
24 thread::spawn(move || { 36 thread::spawn(move || {
25 let rt: Runtime = tokio::runtime::Runtime::new().unwrap(); 37 let rt: Runtime = tokio::runtime::Runtime::new().unwrap();
26 38
27 let _ = rt.block_on(download_all_images_async(downloads)); 39 let _ = rt.block_on(download_all_images_async(
40 downloads
41 .into_iter()
42 .filter(|request| request.is_some())
43 .map(|request| request.unwrap())
44 .collect(),
45 ));
28 }); 46 });
29} 47}
30 48
src/global/functions/mod.rs +1
@@ -1,3 +1,4 @@
1//! public functions
1mod secs_display_string; 2mod secs_display_string;
2pub use secs_display_string::secs_display_string; 3pub use secs_display_string::secs_display_string;
3mod viewcount_text; 4mod viewcount_text;
src/global/functions/popup_area.rs +1
@@ -1,5 +1,6 @@
1use tui::layout::Rect; 1use tui::layout::Rect;
2 2
3/// Tries to create a centered area for popup, returns `Err` if not enough space is given
3pub fn popup_area( 4pub fn popup_area(
4 (max_width_percentage, max_height_percentage): (u16, u16), 5 (max_width_percentage, max_height_percentage): (u16, u16),
5 (min_width_length, min_height_length): (u16, u16), 6 (min_width_length, min_height_length): (u16, u16),
src/global/functions/secs_display_string.rs +1 −1
@@ -1,7 +1,7 @@
1const SECS_IN_MINUTE: u32 = 60; 1const SECS_IN_MINUTE: u32 = 60;
2const SECS_IN_HOUR: u32 = 3600; 2const SECS_IN_HOUR: u32 = 3600;
3 3
4// Turns seconds into pretty format like 02:43 4/// Turns seconds into pretty format like `02:43`
5pub fn secs_display_string(mut secs: u32) -> String { 5pub fn secs_display_string(mut secs: u32) -> String {
6 let mut out = Vec::new(); 6 let mut out = Vec::new();
7 7
src/global/functions/viewcount_text.rs +4 −2
@@ -5,10 +5,12 @@ const UNITS: &[(&'static str, f64)] = &[
5 ("", 1_f64), 5 ("", 1_f64),
6]; 6];
7 7
8// Turns number into short hand like 1.56M instead of its full form 8/// Turns number into short hand like `1.56M` instead of `1560000`
9pub fn viewcount_text(views: u64) -> String { 9pub fn viewcount_text(views: u64) -> String {
10 for unit in UNITS.iter() { 10 for unit in UNITS.iter() {
11 if views >= unit.1 as u64 { 11 if unit.1 == 1_f64 {
12 return format!("{}", views);
13 } else if views >= unit.1 as u64 {
12 return format!("{:.2}{}", views as f64 / unit.1, unit.0); 14 return format!("{:.2}{}", views as f64 / unit.1, unit.0);
13 } 15 }
14 } 16 }
src/global/mod.rs +2 −9
@@ -1,11 +1,4 @@
1pub mod errors; 1//! Structs , traits and functions for the entire app
2pub mod invidiousclient;
3pub mod item;
4pub mod keyaction;
5pub mod message;
6pub mod page;
7pub mod status;
8pub mod tasks;
9
10pub mod functions; 2pub mod functions;
3pub mod structs;
11pub mod traits; 4pub mod traits;
src/global/errors.rs → src/global/structs/errors.rs renamed +1 −1
@@ -1,6 +1,6 @@
1use std::{error::Error, fmt::Display}; 1use std::{error::Error, fmt::Display};
2 2
3// Errors for displaying custom string in the message bar if there is an error 3/// Errors for displaying custom string in the message bar if there is an error
4#[derive(Debug)] 4#[derive(Debug)]
5pub enum Errors { 5pub enum Errors {
6 BlankError, 6 BlankError,
src/global/invidiousclient.rs → src/global/structs/invidiousclient.rs renamed +2 −1
@@ -1,7 +1,8 @@
1use invidious::reqwest::blocking::Client; 1use invidious::reqwest::blocking::Client;
2use typemap::Key; 2use typemap::Key;
3 3
4// Holds the invidious client 4// used in `data.global`
5/// Holds the invidious client
5#[derive(Clone)] 6#[derive(Clone)]
6pub struct InvidiousClient(pub Client); 7pub struct InvidiousClient(pub Client);
7 8
src/global/item.rs → src/global/structs/item.rs renamed +101 −5
@@ -1,16 +1,21 @@
1use crate::global::functions::{date_text, secs_display_string, viewcount_text};
2use invidious::structs::hidden::{
3 Playlist, PopularItem, SearchItem, SearchItemTransition, TrendingVideo,
4};
1use std::fmt::Display; 5use std::fmt::Display;
2 6
3use super::functions::{date_text, secs_display_string, viewcount_text}; 7/// Items are things like a single video/playlist and channel
4use invidious::structs::hidden::{PopularItem, SearchItem, TrendingVideo};
5
6// Items are things like a single video/playlist and channel
7// they are displayed by the item info widget in `iteminfo.rs` 8// they are displayed by the item info widget in `iteminfo.rs`
8#[derive(Clone)] 9#[derive(Clone)]
9pub enum Item { 10pub enum Item {
10 // minivideos are all videos that appeared without actually clicking into the video 11 // minivideos are all videos that appeared without actually clicking into the video
11 MiniVideo(MiniVideoItem), 12 MiniVideo(MiniVideoItem),
13 MiniPlaylist(MiniPlaylistItem),
14 MiniChannel(MiniChannelItem),
15 Unknown(SearchItemTransition),
12} 16}
13 17
18/// info from a video from search, trending and popular page
14#[derive(Clone)] 19#[derive(Clone)]
15pub struct MiniVideoItem { 20pub struct MiniVideoItem {
16 pub title: String, 21 pub title: String,
@@ -24,10 +29,35 @@ pub struct MiniVideoItem {
24 pub description: Option<String>, 29 pub description: Option<String>,
25} 30}
26 31
32#[derive(Clone)]
33pub struct MiniPlaylistItem {
34 pub title: String,
35 pub id: String,
36 pub channel: String,
37 pub channel_id: String,
38 pub video_count: u32,
39 // (id, url)
40 pub thumbnail: Option<(String, String)>,
41}
42
43#[derive(Clone)]
44pub struct MiniChannelItem {
45 pub name: String,
46 pub id: String,
47 pub thumbnail_url: String,
48 pub sub_count: u32,
49 pub sub_count_text: String,
50 pub video_count: u32,
51 pub description: String,
52}
53
27impl Display for Item { 54impl Display for Item {
28 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { 55 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
29 f.write_str(match self { 56 f.write_str(match self {
30 Self::MiniVideo(video) => &video.title, 57 Self::MiniVideo(video) => &video.title,
58 Self::MiniPlaylist(playlist) => &playlist.title,
59 Self::MiniChannel(channel) => &channel.name,
60 Self::Unknown(_) => "Unknown item",
31 }) 61 })
32 } 62 }
33} 63}
@@ -37,6 +67,12 @@ impl Item {
37 pub fn thumbnail_id(&self) -> &str { 67 pub fn thumbnail_id(&self) -> &str {
38 match self { 68 match self {
39 Self::MiniVideo(video) => &video.id, 69 Self::MiniVideo(video) => &video.id,
70 Self::MiniPlaylist(playlist) => match &playlist.thumbnail {
71 Some((id, _)) => &id,
72 None => "invalid",
73 },
74 Self::MiniChannel(channel) => &channel.id,
75 Self::Unknown(_) => "invalid",
40 } 76 }
41 } 77 }
42 78
@@ -77,6 +113,24 @@ impl Item {
77 }) 113 })
78 } 114 }
79 115
116 pub fn from_mini_playlist(original: Playlist, image_index: usize) -> Self {
117 Self::MiniPlaylist(MiniPlaylistItem {
118 title: original.title,
119 id: original.id,
120 channel: original.author,
121 channel_id: original.author_id,
122 video_count: original.video_count,
123 thumbnail: if original.videos.len() == 0 {
124 None
125 } else {
126 Some((
127 original.videos[0].id.clone(),
128 original.videos[0].thumbnails[image_index].url.clone(),
129 ))
130 },
131 })
132 }
133
80 pub fn from_search_item(original: SearchItem, image_index: usize) -> Self { 134 pub fn from_search_item(original: SearchItem, image_index: usize) -> Self {
81 match original { 135 match original {
82 SearchItem::Video { 136 SearchItem::Video {
@@ -106,7 +160,49 @@ impl Item {
106 published: format!("{} [{}]", published_text, date_text(published)), 160 published: format!("{} [{}]", published_text, date_text(published)),
107 description: Some(description), 161 description: Some(description),
108 }), 162 }),
109 _ => todo!(), 163 SearchItem::Playlist {
164 title,
165 id,
166 author,
167 author_id,
168 author_url: _,
169 video_count,
170 videos,
171 } => Self::MiniPlaylist(MiniPlaylistItem {
172 title,
173 id,
174 channel: author,
175 channel_id: author_id,
176 video_count,
177 thumbnail: if videos.len() == 0 {
178 None
179 } else {
180 Some((
181 videos[0].id.clone(),
182 videos[0].thumbnails[image_index].url.clone(),
183 ))
184 },
185 }),
186 SearchItem::Channel {
187 name,
188 id,
189 url: _,
190 thumbnails,
191 subscribers,
192 video_count,
193 description,
194 description_html: _,
195 } => {
196 Self::MiniChannel(MiniChannelItem {
197 name,
198 id,
199 thumbnail_url: format!("https://{}", thumbnails[image_index].url),
200 video_count,
201 sub_count: subscribers,
202 sub_count_text: viewcount_text(subscribers as u64),
203 description,
204 })},
205 SearchItem::Unknown(searchitem_transitional) => Self::Unknown(searchitem_transitional),
110 } 206 }
111 } 207 }
112} 208}
src/global/keyaction.rs → src/global/structs/keyaction.rs renamed +1
@@ -1,5 +1,6 @@
1use serde::{Deserialize, Serialize}; 1use serde::{Deserialize, Serialize};
2 2
3/// Part of the keybindings config
3// Each key + modifier is bind to a key in a HashMap<KeyCode, HashMap<u8, KeyAction>> 4// Each key + modifier is bind to a key in a HashMap<KeyCode, HashMap<u8, KeyAction>>
4#[derive(Serialize, Deserialize, Clone, Copy, PartialEq, Eq, Debug)] 5#[derive(Serialize, Deserialize, Clone, Copy, PartialEq, Eq, Debug)]
5pub enum KeyAction { 6pub enum KeyAction {
src/global/message.rs → src/global/structs/message.rs renamed +2 −1
@@ -1,6 +1,7 @@
1use typemap::Key; 1use typemap::Key;
2 2
3// Messages in the message bar, the struct is global 3/// Messages in the message bar
4// is stored in `data.global`
4#[derive(Clone)] 5#[derive(Clone)]
5pub enum Message { 6pub enum Message {
6 Message(String), 7 Message(String),
src/global/structs/mod.rs added +18
@@ -0,0 +1,18 @@
1//! enums and structs
2mod errors;
3mod invidiousclient;
4mod item;
5mod keyaction;
6mod message;
7mod page;
8mod status;
9mod tasks;
10
11pub use errors::*;
12pub use invidiousclient::*;
13pub use item::*;
14pub use keyaction::*;
15pub use message::*;
16pub use page::*;
17pub use status::*;
18pub use tasks::*;
src/global/page.rs → src/global/structs/page.rs renamed +2 −1
@@ -3,7 +3,7 @@ use tui_additions::framework::Framework;
3use typemap::Key; 3use typemap::Key;
4 4
5// Page can be converted into PageConfig, which can then be converted into State 5// Page can be converted into PageConfig, which can then be converted into State
6// Covers all possible pages and its variants 6/// Covers all possible pages and variants
7#[derive(Clone, PartialEq, Eq)] 7#[derive(Clone, PartialEq, Eq)]
8pub enum Page { 8pub enum Page {
9 MainMenu(MainMenuPage), 9 MainMenu(MainMenuPage),
@@ -20,6 +20,7 @@ impl Key for Page {
20 type Value = Self; 20 type Value = Self;
21} 21}
22 22
23/// page variants for the main menu
23#[derive(Clone, PartialEq, Eq)] 24#[derive(Clone, PartialEq, Eq)]
24pub enum MainMenuPage { 25pub enum MainMenuPage {
25 Trending, 26 Trending,
src/global/status.rs → src/global/structs/status.rs renamed +1
@@ -1,5 +1,6 @@
1use typemap::Key; 1use typemap::Key;
2 2
3/// a struct for storing different info, currently only stores one info
3#[derive(Clone)] 4#[derive(Clone)]
4pub struct Status { 5pub struct Status {
5 pub popup_opened: bool, 6 pub popup_opened: bool,
src/global/tasks.rs → src/global/structs/tasks.rs renamed +3 −1
@@ -8,6 +8,7 @@ use tui::{
8use tui_additions::framework::{CursorState, Framework}; 8use tui_additions::framework::{CursorState, Framework};
9use typemap::Key; 9use typemap::Key;
10 10
11/// tasks to be put on taskqueues
11#[derive(Clone)] 12#[derive(Clone)]
12pub enum Task { 13pub enum Task {
13 RenderAll, 14 RenderAll,
@@ -17,6 +18,7 @@ pub enum Task {
17 ClearPage, 18 ClearPage,
18} 19}
19 20
21/// multiple tasks joined together, with duplicates removed
20#[derive(Clone, PartialEq, Eq)] 22#[derive(Clone, PartialEq, Eq)]
21pub struct TaskQueue { 23pub struct TaskQueue {
22 pub render: RenderTask, 24 pub render: RenderTask,
@@ -194,9 +196,9 @@ pub enum RenderTask {
194 Only(Vec<(usize, usize)>), 196 Only(Vec<(usize, usize)>),
195} 197}
196 198
199/// priority will get executed first, last will get executed after priority queue finished
197#[derive(Clone, Default)] 200#[derive(Clone, Default)]
198pub struct Tasks { 201pub struct Tasks {
199 // priority will get executed first, last will get executed after priority queue finished
200 pub priority: TaskQueue, 202 pub priority: TaskQueue,
201 pub last: TaskQueue, 203 pub last: TaskQueue,
202} 204}
src/global/traits/asurlstring.rs +1 −1
@@ -1,4 +1,4 @@
1// A single URL param 1/// A single URL param
2pub trait AsUrlString { 2pub trait AsUrlString {
3 const TAG: &'static str; 3 const TAG: &'static str;
4 fn as_url_string(&self) -> String 4 fn as_url_string(&self) -> String
src/config/configtrait.rs → src/global/traits/configtrait.rs renamed +2 −2
@@ -5,9 +5,9 @@ use std::{
5 io::Write, 5 io::Write,
6}; 6};
7 7
8pub const EXTENSION: &'static str = "yml"; 8const EXTENSION: &'static str = "yml";
9 9
10// Trait for loading, saving config files 10/// Trait for loading, saving config files
11pub trait ConfigTrait { 11pub trait ConfigTrait {
12 const LABEL: &'static str; 12 const LABEL: &'static str;
13 13
src/global/traits/mod.rs +8 −1
@@ -1 +1,8 @@
1pub mod asurlstring; 1//! public traits
2mod asurlstring;
3mod configtrait;
4mod searchfilteritem;
5
6pub use asurlstring::*;
7pub use configtrait::*;
8pub use searchfilteritem::*;
src/global/traits/searchfilteritem.rs added +13
@@ -0,0 +1,13 @@
1/// trait for on single search filter
2pub trait SearchFilterItem
3where
4 Self: Sized,
5{
6 // display name of the option
7 const NAME: &'static str;
8
9 fn option_name(&self) -> &'static str;
10 fn ordering() -> Vec<&'static str>;
11 fn selected_index(&self) -> usize;
12 fn at_index(index: usize) -> Self;
13}
src/init.rs +5 −5
@@ -1,22 +1,22 @@
1use crate::{ 1use crate::{
2 config::{ 2 config::{
3 AppearanceConfig, AppearanceConfigSerde, ConfigTrait, KeyBindingsConfig, MainConfig, 3 AppearanceConfig, AppearanceConfigSerde, KeyBindingsConfig, MainConfig, MinDimentions,
4 MinDimentions, PagesConfig, Search, 4 PagesConfig, Search,
5 }, 5 },
6 global::{ 6 global::{
7 invidiousclient::InvidiousClient, message::Message, page::Page, status::Status, 7 structs::{InvidiousClient, Message, Page, Status, Tasks},
8 tasks::Tasks, 8 traits::ConfigTrait,
9 }, 9 },
10}; 10};
11use home::home_dir; 11use home::home_dir;
12use std::{error::Error, fs}; 12use std::{error::Error, fs};
13use tui_additions::framework::Framework; 13use tui_additions::framework::Framework;
14 14
15/// app to run before the app starts
15// init tasks: 16// init tasks:
16// - create folders like `~/.config/youtube-tui/` and `~/.cache/youtube-tui/thumbnails/` 17// - create folders like `~/.config/youtube-tui/` and `~/.cache/youtube-tui/thumbnails/`
17// - load all config files 18// - load all config files
18// - insert data 19// - insert data
19
20pub fn init(framework: &mut Framework) -> Result<(), Box<dyn Error>> { 20pub fn init(framework: &mut Framework) -> Result<(), Box<dyn Error>> {
21 // creating files 21 // creating files
22 let home_dir = home_dir().unwrap(); 22 let home_dir = home_dir().unwrap();
src/items/iteminfo.rs +82 −3
@@ -8,10 +8,10 @@ use viuer::{print_from_file, Config};
8 8
9use crate::{ 9use crate::{
10 config::{AppearanceConfig, MainConfig}, 10 config::{AppearanceConfig, MainConfig},
11 global::{item::Item, status::Status}, 11 global::structs::{Item, Status},
12}; 12};
13 13
14// an item info displays info of any `Item`s 14/// an item info displays info of any `Item`s
15#[derive(Clone)] 15#[derive(Clone)]
16pub struct ItemInfo { 16pub struct ItemInfo {
17 pub item: Option<Item>, 17 pub item: Option<Item>,
@@ -49,7 +49,11 @@ impl FrameworkItem for ItemInfo {
49 .join(item.thumbnail_id()); 49 .join(item.thumbnail_id());
50 if thumbnail_path.exists() { 50 if thumbnail_path.exists() {
51 let config = Config { 51 let config = Config {
52 width: Some(area.width as u32), 52 width: Some(if let Item::MiniChannel(_) = item {
53 area.width / 2
54 } else {
55 area.width
56 } as u32),
53 x: area.x, 57 x: area.x,
54 y: area.y as i16, 58 y: area.y as i16,
55 use_sixel: main_config.images.use_sixels(), 59 use_sixel: main_config.images.use_sixels(),
@@ -116,6 +120,81 @@ impl FrameworkItem for ItemInfo {
116 ); 120 );
117 out 121 out
118 } 122 }
123 Item::MiniPlaylist(miniplaylist) => (
124 vec![
125 (
126 String::from("[Playlist]"),
127 Style::default().fg(appearance.colors.item_info.tag),
128 ),
129 (
130 miniplaylist.title.clone(),
131 Style::default().fg(appearance.colors.item_info.title),
132 ),
133 (
134 format!("Created by by {}", miniplaylist.channel),
135 Style::default().fg(appearance.colors.item_info.author),
136 ),
137 (
138 format!(
139 "{} video{}",
140 miniplaylist.video_count,
141 if miniplaylist.video_count <= 1 {
142 ""
143 } else {
144 "s"
145 }
146 ),
147 Style::default().fg(appearance.colors.item_info.video_count),
148 ),
149 ],
150 None,
151 ),
152 Item::MiniChannel(minichannel) => (
153 vec![
154 (
155 String::from("[Channel]"),
156 Style::default().fg(appearance.colors.item_info.tag),
157 ),
158 (
159 minichannel.name.clone(),
160 Style::default().fg(appearance.colors.item_info.title),
161 ),
162 (
163 format!("{} subscriber{}", minichannel.sub_count_text, if minichannel.sub_count <= 1 {
164 ""
165 } else {
166 "s"
167 }),
168 Style::default().fg(appearance.colors.item_info.sub_count),
169 ),
170 (
171 format!(
172 "{} video{}",
173 minichannel.video_count,
174 if minichannel.video_count <= 1 {
175 ""
176 } else {
177 "s"
178 }
179 ),
180 Style::default().fg(appearance.colors.item_info.video_count),
181 ),
182 ],
183 Some((
184 minichannel.description.clone(),
185 Style::default().fg(appearance.colors.item_info.description),
186 )),
187 ),
188 Item::Unknown(searchitem_transitional) => (
189 vec![(
190 format!("Unknown type `{}`", searchitem_transitional.r#type),
191 Style::default().fg(appearance.colors.error_text),
192 )],
193 Some((
194 serde_json::to_string(&searchitem_transitional).unwrap(),
195 Style::default().fg(appearance.colors.item_info.description),
196 )),
197 ),
119 }; 198 };
120 199
121 // puts each "span" in its own line 200 // puts each "span" in its own line
src/items/itemlist.rs +5 −9
@@ -2,7 +2,7 @@ use std::error::Error;
2 2
3use tui::{layout::Constraint, style::Style}; 3use tui::{layout::Constraint, style::Style};
4use tui_additions::{ 4use tui_additions::{
5 framework::{Framework, FrameworkItem}, 5 framework::FrameworkItem,
6 widgets::{Grid, TextList}, 6 widgets::{Grid, TextList},
7}; 7};
8 8
@@ -11,15 +11,11 @@ use crate::{
11 config::{AppearanceConfig, KeyBindingsConfig, MainConfig}, 11 config::{AppearanceConfig, KeyBindingsConfig, MainConfig},
12 global::{ 12 global::{
13 functions::download_all_images, 13 functions::download_all_images,
14 invidiousclient::InvidiousClient, 14 structs::{InvidiousClient, Item, KeyAction, MainMenuPage, Page, Task, Tasks},
15 item::Item,
16 keyaction::KeyAction,
17 page::{MainMenuPage, Page},
18 tasks::{Task, Tasks},
19 }, 15 },
20}; 16};
21 17
22// An item list displays a list of items 18/// An item list displays a list of items
23// 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
24#[derive(Clone)] 20#[derive(Clone)]
25pub struct ItemList { 21pub struct ItemList {
@@ -29,8 +25,8 @@ pub struct ItemList {
29 pub grid: Grid, 25 pub grid: Grid,
30} 26}
31 27
32impl ItemList { 28impl Default for ItemList {
33 pub fn new(framework: &mut Framework) -> Self { 29 fn default() -> Self {
34 Self { 30 Self {
35 info: ItemInfo::default(), 31 info: ItemInfo::default(),
36 items: Vec::new(), 32 items: Vec::new(),
src/items/messagebar.rs +2 −1
@@ -1,6 +1,6 @@
1use crate::{ 1use crate::{
2 config::{AppearanceConfig, MainConfig}, 2 config::{AppearanceConfig, MainConfig},
3 global::message::Message, 3 global::structs::Message,
4}; 4};
5use tui::{ 5use tui::{
6 style::Style, 6 style::Style,
@@ -8,6 +8,7 @@ use tui::{
8}; 8};
9use tui_additions::framework::FrameworkItem; 9use tui_additions::framework::FrameworkItem;
10 10
11/// a message bar item, contains no fields because the message is taken from `data.global.Message`
11#[derive(Clone, Copy, Default)] 12#[derive(Clone, Copy, Default)]
12pub struct MessageBar; 13pub struct MessageBar;
13 14
src/items/mod.rs +1
@@ -1,3 +1,4 @@
1//! items to be rendered, impls FrameworkItem
1mod searchbar; 2mod searchbar;
2pub use searchbar::*; 3pub use searchbar::*;
3mod messagebar; 4mod messagebar;
src/items/pagebutton.rs +2 −5
@@ -1,9 +1,6 @@
1use crate::{ 1use crate::{
2 config::AppearanceConfig, 2 config::AppearanceConfig,
3 global::{ 3 global::structs::{MainMenuPage, Page, Task, Tasks},
4 page::{MainMenuPage, Page},
5 tasks::{Task, Tasks},
6 },
7}; 4};
8use tui::{ 5use tui::{
9 layout::Alignment, 6 layout::Alignment,
@@ -12,7 +9,7 @@ use tui::{
12}; 9};
13use tui_additions::framework::FrameworkItem; 10use tui_additions::framework::FrameworkItem;
14 11
15// button that on press will go to another page instead of selecting it 12/// button that on press will go to another page instead of selecting it
16#[derive(Clone, Copy)] 13#[derive(Clone, Copy)]
17pub enum PageButton { 14pub enum PageButton {
18 Trending, 15 Trending,
src/items/searchbar.rs +1 −4
@@ -2,10 +2,7 @@ use std::error::Error;
2 2
3use crate::{ 3use crate::{
4 config::{AppearanceConfig, Search}, 4 config::{AppearanceConfig, Search},
5 global::{ 5 global::structs::{Page, Task, Tasks},
6 page::Page,
7 tasks::{Task, Tasks},
8 },
9}; 6};
10use crossterm::event::KeyCode; 7use crossterm::event::KeyCode;
11use tui::{ 8use tui::{
src/items/searchfilters.rs +2 −6
@@ -1,13 +1,8 @@
1use std::array::IntoIter;
2
3use crate::{ 1use crate::{
4 config::{AppearanceConfig, KeyBindingsConfig, Search, SearchFilters}, 2 config::{AppearanceConfig, KeyBindingsConfig, Search, SearchFilters},
5 global::{ 3 global::{
6 functions::popup_area, 4 functions::popup_area,
7 keyaction::KeyAction, 5 structs::{KeyAction, Message, Status, Task, Tasks},
8 message::Message,
9 status::Status,
10 tasks::{Task, Tasks},
11 }, 6 },
12}; 7};
13use tui::{ 8use tui::{
@@ -25,6 +20,7 @@ const POPUP_MIN_HEIGHT: u16 = 9;
25const POPUP_WIDTH_PERCENTAGE: u16 = 70; 20const POPUP_WIDTH_PERCENTAGE: u16 = 70;
26const POPOUP_HEIGHT_PERCENTAGE: u16 = 70; 21const POPOUP_HEIGHT_PERCENTAGE: u16 = 70;
27 22
23/// a tiny button when not selected, renders a popup when selected
28#[derive(Clone)] 24#[derive(Clone)]
29pub struct SearchFilter { 25pub struct SearchFilter {
30 pub left_textlist: TextList, 26 pub left_textlist: TextList,
src/run.rs +2 −7
@@ -5,15 +5,10 @@ use tui_additions::framework::{Framework, FrameworkDirection};
5 5
6use crate::{ 6use crate::{
7 config::KeyBindingsConfig, 7 config::KeyBindingsConfig,
8 global::{ 8 global::structs::{KeyAction, MainMenuPage, Message, Page, Task, Tasks},
9 keyaction::KeyAction,
10 message::Message,
11 page::{MainMenuPage, Page},
12 tasks::{Task, Tasks},
13 },
14}; 9};
15 10
16// the main event loop of the program 11/// the main event loop of the program
17pub fn run( 12pub fn run(
18 terminal: &mut Terminal<CrosstermBackend<Stdout>>, 13 terminal: &mut Terminal<CrosstermBackend<Stdout>>,
19 mut framework: Framework, 14 mut framework: Framework,