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