Commit e7f2bba5c2

e7f2bba5c2167f626d22f762114f74b27774b40a

parent: 54a1ffb572

Unsigned

Siriusmart <71584876+Siriusmart@users.noreply.github.com> · 2023-01-05 21:58 UTC

0.6.1

Layout: unified · split

Cargo.lock +53 −64
@@ -150,15 +150,14 @@ checksum = "3d7b894f5411737b7867f4827955924d7c254fc9f4d91a6aad6b097804b1018b"
150 150
151[[package]] 151[[package]]
152name = "console" 152name = "console"
153version = "0.15.2" 153version = "0.15.3"
154source = "registry+https://github.com/rust-lang/crates.io-index" 154source = "registry+https://github.com/rust-lang/crates.io-index"
155checksum = "c050367d967ced717c04b65d8c619d863ef9292ce0c5760028655a2fb298718c" 155checksum = "5556015fe3aad8b968e5d4124980fbe2f6aaee7aeec6b749de1faaa2ca5d0a4c"
156dependencies = [ 156dependencies = [
157 "encode_unicode", 157 "encode_unicode",
158 "lazy_static", 158 "lazy_static",
159 "libc", 159 "libc",
160 "terminal_size", 160 "windows-sys 0.42.0",
161 "winapi",
162] 161]
163 162
164[[package]] 163[[package]]
@@ -263,9 +262,9 @@ checksum = "7a81dae078cea95a014a339291cec439d2f232ebe854a9d672b796c6afafa9b7"
263 262
264[[package]] 263[[package]]
265name = "cxx" 264name = "cxx"
266version = "1.0.83" 265version = "1.0.85"
267source = "registry+https://github.com/rust-lang/crates.io-index" 266source = "registry+https://github.com/rust-lang/crates.io-index"
268checksum = "bdf07d07d6531bfcdbe9b8b739b104610c6508dcc4d63b410585faf338241daf" 267checksum = "5add3fc1717409d029b20c5b6903fc0c0b02fa6741d820054f4a2efa5e5816fd"
269dependencies = [ 268dependencies = [
270 "cc", 269 "cc",
271 "cxxbridge-flags", 270 "cxxbridge-flags",
@@ -275,9 +274,9 @@ dependencies = [
275 274
276[[package]] 275[[package]]
277name = "cxx-build" 276name = "cxx-build"
278version = "1.0.83" 277version = "1.0.85"
279source = "registry+https://github.com/rust-lang/crates.io-index" 278source = "registry+https://github.com/rust-lang/crates.io-index"
280checksum = "d2eb5b96ecdc99f72657332953d4d9c50135af1bac34277801cc3937906ebd39" 279checksum = "b4c87959ba14bc6fbc61df77c3fcfe180fc32b93538c4f1031dd802ccb5f2ff0"
281dependencies = [ 280dependencies = [
282 "cc", 281 "cc",
283 "codespan-reporting", 282 "codespan-reporting",
@@ -290,15 +289,15 @@ dependencies = [
290 289
291[[package]] 290[[package]]
292name = "cxxbridge-flags" 291name = "cxxbridge-flags"
293version = "1.0.83" 292version = "1.0.85"
294source = "registry+https://github.com/rust-lang/crates.io-index" 293source = "registry+https://github.com/rust-lang/crates.io-index"
295checksum = "ac040a39517fd1674e0f32177648334b0f4074625b5588a64519804ba0553b12" 294checksum = "69a3e162fde4e594ed2b07d0f83c6c67b745e7f28ce58c6df5e6b6bef99dfb59"
296 295
297[[package]] 296[[package]]
298name = "cxxbridge-macro" 297name = "cxxbridge-macro"
299version = "1.0.83" 298version = "1.0.85"
300source = "registry+https://github.com/rust-lang/crates.io-index" 299source = "registry+https://github.com/rust-lang/crates.io-index"
301checksum = "1362b0ddcfc4eb0a1f57b68bd77dd99f0e826958a96abd0ae9bd092e114ffed6" 300checksum = "3e7e2adeb6a0d4a282e581096b06e1791532b7d576dcde5ccd9382acf55db8e6"
302dependencies = [ 301dependencies = [
303 "proc-macro2", 302 "proc-macro2",
304 "quote", 303 "quote",
@@ -307,9 +306,9 @@ dependencies = [
307 306
308[[package]] 307[[package]]
309name = "dyn-clone" 308name = "dyn-clone"
310version = "1.0.9" 309version = "1.0.10"
311source = "registry+https://github.com/rust-lang/crates.io-index" 310source = "registry+https://github.com/rust-lang/crates.io-index"
312checksum = "4f94fa09c2aeea5b8839e414b7b841bf429fd25b9c522116ac97ee87856d88b2" 311checksum = "c9b0705efd4599c15a38151f4721f7bc388306f61084d3bfd50bd07fbca5cb60"
313 312
314[[package]] 313[[package]]
315name = "either" 314name = "either"
@@ -564,9 +563,9 @@ dependencies = [
564 563
565[[package]] 564[[package]]
566name = "half" 565name = "half"
567version = "2.1.0" 566version = "2.2.0"
568source = "registry+https://github.com/rust-lang/crates.io-index" 567source = "registry+https://github.com/rust-lang/crates.io-index"
569checksum = "ad6a9459c9c30b177b925162351f97e7d967c7ea8bab3b8352805327daf45554" 568checksum = "6c467d36af040b7b2681f5fddd27427f6da8d3d072f575a265e181d2f8e8d157"
570dependencies = [ 569dependencies = [
571 "crunchy", 570 "crunchy",
572] 571]
@@ -579,9 +578,9 @@ checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888"
579 578
580[[package]] 579[[package]]
581name = "hermit-abi" 580name = "hermit-abi"
582version = "0.1.19" 581version = "0.2.6"
583source = "registry+https://github.com/rust-lang/crates.io-index" 582source = "registry+https://github.com/rust-lang/crates.io-index"
584checksum = "62b467343b94ba476dcb2500d242dadbb39557df889310ac77c5d99100aaac33" 583checksum = "ee512640fe35acbfb4bb779db6f0d80704c2cacfa2e39b601ef3e3f47d1ae4c7"
585dependencies = [ 584dependencies = [
586 "libc", 585 "libc",
587] 586]
@@ -757,9 +756,9 @@ checksum = "11b0d96e660696543b251e58030cf9787df56da39dab19ad60eae7353040917e"
757 756
758[[package]] 757[[package]]
759name = "itoa" 758name = "itoa"
760version = "1.0.4" 759version = "1.0.5"
761source = "registry+https://github.com/rust-lang/crates.io-index" 760source = "registry+https://github.com/rust-lang/crates.io-index"
762checksum = "4217ad341ebadf8d8e724e264f13e593e0648f5b3e94b3896a5df283be015ecc" 761checksum = "fad582f4b9e86b6caa621cabeb0963332d92eea04729ab12892c2533951e6440"
763 762
764[[package]] 763[[package]]
765name = "jpeg-decoder" 764name = "jpeg-decoder"
@@ -793,15 +792,15 @@ checksum = "03087c2bad5e1034e8cace5926dec053fb3790248370865f5117a7d0213354c8"
793 792
794[[package]] 793[[package]]
795name = "libc" 794name = "libc"
796version = "0.2.138" 795version = "0.2.139"
797source = "registry+https://github.com/rust-lang/crates.io-index" 796source = "registry+https://github.com/rust-lang/crates.io-index"
798checksum = "db6d7e329c562c5dfab7a46a2afabc8b987ab9a4834c9d1ca04dc54c1546cef8" 797checksum = "201de327520df007757c1f0adce6e827fe8562fbc28bfd9c15571c66ca1f5f79"
799 798
800[[package]] 799[[package]]
801name = "link-cplusplus" 800name = "link-cplusplus"
802version = "1.0.7" 801version = "1.0.8"
803source = "registry+https://github.com/rust-lang/crates.io-index" 802source = "registry+https://github.com/rust-lang/crates.io-index"
804checksum = "9272ab7b96c9046fbc5bc56c06c117cb639fe2d509df0c421cad82d2915cf369" 803checksum = "ecd207c9c713c34f95a097a5b029ac2ce6010530c7b49d7fea24d977dede04f5"
805dependencies = [ 804dependencies = [
806 "cc", 805 "cc",
807] 806]
@@ -941,9 +940,9 @@ dependencies = [
941 940
942[[package]] 941[[package]]
943name = "num_cpus" 942name = "num_cpus"
944version = "1.14.0" 943version = "1.15.0"
945source = "registry+https://github.com/rust-lang/crates.io-index" 944source = "registry+https://github.com/rust-lang/crates.io-index"
946checksum = "f6058e64324c71e02bc2b150e4f3bc8286db6c83092132ffa3f6b1eab0f9def5" 945checksum = "0fac9e2da13b5eb447a6ce3d392f23a29d8694bff781bf03a16cd9ac8697593b"
947dependencies = [ 946dependencies = [
948 "hermit-abi", 947 "hermit-abi",
949 "libc", 948 "libc",
@@ -980,15 +979,15 @@ dependencies = [
980 979
981[[package]] 980[[package]]
982name = "once_cell" 981name = "once_cell"
983version = "1.16.0" 982version = "1.17.0"
984source = "registry+https://github.com/rust-lang/crates.io-index" 983source = "registry+https://github.com/rust-lang/crates.io-index"
985checksum = "86f0b0d4bf799edbc74508c1e8bf170ff5f41238e5f8225603ca7caaae2b7860" 984checksum = "6f61fba1741ea2b3d6a1e3178721804bb716a68a6aeba1149b5d52e3d464ea66"
986 985
987[[package]] 986[[package]]
988name = "openssl" 987name = "openssl"
989version = "0.10.44" 988version = "0.10.45"
990source = "registry+https://github.com/rust-lang/crates.io-index" 989source = "registry+https://github.com/rust-lang/crates.io-index"
991checksum = "29d971fd5722fec23977260f6e81aa67d2f22cadbdc2aa049f1022d9a3be1566" 990checksum = "b102428fd03bc5edf97f62620f7298614c45cedf287c271e7ed450bbaf83f2e1"
992dependencies = [ 991dependencies = [
993 "bitflags", 992 "bitflags",
994 "cfg-if", 993 "cfg-if",
@@ -1018,9 +1017,9 @@ checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf"
1018 1017
1019[[package]] 1018[[package]]
1020name = "openssl-sys" 1019name = "openssl-sys"
1021version = "0.9.79" 1020version = "0.9.80"
1022source = "registry+https://github.com/rust-lang/crates.io-index" 1021source = "registry+https://github.com/rust-lang/crates.io-index"
1023checksum = "5454462c0eced1e97f2ec09036abc8da362e66802f66fd20f86854d9d8cbcbc4" 1022checksum = "23bbbf7854cd45b83958ebe919f0e8e516793727652e27fda10a8384cfc790b7"
1024dependencies = [ 1023dependencies = [
1025 "autocfg", 1024 "autocfg",
1026 "cc", 1025 "cc",
@@ -1110,18 +1109,18 @@ dependencies = [
1110 1109
1111[[package]] 1110[[package]]
1112name = "proc-macro2" 1111name = "proc-macro2"
1113version = "1.0.47" 1112version = "1.0.49"
1114source = "registry+https://github.com/rust-lang/crates.io-index" 1113source = "registry+https://github.com/rust-lang/crates.io-index"
1115checksum = "5ea3d908b0e36316caf9e9e2c4625cdde190a7e6f440d794667ed17a1855e725" 1114checksum = "57a8eca9f9c4ffde41714334dee777596264c7825420f521abc92b5b5deb63a5"
1116dependencies = [ 1115dependencies = [
1117 "unicode-ident", 1116 "unicode-ident",
1118] 1117]
1119 1118
1120[[package]] 1119[[package]]
1121name = "quote" 1120name = "quote"
1122version = "1.0.21" 1121version = "1.0.23"
1123source = "registry+https://github.com/rust-lang/crates.io-index" 1122source = "registry+https://github.com/rust-lang/crates.io-index"
1124checksum = "bbe448f377a7d6961e30f5955f9b8d106c3f5e449d493ee1b125c1d43c2b5179" 1123checksum = "8856d8364d252a14d474036ea1358d63c9e6965c8e5c1885c18f73d70bff9c7b"
1125dependencies = [ 1124dependencies = [
1126 "proc-macro2", 1125 "proc-macro2",
1127] 1126]
@@ -1214,9 +1213,9 @@ dependencies = [
1214 1213
1215[[package]] 1214[[package]]
1216name = "ryu" 1215name = "ryu"
1217version = "1.0.11" 1216version = "1.0.12"
1218source = "registry+https://github.com/rust-lang/crates.io-index" 1217source = "registry+https://github.com/rust-lang/crates.io-index"
1219checksum = "4501abdff3ae82a1c1b477a17252eb69cee9e66eb915c1abaa4f44d873df9f09" 1218checksum = "7b4b9743ed687d4b4bcedf9ff5eaa7398495ae14e61cba0a295704edbc7decde"
1220 1219
1221[[package]] 1220[[package]]
1222name = "schannel" 1221name = "schannel"
@@ -1242,9 +1241,9 @@ checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd"
1242 1241
1243[[package]] 1242[[package]]
1244name = "scratch" 1243name = "scratch"
1245version = "1.0.2" 1244version = "1.0.3"
1246source = "registry+https://github.com/rust-lang/crates.io-index" 1245source = "registry+https://github.com/rust-lang/crates.io-index"
1247checksum = "9c8132065adcfd6e02db789d9285a0deb2f3fcb04002865ab67d5fb103533898" 1246checksum = "ddccb15bcce173023b3fedd9436f882a0739b8dfb45e4f6b6002bee5929f61b2"
1248 1247
1249[[package]] 1248[[package]]
1250name = "security-framework" 1249name = "security-framework"
@@ -1271,18 +1270,18 @@ dependencies = [
1271 1270
1272[[package]] 1271[[package]]
1273name = "serde" 1272name = "serde"
1274version = "1.0.151" 1273version = "1.0.152"
1275source = "registry+https://github.com/rust-lang/crates.io-index" 1274source = "registry+https://github.com/rust-lang/crates.io-index"
1276checksum = "97fed41fc1a24994d044e6db6935e69511a1153b52c15eb42493b26fa87feba0" 1275checksum = "bb7d1f0d3021d347a83e556fc4683dea2ea09d87bccdf88ff5c12545d89d5efb"
1277dependencies = [ 1276dependencies = [
1278 "serde_derive", 1277 "serde_derive",
1279] 1278]
1280 1279
1281[[package]] 1280[[package]]
1282name = "serde_derive" 1281name = "serde_derive"
1283version = "1.0.151" 1282version = "1.0.152"
1284source = "registry+https://github.com/rust-lang/crates.io-index" 1283source = "registry+https://github.com/rust-lang/crates.io-index"
1285checksum = "255abe9a125a985c05190d687b320c12f9b1f0b99445e608c21ba0782c719ad8" 1284checksum = "af487d118eecd09402d70a5d72551860e788df87b464af30e5ea6a38c75c541e"
1286dependencies = [ 1285dependencies = [
1287 "proc-macro2", 1286 "proc-macro2",
1288 "quote", 1287 "quote",
@@ -1291,9 +1290,9 @@ dependencies = [
1291 1290
1292[[package]] 1291[[package]]
1293name = "serde_json" 1292name = "serde_json"
1294version = "1.0.89" 1293version = "1.0.91"
1295source = "registry+https://github.com/rust-lang/crates.io-index" 1294source = "registry+https://github.com/rust-lang/crates.io-index"
1296checksum = "020ff22c755c2ed3f8cf162dbb41a7268d934702f3ed3631656ea597e08fc3db" 1295checksum = "877c235533714907a8c2464236f5c4b2a17262ef1bd71f38f35ea592c8da6883"
1297dependencies = [ 1296dependencies = [
1298 "itoa", 1297 "itoa",
1299 "ryu", 1298 "ryu",
@@ -1314,9 +1313,9 @@ dependencies = [
1314 1313
1315[[package]] 1314[[package]]
1316name = "serde_yaml" 1315name = "serde_yaml"
1317version = "0.9.14" 1316version = "0.9.16"
1318source = "registry+https://github.com/rust-lang/crates.io-index" 1317source = "registry+https://github.com/rust-lang/crates.io-index"
1319checksum = "6d232d893b10de3eb7258ff01974d6ee20663d8e833263c99409d4b13a0209da" 1318checksum = "92b5b431e8907b50339b51223b97d102db8d987ced36f6e4d03621db9316c834"
1320dependencies = [ 1319dependencies = [
1321 "indexmap", 1320 "indexmap",
1322 "itoa", 1321 "itoa",
@@ -1409,9 +1408,9 @@ dependencies = [
1409 1408
1410[[package]] 1409[[package]]
1411name = "syn" 1410name = "syn"
1412version = "1.0.105" 1411version = "1.0.107"
1413source = "registry+https://github.com/rust-lang/crates.io-index" 1412source = "registry+https://github.com/rust-lang/crates.io-index"
1414checksum = "60b9b43d45702de4c839cb9b51d9f529c5dd26a4aff255b42b1ebc03e88ee908" 1413checksum = "1f4064b5b16e03ae50984a5a8ed5d4f8803e6bc1fd170a3cda91a1be4b18e3f5"
1415dependencies = [ 1414dependencies = [
1416 "proc-macro2", 1415 "proc-macro2",
1417 "quote", 1416 "quote",
@@ -1441,16 +1440,6 @@ dependencies = [
1441 "winapi-util", 1440 "winapi-util",
1442] 1441]
1443 1442
1444[[package]]
1445name = "terminal_size"
1446version = "0.1.17"
1447source = "registry+https://github.com/rust-lang/crates.io-index"
1448checksum = "633c1a546cee861a1a6d0dc69ebeca693bf4296661ba7852b9d21d159e0506df"
1449dependencies = [
1450 "libc",
1451 "winapi",
1452]
1453
1454[[package]] 1443[[package]]
1455name = "threadpool" 1444name = "threadpool"
1456version = "1.8.1" 1445version = "1.8.1"
@@ -1615,9 +1604,9 @@ checksum = "099b7128301d285f79ddd55b9a83d5e6b9e97c92e0ea0daebee7263e932de992"
1615 1604
1616[[package]] 1605[[package]]
1617name = "unicode-ident" 1606name = "unicode-ident"
1618version = "1.0.5" 1607version = "1.0.6"
1619source = "registry+https://github.com/rust-lang/crates.io-index" 1608source = "registry+https://github.com/rust-lang/crates.io-index"
1620checksum = "6ceab39d59e4c9499d4e5a8ee0e2735b891bb7308ac83dfb4e80cad195c9f6f3" 1609checksum = "84a22b9f218b40614adcb3f4ff08b703773ad44fa9423e4e0d346d5db86e4ebc"
1621 1610
1622[[package]] 1611[[package]]
1623name = "unicode-normalization" 1612name = "unicode-normalization"
@@ -1651,9 +1640,9 @@ dependencies = [
1651 1640
1652[[package]] 1641[[package]]
1653name = "unsafe-libyaml" 1642name = "unsafe-libyaml"
1654version = "0.2.4" 1643version = "0.2.5"
1655source = "registry+https://github.com/rust-lang/crates.io-index" 1644source = "registry+https://github.com/rust-lang/crates.io-index"
1656checksum = "c1e5fa573d8ac5f1a856f8d7be41d390ee973daf97c806b2c1a465e4e1406e68" 1645checksum = "bc7ed8ba44ca06be78ea1ad2c3682a43349126c8818054231ee6f4748012aed2"
1657 1646
1658[[package]] 1647[[package]]
1659name = "url" 1648name = "url"
docs/src/README.md +2 −3
@@ -53,12 +53,11 @@ It also includes features like:
53 53
54### What it doesn't have 54### What it doesn't have
55 55
56- Command line args (first priority) 56- Binding commands to keys (first priority)
57- Bootleg Vimscript? (will implement) 57- Bootleg Vimscript? (first priority)
58- Channel search (will implement) 58- Channel search (will implement)
59- Channel videos sorting (will implement) 59- Channel videos sorting (will implement)
60- Subscriptions (will implement) 60- Subscriptions (will implement)
61- Recommendations/comments (probably will not implement)
62 61
63## How to contribute 62## How to contribute
64 63
docs/src/changelogs.md +13 −1
@@ -1,9 +1,21 @@
1# Changelogs 1# Changelogs
2 2
3## v0.6.0 3## v0.6.1
4 4
5### Added 5### Added
6 6
7- Rework of the env system, now using environment variables provided by the OS as opposed to implmenting own version of env
8- Ability to use envs in command mode
9- Launch commands (including `youtube-tui help`)
10
11### Fixed
12
13- Screen blinking when pressing up arrow on the first item in playlist page, videos view
14
15### v0.6.0
16
17#### Added
18
7- Mouse support 19- Mouse support
8- Vim-like commands 20- Vim-like commands
9- Pasting with `Ctrl + V` in search bar and command mode 21- Pasting with `Ctrl + V` in search bar and command mode
docs/src/commands.md +26 −13
@@ -2,6 +2,10 @@
2 2
3Commands can be entered to the TUI by pressing the `:` key, the same as in Vim. Some commands have shorter *alternatives* that can be used instead. 3Commands can be entered to the TUI by pressing the `:` key, the same as in Vim. Some commands have shorter *alternatives* that can be used instead.
4 4
5> Env variables can be used by passing in as `${key}`, such as `:channel ${channel-id}` when in a video or playlist page.
6
7**Loadpage commands** can also be used when launching, for example `youtube-tui loadpage popular` or `youtube-tui popular`.
8
5Below are the avaliable commands: 9Below are the avaliable commands:
6 10
7## Loadpage 11## Loadpage
@@ -9,13 +13,13 @@ Below are the avaliable commands:
9`loadpage` can be used to load a specific page. 13`loadpage` can be used to load a specific page.
10 14
11```vim 15```vim
12:loadpage popular (alt: `popular`) 16loadpage popular (alt: `popular`)
13:loadpage trending (alt: `trending`) 17loadpage trending (alt: `trending`)
14:loadpage watchhistory (alt: `watchhistory`) 18loadpage watchhistory (alt: `watchhistory`)
15:loadpage search [search query] (alt: `search [search query]`) 19loadpage search [search query] (alt: `search [search query]`)
16:loadpage video [id or url] (alt: `video [id or url]`) 20loadpage video [id or url] (alt: `video [id or url]`)
17:loadpage playlist [id or url] (alt: `playlist [id or url] `) 21loadpage playlist [id or url] (alt: `playlist [id or url] `)
18:loadpage channel [id or url] (alt: `channel [id or url] `) 22loadpage channel [id or url] (alt: `channel [id or url] `)
19``` 23```
20 24
21## History 25## History
@@ -23,19 +27,28 @@ Below are the avaliable commands:
23`history` is used to manage page history (`Backspace` equivalent). 27`history` is used to manage page history (`Backspace` equivalent).
24 28
25```vim 29```vim
26:history back (alt: `back`) 30history back (alt: `back`)
27:history clear 31history clear
28``` 32```
29 33
30## Utility 34## Utility
31 35
32```vim 36```vim
33:reload (alt `r`) 37reload (alt `r`)
34:reload configs (alt `reload/r config/configs`) 38reload configs (alt `reload/r config/configs`)
35:flush 39flush
36:quit (alt `q`, `exit`, `x`) 40quit (alt `q`, `exit`, `x`)
37``` 41```
38 42
39> The `flush` command is used to run all tasks in queue immediately, this is usually done automatically. 43> The `flush` command is used to run all tasks in queue immediately, this is usually done automatically.
40> 44>
41> But for when tasks are stacked up in the *same* event loop and the order of which they are executed matters, this command can be used to force the already stacked up commands to be ran first. 45> But for when tasks are stacked up in the *same* event loop and the order of which they are executed matters, this command can be used to force the already stacked up commands to be ran first.
46
47## Text commands
48
49Text commands generates a *text only response* without launching the TUI.
50
51```vim
52help
53version
54```
docs/src/config/commands.md +4 −2
@@ -9,7 +9,7 @@ video:
9- Play video: ${video-player} ${embed-url} 9- Play video: ${video-player} ${embed-url}
10- Play audio: ${terminal-emulator} ${video-player} ${embed-url} --no-video 10- Play audio: ${terminal-emulator} ${video-player} ${embed-url} --no-video
11- Play audio (loop): ${terminal-emulator} ${video-player} ${embed-url} --no-video --loop-file=inf 11- Play audio (loop): ${terminal-emulator} ${video-player} ${embed-url} --no-video --loop-file=inf
12- View channel: :channel ${channel_id} 12- View channel: :channel ${channel-id}
13- Open in browser: ${browser} ${url} 13- Open in browser: ${browser} ${url}
14- Download video (webm): ${terminal-emulator} ${youtube-downloader} -o ${download-path} ${embed-url} 14- Download video (webm): ${terminal-emulator} ${youtube-downloader} -o ${download-path} ${embed-url}
15- Download audio (opus): ${terminal-emulator} ${youtube-downloader} -o ${download-path} ${embed-url} -x 15- Download audio (opus): ${terminal-emulator} ${youtube-downloader} -o ${download-path} ${embed-url} -x
@@ -20,7 +20,7 @@ playlist:
20- Play all audio: ${terminal-emulator} ${video-player} ${all-videos} --no-video 20- Play all audio: ${terminal-emulator} ${video-player} ${all-videos} --no-video
21- Shuffle play all audio: ${terminal-emulator} ${video-player} ${all-videos} --no-video --shuffle 21- Shuffle play all audio: ${terminal-emulator} ${video-player} ${all-videos} --no-video --shuffle
22- Shuffle play all audio (loop): ${terminal-emulator} ${video-player} ${all-videos} --no-video --shuffle --loop-playlist=inf 22- Shuffle play all audio (loop): ${terminal-emulator} ${video-player} ${all-videos} --no-video --shuffle --loop-playlist=inf
23- View channel: :channel ${channel_id} 23- View channel: :channel ${channel-id}
24- Open in browser: ${browser} ${url} 24- Open in browser: ${browser} ${url}
25- Download all video (webm): ${terminal-emulator} ${youtube-downloader} -o ${download-path} ${all-videos} 25- Download all video (webm): ${terminal-emulator} ${youtube-downloader} -o ${download-path} ${all-videos}
26- Download all audio (opus): ${terminal-emulator} ${youtube-downloader} -o ${download-path} ${all-videos} -x 26- Download all audio (opus): ${terminal-emulator} ${youtube-downloader} -o ${download-path} ${all-videos} -x
@@ -84,6 +84,8 @@ Does not include custom env set in `main.yml`.
84|Name|Page|Value| 84|Name|Page|Value|
85|---|---|---| 85|---|---|---|
86|`url`|video & playlist|String url to the web page| 86|`url`|video & playlist|String url to the web page|
87|`id`|video & playlist|String id of the video or playlist|
88|`channel-id`|video & playlist|String id of the channel|
87|`embed-url`|video|String url to the embed video (required to play video using mpv from Invidious)| 89|`embed-url`|video|String url to the embed video (required to play video using mpv from Invidious)|
88|`all-videos`|playlist|String url***s*** separated by space to all embed videos in a playlist| 90|`all-videos`|playlist|String url***s*** separated by space to all embed videos in a playlist|
89|`provider`|video & playlist|To display the current provider, is the only env that can be displayed in the label, and can only be used when `%switch-provider%` is the command| 91|`provider`|video & playlist|To display the current provider, is the only env that can be displayed in the label, and can only be used when `%switch-provider%` is the command|
docs/src/installation.md +3 −5
@@ -25,13 +25,11 @@ The YouTube TUI is avaliable in the AUR <a href="https://aur.archlinux.org/packa
25Use an <a href="https://aur.archlinux.org" target=_blank>AUR</a> helper like <a href="https://aur.archlinux.org/packages/yay" target=_blank>`yay`</a> to install. 25Use an <a href="https://aur.archlinux.org" target=_blank>AUR</a> helper like <a href="https://aur.archlinux.org/packages/yay" target=_blank>`yay`</a> to install.
26 26
27```sh 27```sh
28yay -S youtube-tui # replace `yay` with your AUR helper 28yay -S youtube-tui-git # replace `yay` with your AUR helper
29yay -S youtube-tui-full-bin # requires libsixel
30yay -S youtube-tui-nodefaults-bin
29``` 31```
30 32
31## Download a compiled binary
32
33Download the compiled binary for your system from <a href="https://github.com/Siriusmart/youtube-tui/releases" target=_blank>*GitHub releases*</a> and manually place it in *a folder* (e.g. `~/.cargo/bin/` or `/bin/`)
34
35## Build from source 33## Build from source
36 34
37Use the `cargo` command: 35Use the `cargo` command:
src/config/commands.rs +2 −2
@@ -77,7 +77,7 @@ fn video_default() -> Vec<HashMap<String, String>> {
77 )]), 77 )]),
78 HashMap::from([( 78 HashMap::from([(
79 String::from("View channel"), 79 String::from("View channel"),
80 String::from(":channel ${channel_id}"), 80 String::from(":channel ${channel-id}"),
81 )]), 81 )]),
82 HashMap::from([( 82 HashMap::from([(
83 String::from("Open in browser"), 83 String::from("Open in browser"),
@@ -123,7 +123,7 @@ fn playlist_default() -> Vec<HashMap<String, String>> {
123 )]), 123 )]),
124 HashMap::from([( 124 HashMap::from([(
125 String::from("View channel"), 125 String::from("View channel"),
126 String::from(":channel ${channel_id}"), 126 String::from(":channel ${channel-id}"),
127 )]), 127 )]),
128 HashMap::from([( 128 HashMap::from([(
129 String::from("Open in browser"), 129 String::from("Open in browser"),
src/config/keybindings.rs −4
@@ -109,10 +109,6 @@ impl Default for KeyBindingsConfigSerde {
109 HashMap::from([(0, KeyAction::FirstHistory)]), 109 HashMap::from([(0, KeyAction::FirstHistory)]),
110 ), 110 ),
111 // clipboard 111 // clipboard
112 (
113 KeyCodeSerde::Char('c'),
114 HashMap::from([(2, KeyAction::Copy)]),
115 ),
116 ( 112 (
117 KeyCodeSerde::Char('v'), 113 KeyCodeSerde::Char('v'),
118 HashMap::from([(2, KeyAction::Paste)]), 114 HashMap::from([(2, KeyAction::Paste)]),
src/config/main.rs −1
@@ -80,7 +80,6 @@ impl Images {
80pub enum Provider { 80pub enum Provider {
81 YouTube, 81 YouTube,
82 Invidious, 82 Invidious,
83 // Piped,
84} 83}
85 84
86impl Provider { 85impl Provider {
src/eggs.rs deleted −57
@@ -1,57 +0,0 @@
1use std::{fs::{self, File}, thread, time::Duration, process::Command, io::Write};
2
3use chrono::Datelike;
4use home::home_dir;
5
6use crate::global::functions::fake_rand_range;
7
8pub fn egg() {
9 let date_chrono = chrono::Local::now().date_naive();
10
11 let month = date_chrono.month();
12 let date = date_chrono.day();
13
14 let home_dir = home_dir().unwrap();
15 let displayed_store_path = home_dir.join(".local/share/youtube-tui/eggs/");
16 let video_cache_path = home_dir.join(".cache/youtube-tui/eggs/");
17
18 if !displayed_store_path.exists() {
19 let _ = fs::create_dir_all(displayed_store_path);
20 }
21
22 if !video_cache_path.exists() {
23 let _ = fs::create_dir_all(video_cache_path);
24 }
25
26 match (month, date) {
27 (12, 25) | (12, 26) => if !displayed("christmas") {
28 thread::spawn(|| {
29 thread::sleep(Duration::from_secs(fake_rand_range(30_i64, 250) as u64));
30
31 store("christmas", "happy christmas ;)");
32 let _ = Command::new("mpv").args(["--no-terminal", CHRISTMAS_VIDEOS[fake_rand_range(0_i64, CHRISTMAS_VIDEOS.len() as i64) as usize]]).output();
33 });
34 },
35 _ => {}
36 }
37}
38
39fn displayed(label: &str) -> bool {
40 let home_dir = home_dir().unwrap();
41 let year = chrono::Local::now().date_naive().year();
42 let file_path = home_dir.join(".local/share/youtube-tui/eggs/").join(format!("{label}{year}"));
43
44 file_path.exists()
45}
46
47fn store(label: &str, content: &str) {
48 let home_dir = home_dir().unwrap();
49 let year = chrono::Local::now().date_naive().year();
50 let file_path = home_dir.join(".local/share/youtube-tui/eggs/").join(format!("{label}{year}"));
51
52
53 let mut file = File::create(file_path).unwrap();
54 let _ =file.write_all(content.as_bytes());
55}
56
57const CHRISTMAS_VIDEOS: &[&str] = &["https://youtu.be/YH7LouNgIvE", "https://youtu.be/KsInh3VvE3s"];
src/global/functions/command_capture.rs +2 −2
@@ -1,4 +1,4 @@
1use super::get_clipboard; 1use super::{apply_envs, get_clipboard};
2use crate::{ 2use crate::{
3 config::KeyBindingsConfig, 3 config::KeyBindingsConfig,
4 global::structs::{KeyAction, Message, Status, Task, Tasks}, 4 global::structs::{KeyAction, Message, Status, Task, Tasks},
@@ -66,7 +66,7 @@ pub fn command_capture(framework: &mut FrameworkClean, key: KeyEvent) -> bool {
66 .get_mut::<Tasks>() 66 .get_mut::<Tasks>()
67 .unwrap() 67 .unwrap()
68 .priority 68 .priority
69 .push(Task::Command(textfield.content.clone())); 69 .push(Task::Command(apply_envs(textfield.content.clone())));
70 framework 70 framework
71 .data 71 .data
72 .global 72 .global
src/global/functions/from_url.rs +11 −3
@@ -1,3 +1,4 @@
1/// gets the channel id from it's url
1pub fn from_channel_url(identifier: &str) -> Result<String, String> { 2pub fn from_channel_url(identifier: &str) -> Result<String, String> {
2 // a youtube channel id is exactly 24 characters long, so if the identifier to 24 chars 3 // a youtube channel id is exactly 24 characters long, so if the identifier to 24 chars
3 // long, then just assume its the channel id 4 // long, then just assume its the channel id
@@ -27,14 +28,18 @@ pub fn from_channel_url(identifier: &str) -> Result<String, String> {
27} 28}
28 29
29pub fn from_video_url(identifier: &str) -> Result<String, String> { 30pub fn from_video_url(identifier: &str) -> Result<String, String> {
31 // a youtube video id is exactly 11 characters long, so if the identifier to 11 chars
32 // long, then just assume its the video id
30 if identifier.len() == 11 { 33 if identifier.len() == 11 {
31 Ok(identifier.to_string()) 34 Ok(identifier.to_string())
32 } else { 35 } else {
36 // the id can come after "?v=" in an url
33 let index = if let Some(index) = identifier.find("?v=") { 37 let index = if let Some(index) = identifier.find("?v=") {
34 if identifier.len() < index + 15 { 38 if identifier.len() < index + 15 {
35 return Err(format!("Cannot find video id from string `{}`", identifier)); 39 return Err(format!("Cannot find video id from string `{}`", identifier));
36 } 40 }
37 index + 3 41 index + 3
42 // and also "youtu.be/"
38 } else if let Some(index) = identifier.find("youtu.be/") { 43 } else if let Some(index) = identifier.find("youtu.be/") {
39 if identifier.len() < index + 21 { 44 if identifier.len() < index + 21 {
40 return Err(format!("Cannot find video id from string `{}`", identifier)); 45 return Err(format!("Cannot find video id from string `{}`", identifier));
@@ -49,17 +54,20 @@ pub fn from_video_url(identifier: &str) -> Result<String, String> {
49} 54}
50 55
51pub fn from_playlist_url(identifier: &str) -> Result<String, String> { 56pub fn from_playlist_url(identifier: &str) -> Result<String, String> {
57 // a youtube playlist id is exactly 34 characters long, so if the identifier to 34 chars
58 // long, then just assume its the playlist id
52 if identifier.len() == 34 { 59 if identifier.len() == 34 {
53 Ok(identifier.to_string()) 60 Ok(identifier.to_string())
54 } else { 61 } else {
55 let index = if let Some(index) = identifier.find("playlist?list=") { 62 // the id can come after "list=" in urls
56 if identifier.len() < index + 48 { 63 let index = if let Some(index) = identifier.find("list=") {
64 if identifier.len() < index + 39 {
57 return Err(format!( 65 return Err(format!(
58 "Cannot find plalyist id from string `{}`", 66 "Cannot find plalyist id from string `{}`",
59 identifier 67 identifier
60 )); 68 ));
61 } 69 }
62 index + 14 70 index + 5
63 } else { 71 } else {
64 return Err(format!( 72 return Err(format!(
65 "Cannot find playlist id from string `{}`", 73 "Cannot find playlist id from string `{}`",
src/global/functions/mod.rs +3 −3
@@ -10,14 +10,14 @@ pub use download_all_images::download_all_images;
10mod popup_area; 10mod popup_area;
11pub use popup_area::popup_area; 11pub use popup_area::popup_area;
12mod run_command; 12mod run_command;
13pub use run_command::run_command; 13pub use run_command::*;
14mod command_capture; 14mod command_capture;
15pub use command_capture::command_capture; 15pub use command_capture::command_capture;
16mod fake_rand; 16mod fake_rand;
17pub use fake_rand::*; 17pub use fake_rand::*;
18mod clipboard; 18mod clipboard;
19pub use self::clipboard::*; 19pub use self::clipboard::*;
20mod type_name_of_val;
21pub use type_name_of_val::*;
22mod from_url; 20mod from_url;
23pub use from_url::*; 21pub use from_url::*;
22mod envs;
23pub use envs::*;
src/global/functions/run_command.rs +136 −24
@@ -6,29 +6,44 @@ use crate::{
6 }, 6 },
7 load_configs, 7 load_configs,
8}; 8};
9use std::io::Stdout; 9use std::{io::Stdout, thread};
10use tui::{backend::CrosstermBackend, Terminal}; 10use tui::{backend::CrosstermBackend, Terminal};
11use tui_additions::framework::Framework; 11use tui_additions::framework::Framework;
12 12
13use super::{fake_rand_range, from_channel_url, from_video_url, from_playlist_url}; 13use super::{fake_rand_range, from_channel_url, from_playlist_url, from_video_url};
14 14
15/// WIP text command support 15/// runs text command - command from the command line (not TUI) which response is just a string
16pub fn text_command(command: &[&str]) -> Option<String> {
17 match command {
18 ["help"] => Some(String::from(HELP_MSG)),
19 ["version"] => Some(format!(
20 "{} {}",
21 env!("CARGO_PKG_NAME"),
22 env!("CARGO_PKG_VERSION")
23 )),
24 _ => None,
25 }
26}
27
28/// runs a command in the TUI, returns true if its a loadpage command, false if not
16pub fn run_command( 29pub fn run_command(
17 command: &[&str], 30 command: &[&str],
18 framework: &mut Framework, 31 framework: &mut Framework,
19 terminal: &mut Terminal<CrosstermBackend<Stdout>>, 32 terminal: &mut Terminal<CrosstermBackend<Stdout>>,
20) { 33) -> bool {
21 // match a command splitted by space to a bunch of avaliable commands 34 // match a command splitted by space to a bunch of avaliable commands
22 match command { 35 match command {
23 [] => {} 36 [] => false,
24 ["help"] | ["h"] => { 37 ["help"] | ["h"] => {
25 *framework.data.global.get_mut::<Message>().unwrap() = Message::Message(String::from( 38 *framework.data.global.get_mut::<Message>().unwrap() = Message::Message(String::from(
26 "Avaliable commands can be viewed by running `youtube-tui help` in terminal", 39 "Avaliable commands can be viewed by running `youtube-tui help` in terminal",
27 )) 40 ));
41 false
28 } 42 }
29 ["loadpage"] => { 43 ["loadpage"] => {
30 *framework.data.global.get_mut::<Message>().unwrap() = 44 *framework.data.global.get_mut::<Message>().unwrap() =
31 Message::Message(String::from("Usage: `loadpage {page}`")) 45 Message::Message(String::from("Usage: `loadpage {page}`"));
46 false
32 } 47 }
33 // loads a given page 48 // loads a given page
34 ["loadpage", page, ..] => { 49 ["loadpage", page, ..] => {
@@ -40,7 +55,7 @@ pub fn run_command(
40 if command.len() == 2 { 55 if command.len() == 2 {
41 *framework.data.global.get_mut::<Message>().unwrap() = 56 *framework.data.global.get_mut::<Message>().unwrap() =
42 Message::Message(String::from("Usage: `loadpage channel {id/url}`")); 57 Message::Message(String::from("Usage: `loadpage channel {id/url}`"));
43 return; 58 return false;
44 } 59 }
45 60
46 match from_channel_url(command[2]) { 61 match from_channel_url(command[2]) {
@@ -51,7 +66,7 @@ pub fn run_command(
51 Err(e) => { 66 Err(e) => {
52 *framework.data.global.get_mut::<Message>().unwrap() = 67 *framework.data.global.get_mut::<Message>().unwrap() =
53 Message::Error(e); 68 Message::Error(e);
54 return; 69 return false;
55 } 70 }
56 } 71 }
57 } 72 }
@@ -59,7 +74,7 @@ pub fn run_command(
59 if command.len() == 2 { 74 if command.len() == 2 {
60 *framework.data.global.get_mut::<Message>().unwrap() = 75 *framework.data.global.get_mut::<Message>().unwrap() =
61 Message::Message(String::from("Usage: `loadpage video {id/url}`")); 76 Message::Message(String::from("Usage: `loadpage video {id/url}`"));
62 return; 77 return false;
63 } 78 }
64 79
65 match from_video_url(command[2]) { 80 match from_video_url(command[2]) {
@@ -67,7 +82,7 @@ pub fn run_command(
67 Err(e) => { 82 Err(e) => {
68 *framework.data.global.get_mut::<Message>().unwrap() = 83 *framework.data.global.get_mut::<Message>().unwrap() =
69 Message::Error(e); 84 Message::Error(e);
70 return; 85 return false;
71 } 86 }
72 } 87 }
73 } 88 }
@@ -75,7 +90,7 @@ pub fn run_command(
75 if command.len() == 2 { 90 if command.len() == 2 {
76 *framework.data.global.get_mut::<Message>().unwrap() = 91 *framework.data.global.get_mut::<Message>().unwrap() =
77 Message::Message(String::from("Usage: `loadpage playlist {id/url}`")); 92 Message::Message(String::from("Usage: `loadpage playlist {id/url}`"));
78 return; 93 return false;
79 } 94 }
80 95
81 match from_playlist_url(command[2]) { 96 match from_playlist_url(command[2]) {
@@ -83,7 +98,7 @@ pub fn run_command(
83 Err(e) => { 98 Err(e) => {
84 *framework.data.global.get_mut::<Message>().unwrap() = 99 *framework.data.global.get_mut::<Message>().unwrap() =
85 Message::Error(e); 100 Message::Error(e);
86 return; 101 return false;
87 } 102 }
88 } 103 }
89 } 104 }
@@ -91,7 +106,7 @@ pub fn run_command(
91 if command.len() == 2 { 106 if command.len() == 2 {
92 *framework.data.global.get_mut::<Message>().unwrap() = 107 *framework.data.global.get_mut::<Message>().unwrap() =
93 Message::Message(String::from("Usage: `search {query}`")); 108 Message::Message(String::from("Usage: `search {query}`"));
94 return; 109 return true;
95 } 110 }
96 111
97 // search for a query, although the command is matched as an array, the original query can 112 // search for a query, although the command is matched as an array, the original query can
@@ -117,6 +132,8 @@ pub fn run_command(
117 .priority 132 .priority
118 .push(Task::LoadPage(page)) 133 .push(Task::LoadPage(page))
119 } 134 }
135
136 true
120 } 137 }
121 // redirects to the relevant `loadpage` command 138 // redirects to the relevant `loadpage` command
122 ["popular"] => run_command(&["loadpage", "popular"], framework, terminal), 139 ["popular"] => run_command(&["loadpage", "popular"], framework, terminal),
@@ -142,42 +159,95 @@ pub fn run_command(
142 ["playlist", identifier] => { 159 ["playlist", identifier] => {
143 run_command(&["loadpage", "playlist", *identifier], framework, terminal) 160 run_command(&["loadpage", "playlist", *identifier], framework, terminal)
144 } 161 }
145 ["history"] => { /* help message */ } 162 ["history"] => {
163 *framework.data.global.get_mut::<Message>().unwrap() =
164 Message::Message(String::from("Usage: `history [back/clear]`"));
165 false
166 }
146 ["history", "back"] | ["back"] => { 167 ["history", "back"] | ["back"] => {
147 let _ = framework.revert_last_history(); 168 let _ = framework.revert_last_history();
148 framework.data.state.get_mut::<Tasks>().unwrap().priority.push(Task::ClearPage); 169 framework
149 framework.data.state.get_mut::<Tasks>().unwrap().priority.push(Task::RenderAll); 170 .data
171 .state
172 .get_mut::<Tasks>()
173 .unwrap()
174 .priority
175 .push(Task::ClearPage);
176 framework
177 .data
178 .state
179 .get_mut::<Tasks>()
180 .unwrap()
181 .priority
182 .push(Task::RenderAll);
150 run_command(&["flush"], framework, terminal); 183 run_command(&["flush"], framework, terminal);
151 framework.data.global.get_mut::<Status>().unwrap().render_image = true; 184 framework
152 }, 185 .data
153 ["history", "clear"] => framework.clear_history(), 186 .global
187 .get_mut::<Status>()
188 .unwrap()
189 .render_image = true;
190 false
191 }
192 ["history", "clear"] => {
193 framework.clear_history();
194 false
195 }
154 ["flush"] => loop { 196 ["flush"] => loop {
155 // runs all stacked actions 197 // runs all stacked actions
156 if let Some(tasks) = framework.data.state.get_mut::<Tasks>().unwrap().pop() { 198 if let Some(tasks) = framework.data.state.get_mut::<Tasks>().unwrap().pop() {
157 let _res = tasks.run(framework, terminal); 199 let _res = tasks.run(framework, terminal);
158 continue; 200 continue;
159 } 201 }
160 break; 202 break false;
161 }, 203 },
162 ["reload"] | ["r"] => framework.data.state.get_mut::<Tasks>().unwrap().priority.push(Task::Reload), 204 ["reload"] | ["r"] => {
205 framework
206 .data
207 .state
208 .get_mut::<Tasks>()
209 .unwrap()
210 .priority
211 .push(Task::Reload);
212 false
213 }
163 ["reload", "config"] | ["reload", "configs"] | ["r", "config"] | ["r", "configs"] => { 214 ["reload", "config"] | ["reload", "configs"] | ["r", "config"] | ["r", "configs"] => {
164 *framework.data.global.get_mut::<Message>().unwrap() = 215 *framework.data.global.get_mut::<Message>().unwrap() =
165 match load_configs(&mut framework.split_clean().0) { 216 match load_configs(&mut framework.split_clean().0) {
166 Ok(()) => Message::Success(String::from("Config files have been reloaded")), 217 Ok(()) => Message::Success(String::from("Config files have been reloaded")),
167 Err(e) => Message::Error(e.to_string()), 218 Err(e) => Message::Error(e.to_string()),
168 } 219 };
220 false
169 } 221 }
170 ["q"] | ["quit"] | ["x"] | ["exit"] => { 222 ["q"] | ["quit"] | ["x"] | ["exit"] => {
171 framework.data.global.get_mut::<Status>().unwrap().exit = true; 223 framework.data.global.get_mut::<Status>().unwrap().exit = true;
224 false
172 } 225 }
173 ["hello", "world"] => { 226 ["hello", "world"] => {
174 let index = fake_rand_range(0, HELLO_WORLDS.len() as i64) as usize; 227 let index = fake_rand_range(0, HELLO_WORLDS.len() as i64) as usize;
175 *framework.data.global.get_mut::<Message>().unwrap() = 228 *framework.data.global.get_mut::<Message>().unwrap() =
176 Message::Message(format!("Line #{index}: {}", HELLO_WORLDS[index])); 229 Message::Message(format!("Line #{index}: {}", HELLO_WORLDS[index]));
230 false
231 }
232 ["version"] | ["v"] => {
233 *framework.data.global.get_mut::<Message>().unwrap() = Message::Message(format!(
234 "{} {}",
235 env!("CARGO_PKG_NAME"),
236 env!("CARGO_PKG_VERSION")
237 ));
238 false
239 }
240 ["run", ..] => {
241 let mut command = execute::command(&command[1..].join(" "));
242 thread::spawn(move || {
243 let _ = command.output();
244 });
245 false
177 } 246 }
178 _ => { 247 _ => {
179 *framework.data.global.get_mut::<Message>().unwrap() = 248 *framework.data.global.get_mut::<Message>().unwrap() =
180 Message::Error(format!("Unknown command: `{}`", command.join(" "))) 249 Message::Error(format!("Unknown command: `{}`", command.join(" ")));
250 false
181 } 251 }
182 } 252 }
183} 253}
@@ -212,3 +282,45 @@ const HELLO_WORLDS: &[&str] = &[
212 "print *, \"Hello World\"", 282 "print *, \"Hello World\"",
213 "<h1>Hello World<\\h1>", 283 "<h1>Hello World<\\h1>",
214]; 284];
285
286const HELP_MSG: &str = "\x1b[32mYouTube TUI commands\x1b[0m
287
288\x1b[37mfor more visit https://siriusmart.github.io/youtube-tui/commands.html\x1b[0m
289
290\x1b[91mUSAGE:\x1b[0m
291 youtube-tui (command)
292
293\x1b[91mINFORMATIONAL:\x1b[0m
294 \x1b[33mhelp\x1b[0m Display this message
295 \x1b[33mversion\x1b[0m Print version info and exit
296
297\x1b[91mLOADPAGE:
298\x1b[37mloadpage [page] loads the corresponding page\x1b[0m
299 \x1b[33mloadpage popular\x1b[0m Loads the popular videos page
300 \x1b[33mloadpage trending\x1b[0m Loads the trending videos page
301 \x1b[33mloadpage watchhistory\x1b[0m Loads the watch history page
302 \x1b[33mloadpage search [query]\x1b[0m Loads the search page with the given query
303 \x1b[33mloadpage video [identifier]\x1b[0m Loads the video item page
304 \x1b[33mloadpage playlist [identifier]\x1b[0m Loads the playlist item page
305 \x1b[33mloadpage channel [identifier]\x1b[0m Loads the channel item page
306
307\x1b[91mHISTORY:\x1b[0m
308 \x1b[33mhistory back\x1b[0m Revert back to previous state
309 \x1b[33mhistory clear\x1b[0m Clear all previously saved states, making the current state the original
310
311\x1b[91mUTILITY:\x1b[0m
312 \x1b[33mreload\x1b[0m Reloads the current page
313 \x1b[33mreload configs\x1b[0m Reload all config files
314 \x1b[33mflush\x1b[0m Run all tasks in queue immediately
315 \x1b[33mquit\x1b[0m Immediately exit
316
317\x1b[91mALT:\x1b[0m
318\x1b[37malts links back to the original command\x1b[30m
319
320 \x1b[33m[page] (additional options)\x1b[0m `loadpage [page]`
321 \x1b[33mback\x1b[0m `history back`
322 \x1b[33mr\x1b[0m `reload`
323 \x1b[33mreload/r config/configs\x1b[0m `reload configs`
324 \x1b[33mq, exit, x\x1b[0m `quit`
325
326\x1b[37mOnly load page commands and informational commands can be used from command line, the rest can only be used in (`:`) command mode inside the TUI.\x1b[0m";
src/global/functions/type_name_of_val.rs deleted −5
@@ -1,5 +0,0 @@
1use std::any::type_name;
2
3pub fn type_name_of_val<T: ?Sized>(_val: &T) -> &'static str {
4 type_name::<T>()
5}
src/global/structs/item.rs +26 −3
@@ -28,6 +28,7 @@ pub enum Item {
28 Unknown(SearchItemTransition), 28 Unknown(SearchItemTransition),
29} 29}
30 30
31/// stores information of a previewed video
31#[derive(Clone, Serialize, Deserialize)] 32#[derive(Clone, Serialize, Deserialize)]
32pub struct MiniVideoItem { 33pub struct MiniVideoItem {
33 pub title: String, 34 pub title: String,
@@ -41,6 +42,7 @@ pub struct MiniVideoItem {
41 pub description: Option<String>, 42 pub description: Option<String>,
42} 43}
43 44
45/// stores information of a previewed playlist
44#[derive(Clone, Serialize, Deserialize)] 46#[derive(Clone, Serialize, Deserialize)]
45pub struct MiniPlaylistItem { 47pub struct MiniPlaylistItem {
46 pub title: String, 48 pub title: String,
@@ -51,6 +53,7 @@ pub struct MiniPlaylistItem {
51 pub thumbnail_url: String, 53 pub thumbnail_url: String,
52} 54}
53 55
56/// stores information of a previewed channel
54#[derive(Clone, Serialize, Deserialize)] 57#[derive(Clone, Serialize, Deserialize)]
55pub struct MiniChannelItem { 58pub struct MiniChannelItem {
56 pub name: String, 59 pub name: String,
@@ -62,6 +65,7 @@ pub struct MiniChannelItem {
62 pub description: String, 65 pub description: String,
63} 66}
64 67
68/// stores information of a viewed video
65#[derive(Clone, Serialize, Deserialize)] 69#[derive(Clone, Serialize, Deserialize)]
66pub struct FullVideoItem { 70pub struct FullVideoItem {
67 pub title: String, 71 pub title: String,
@@ -79,6 +83,7 @@ pub struct FullVideoItem {
79 pub genre: String, 83 pub genre: String,
80} 84}
81 85
86/// stores information of a viewed playlist
82#[derive(Clone, Serialize, Deserialize)] 87#[derive(Clone, Serialize, Deserialize)]
83pub struct FullPlaylistItem { 88pub struct FullPlaylistItem {
84 pub title: String, 89 pub title: String,
@@ -92,6 +97,7 @@ pub struct FullPlaylistItem {
92 pub videos: Vec<Item>, 97 pub videos: Vec<Item>,
93} 98}
94 99
100/// stores information of a viewed channel
95#[derive(Clone, Serialize, Deserialize)] 101#[derive(Clone, Serialize, Deserialize)]
96pub struct FullChannelItem { 102pub struct FullChannelItem {
97 pub name: String, 103 pub name: String,
@@ -127,6 +133,7 @@ impl Display for Item {
127} 133}
128 134
129impl Item { 135impl Item {
136 /// returns the id of an item, `None` is self is Unknown
130 pub fn id(&self) -> Option<&str> { 137 pub fn id(&self) -> Option<&str> {
131 match self { 138 match self {
132 Self::MiniVideo(MiniVideoItem { id, .. }) 139 Self::MiniVideo(MiniVideoItem { id, .. })
@@ -135,16 +142,18 @@ impl Item {
135 | Self::FullVideo(FullVideoItem { id, .. }) 142 | Self::FullVideo(FullVideoItem { id, .. })
136 | Self::FullChannel(FullChannelItem { id, .. }) 143 | Self::FullChannel(FullChannelItem { id, .. })
137 | Self::FullPlaylist(FullPlaylistItem { id, .. }) => Some(id), 144 | Self::FullPlaylist(FullPlaylistItem { id, .. }) => Some(id),
138 _ => None, 145 Self::Unknown(_) | Self::Page(_) => None,
139 } 146 }
140 } 147 }
141 148
149 /// check if self is Self::Unknown
142 pub fn is_unknown(&self) -> bool { 150 pub fn is_unknown(&self) -> bool {
143 matches!(self, Self::Unknown(_)) 151 matches!(self, Self::Unknown(_))
144 } 152 }
145} 153}
146 154
147impl Item { 155impl Item {
156 /// stript self into a FullVideoItem
148 pub fn fullvideo(&self) -> Result<&FullVideoItem, Errors> { 157 pub fn fullvideo(&self) -> Result<&FullVideoItem, Errors> {
149 match self { 158 match self {
150 Self::FullVideo(fullvideo) => Ok(fullvideo), 159 Self::FullVideo(fullvideo) => Ok(fullvideo),
@@ -152,6 +161,7 @@ impl Item {
152 } 161 }
153 } 162 }
154 163
164 /// stript self into a MiniVideoItem
155 pub fn minivideo(&self) -> Result<&MiniVideoItem, Errors> { 165 pub fn minivideo(&self) -> Result<&MiniVideoItem, Errors> {
156 match self { 166 match self {
157 Self::MiniVideo(minivideo) => Ok(minivideo), 167 Self::MiniVideo(minivideo) => Ok(minivideo),
@@ -159,6 +169,7 @@ impl Item {
159 } 169 }
160 } 170 }
161 171
172 /// stript self into a MiniPlaylistItem
162 pub fn miniplaylist(&self) -> Result<&MiniPlaylistItem, Errors> { 173 pub fn miniplaylist(&self) -> Result<&MiniPlaylistItem, Errors> {
163 match self { 174 match self {
164 Self::MiniPlaylist(miniplaylist) => Ok(miniplaylist), 175 Self::MiniPlaylist(miniplaylist) => Ok(miniplaylist),
@@ -166,6 +177,7 @@ impl Item {
166 } 177 }
167 } 178 }
168 179
180 /// stript self into a FullPlaylistItem
169 pub fn fullplaylist(&self) -> Result<&FullPlaylistItem, Errors> { 181 pub fn fullplaylist(&self) -> Result<&FullPlaylistItem, Errors> {
170 match self { 182 match self {
171 Self::FullPlaylist(fullplaylist) => Ok(fullplaylist), 183 Self::FullPlaylist(fullplaylist) => Ok(fullplaylist),
@@ -173,6 +185,7 @@ impl Item {
173 } 185 }
174 } 186 }
175 187
188 /// stript self into a MiniChannelItem
176 pub fn minichannel(&self) -> Result<&MiniChannelItem, Errors> { 189 pub fn minichannel(&self) -> Result<&MiniChannelItem, Errors> {
177 match self { 190 match self {
178 Self::MiniChannel(minichannel) => Ok(minichannel), 191 Self::MiniChannel(minichannel) => Ok(minichannel),
@@ -182,7 +195,8 @@ impl Item {
182} 195}
183 196
184impl Item { 197impl Item {
185 // the file save path for thumbnails (which is by their id) 198 /// returns the file save path for thumbnails (which is by their id)
199 /// returns `invalid` if the item does not have a thumbnail
186 pub fn thumbnail_id(&self) -> &str { 200 pub fn thumbnail_id(&self) -> &str {
187 match self { 201 match self {
188 Self::MiniVideo(video) => &video.id, 202 Self::MiniVideo(video) => &video.id,
@@ -195,7 +209,7 @@ impl Item {
195 } 209 }
196 } 210 }
197 211
198 // cannot impl From<T> because it also need `image_index` 212 /// parse `TrendingVideo` into `Self`
199 pub fn from_trending_video(original: TrendingVideo, image_index: usize) -> Self { 213 pub fn from_trending_video(original: TrendingVideo, image_index: usize) -> Self {
200 Self::MiniVideo(MiniVideoItem { 214 Self::MiniVideo(MiniVideoItem {
201 title: original.title, 215 title: original.title,
@@ -214,6 +228,7 @@ impl Item {
214 }) 228 })
215 } 229 }
216 230
231 /// parse `PopularItem` into `Self`
217 pub fn from_popular_item(original: PopularItem, image_index: usize) -> Self { 232 pub fn from_popular_item(original: PopularItem, image_index: usize) -> Self {
218 Self::MiniVideo(MiniVideoItem { 233 Self::MiniVideo(MiniVideoItem {
219 title: original.title, 234 title: original.title,
@@ -232,6 +247,7 @@ impl Item {
232 }) 247 })
233 } 248 }
234 249
250 /// parse `Playlist` into `Self`
235 pub fn from_mini_playlist(original: Playlist) -> Self { 251 pub fn from_mini_playlist(original: Playlist) -> Self {
236 Self::MiniPlaylist(MiniPlaylistItem { 252 Self::MiniPlaylist(MiniPlaylistItem {
237 title: original.title, 253 title: original.title,
@@ -243,6 +259,7 @@ impl Item {
243 }) 259 })
244 } 260 }
245 261
262 /// parse `SearchItem` into `Self`
246 pub fn from_search_item(original: SearchItem, image_index: usize) -> Self { 263 pub fn from_search_item(original: SearchItem, image_index: usize) -> Self {
247 match original { 264 match original {
248 SearchItem::Video { 265 SearchItem::Video {
@@ -305,6 +322,7 @@ impl Item {
305 } 322 }
306 } 323 }
307 324
325 /// parse `Video` into `Self`
308 pub fn from_full_video(original: Video, image_index: usize) -> Self { 326 pub fn from_full_video(original: Video, image_index: usize) -> Self {
309 Self::FullVideo(FullVideoItem { 327 Self::FullVideo(FullVideoItem {
310 title: original.title, 328 title: original.title,
@@ -326,6 +344,7 @@ impl Item {
326 }) 344 })
327 } 345 }
328 346
347 /// parse `FullPlaylist` into `Self`
329 pub fn from_full_playlist(original: FullPlaylist, image_index: usize) -> Self { 348 pub fn from_full_playlist(original: FullPlaylist, image_index: usize) -> Self {
330 Self::FullPlaylist(FullPlaylistItem { 349 Self::FullPlaylist(FullPlaylistItem {
331 title: original.title, 350 title: original.title,
@@ -344,6 +363,7 @@ impl Item {
344 }) 363 })
345 } 364 }
346 365
366 /// parse `PlaylistItem` into `Self`
347 pub fn from_playlist_item(original: PlaylistItem, image_index: usize) -> Self { 367 pub fn from_playlist_item(original: PlaylistItem, image_index: usize) -> Self {
348 Self::MiniVideo(MiniVideoItem { 368 Self::MiniVideo(MiniVideoItem {
349 title: original.title, 369 title: original.title,
@@ -358,6 +378,7 @@ impl Item {
358 }) 378 })
359 } 379 }
360 380
381 /// parse `Channel` into `Self`
361 pub fn from_full_channel(original: Channel, image_index: usize) -> Self { 382 pub fn from_full_channel(original: Channel, image_index: usize) -> Self {
362 Self::FullChannel(FullChannelItem { 383 Self::FullChannel(FullChannelItem {
363 name: original.name, 384 name: original.name,
@@ -372,6 +393,7 @@ impl Item {
372 }) 393 })
373 } 394 }
374 395
396 /// parse `ChannelVideo` into `Self`
375 pub fn from_channel_video(original: ChannelVideo, image_index: usize) -> Self { 397 pub fn from_channel_video(original: ChannelVideo, image_index: usize) -> Self {
376 Self::MiniVideo(MiniVideoItem { 398 Self::MiniVideo(MiniVideoItem {
377 title: original.title, 399 title: original.title,
@@ -390,6 +412,7 @@ impl Item {
390 }) 412 })
391 } 413 }
392 414
415 /// parse `Playlist` into `Self`
393 pub fn from_channel_playlist(original: Playlist) -> Self { 416 pub fn from_channel_playlist(original: Playlist) -> Self {
394 Self::MiniPlaylist(MiniPlaylistItem { 417 Self::MiniPlaylist(MiniPlaylistItem {
395 title: original.title, 418 title: original.title,
src/global/structs/keyaction.rs −2
@@ -28,8 +28,6 @@ pub enum KeyAction {
28 Reload, 28 Reload,
29 /// start command capture 29 /// start command capture
30 StartCommandCapture, 30 StartCommandCapture,
31 /// copy text
32 r#Copy,
33 /// paste text 31 /// paste text
34 Paste, 32 Paste,
35} 33}
src/global/structs/mod.rs +2
@@ -5,6 +5,7 @@ mod item;
5mod keyaction; 5mod keyaction;
6mod message; 6mod message;
7mod page; 7mod page;
8mod state_env;
8mod status; 9mod status;
9mod tasks; 10mod tasks;
10mod watchhistory; 11mod watchhistory;
@@ -15,6 +16,7 @@ pub use item::*;
15pub use keyaction::*; 16pub use keyaction::*;
16pub use message::*; 17pub use message::*;
17pub use page::*; 18pub use page::*;
19pub use state_env::*;
18pub use status::*; 20pub use status::*;
19pub use tasks::*; 21pub use tasks::*;
20pub use watchhistory::*; 22pub use watchhistory::*;
src/global/structs/status.rs +2
@@ -5,7 +5,9 @@ use typemap::Key;
5/// a struct for storing different info, currently only stores one info 5/// a struct for storing different info, currently only stores one info
6#[derive(Clone)] 6#[derive(Clone)]
7pub struct Status { 7pub struct Status {
8 /// is there is a popup opened
8 pub popup_opened: bool, 9 pub popup_opened: bool,
10 /// is search filter popup opened
9 pub search_filter_opened: bool, 11 pub search_filter_opened: bool,
10 /// to prevent rerendering the same image 12 /// to prevent rerendering the same image
11 pub render_image: bool, 13 pub render_image: bool,
src/global/structs/tasks.rs +38 −8
@@ -1,9 +1,9 @@
1use crate::{ 1use crate::{
2 config::{AppearanceConfig, MinDimentions}, 2 config::{AppearanceConfig, MainConfig, MinDimentions},
3 global::functions::run_command, 3 global::functions::{clear_envs, run_command, set_envs},
4}; 4};
5 5
6use super::{message::Message, page::Page, status::Status}; 6use super::{message::Message, page::Page, status::Status, StateEnvs};
7use std::{error::Error, io::Stdout, mem}; 7use std::{error::Error, io::Stdout, mem};
8use tui::{ 8use tui::{
9 backend::CrosstermBackend, layout::Alignment, style::Style, widgets::Paragraph, Frame, Terminal, 9 backend::CrosstermBackend, layout::Alignment, style::Style, widgets::Paragraph, Frame, Terminal,
@@ -48,7 +48,7 @@ impl Default for TaskQueue {
48} 48}
49 49
50impl TaskQueue { 50impl TaskQueue {
51 // add task to queue 51 /// add task to queue
52 pub fn push(&mut self, task: Task) { 52 pub fn push(&mut self, task: Task) {
53 match task { 53 match task {
54 Task::RenderAll => self.render = RenderTask::All, 54 Task::RenderAll => self.render = RenderTask::All,
@@ -67,7 +67,6 @@ impl TaskQueue {
67 Task::ClearPage => self.clear_all = true, 67 Task::ClearPage => self.clear_all = true,
68 Task::LazyRendered => self.lazy_rendered = true, 68 Task::LazyRendered => self.lazy_rendered = true,
69 Task::Command(s) => self.commands.push(s), 69 Task::Command(s) => self.commands.push(s),
70 // _ => {}
71 } 70 }
72 } 71 }
73 72
@@ -75,7 +74,7 @@ impl TaskQueue {
75 self == &Self::default() 74 self == &Self::default()
76 } 75 }
77 76
78 // runs all tasks in a task queue 77 /// runs all tasks in a task queue
79 pub fn run( 78 pub fn run(
80 self, 79 self,
81 framework: &mut Framework, 80 framework: &mut Framework,
@@ -109,6 +108,22 @@ impl TaskQueue {
109 *framework.data.global.get_mut::<Message>().unwrap() = 108 *framework.data.global.get_mut::<Message>().unwrap() =
110 Message::Message(page.load_msg(framework)); 109 Message::Message(page.load_msg(framework));
111 framework.push_history(); 110 framework.push_history();
111
112 // clear all envs modified by the previous state (keeping ones that are there when the
113 // program launches), then add the envs set in main config
114 clear_envs(&mut framework.data.state.get_mut::<StateEnvs>().unwrap().0);
115 set_envs(
116 framework
117 .data
118 .global
119 .get::<MainConfig>()
120 .unwrap()
121 .env
122 .clone()
123 .into_iter(),
124 &mut framework.data.state.get_mut::<StateEnvs>().unwrap().0,
125 );
126 // reset cursor position
112 framework.cursor = CursorState::default(); 127 framework.cursor = CursorState::default();
113 128
114 let page_config = page.to_page_config(framework); 129 let page_config = page.to_page_config(framework);
@@ -132,6 +147,20 @@ impl TaskQueue {
132 } 147 }
133 148
134 if self.reload { 149 if self.reload {
150 // same as in loadpage
151 clear_envs(&mut framework.data.state.get_mut::<StateEnvs>().unwrap().0);
152 set_envs(
153 framework
154 .data
155 .global
156 .get::<MainConfig>()
157 .unwrap()
158 .env
159 .clone()
160 .into_iter(),
161 &mut framework.data.state.get_mut::<StateEnvs>().unwrap().0,
162 );
163
135 // reload simply runs `.load()` on all items 164 // reload simply runs `.load()` on all items
136 *framework.data.global.get_mut::<Message>().unwrap() = 165 *framework.data.global.get_mut::<Message>().unwrap() =
137 Message::Message(String::from("Reloading page...")); 166 Message::Message(String::from("Reloading page..."));
@@ -159,7 +188,7 @@ impl TaskQueue {
159 Ok(()) 188 Ok(())
160 } 189 }
161 190
162 // the render task runs this function 191 /// the render task runs this function
163 pub fn render( 192 pub fn render(
164 framework: &mut Framework, 193 framework: &mut Framework,
165 terminal: &mut Terminal<CrosstermBackend<Stdout>>, 194 terminal: &mut Terminal<CrosstermBackend<Stdout>>,
@@ -171,7 +200,7 @@ impl TaskQueue {
171 Ok(()) 200 Ok(())
172 } 201 }
173 202
174 // this function force clears the terminal before rendering, removing sixels and halfblock images 203 /// this function force clears the terminal before rendering, removing sixels and halfblock images
175 pub fn render_force_clear( 204 pub fn render_force_clear(
176 framework: &mut Framework, 205 framework: &mut Framework,
177 terminal: &mut Terminal<CrosstermBackend<Stdout>>, 206 terminal: &mut Terminal<CrosstermBackend<Stdout>>,
@@ -184,6 +213,7 @@ impl TaskQueue {
184 Ok(()) 213 Ok(())
185 } 214 }
186 215
216 /// this function renders onto the given frame
187 pub fn render_with_frame( 217 pub fn render_with_frame(
188 framework: &mut Framework, 218 framework: &mut Framework,
189 frame: &mut Frame<CrosstermBackend<Stdout>>, 219 frame: &mut Frame<CrosstermBackend<Stdout>>,
src/global/traits/asurlstring.rs +1 −1
@@ -1,4 +1,4 @@
1/// A single URL param 1/// A single URL param for search filters
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/init.rs +10 −5
@@ -5,9 +5,9 @@ use crate::{
5 }, 5 },
6 global::{ 6 global::{
7 functions::run_command, 7 functions::run_command,
8 structs::{InvidiousClient, Message, Page, Status, Tasks, WatchHistory}, 8 structs::{InvidiousClient, Message, Page, StateEnvs, Status, Tasks, WatchHistory},
9 traits::ConfigTrait, 9 traits::ConfigTrait,
10 }, egg, 10 },
11}; 11};
12use home::home_dir; 12use home::home_dir;
13use std::{error::Error, fs, io::Stdout}; 13use std::{error::Error, fs, io::Stdout};
@@ -22,6 +22,7 @@ use tui_additions::framework::{Framework, FrameworkClean};
22pub fn init( 22pub fn init(
23 framework: &mut Framework, 23 framework: &mut Framework,
24 terminal: &mut Terminal<CrosstermBackend<Stdout>>, 24 terminal: &mut Terminal<CrosstermBackend<Stdout>>,
25 command: &[&str],
25) -> Result<(), Box<dyn Error>> { 26) -> Result<(), Box<dyn Error>> {
26 // creating files 27 // creating files
27 let home_dir = home_dir().unwrap(); 28 let home_dir = home_dir().unwrap();
@@ -52,7 +53,9 @@ pub fn init(
52 53
53 load_configs(&mut framework.split_clean().0).ok(); 54 load_configs(&mut framework.split_clean().0).ok();
54 55
55 run_command(&["loadpage", "popular"], framework, terminal); 56 if !run_command(command, framework, terminal) {
57 run_command(&["loadpage", "popular"], framework, terminal);
58 }
56 run_command(&["flush"], framework, terminal); 59 run_command(&["flush"], framework, terminal);
57 run_command(&["history", "clear"], framework, terminal); 60 run_command(&["history", "clear"], framework, terminal);
58 Ok(()) 61 Ok(())
@@ -95,8 +98,10 @@ pub fn load_configs(framework: &mut FrameworkClean) -> Result<(), Box<dyn Error>
95 .global 98 .global
96 .insert::<KeyBindingsConfig>(KeyBindingsConfig::load()?); 99 .insert::<KeyBindingsConfig>(KeyBindingsConfig::load()?);
97 framework.data.state.insert::<Search>(*Search::load()?); 100 framework.data.state.insert::<Search>(*Search::load()?);
98 101 framework
99 egg(); 102 .data
103 .state
104 .insert::<StateEnvs>(StateEnvs::default());
100 105
101 Ok(()) 106 Ok(())
102} 107}
src/items/channeldisplay.rs +9
@@ -22,17 +22,21 @@ use tui_additions::{
22/// the 4 pages that a channel has (including the default "blank" page when loading) 22/// the 4 pages that a channel has (including the default "blank" page when loading)
23#[derive(Clone)] 23#[derive(Clone)]
24pub enum ChannelDisplay { 24pub enum ChannelDisplay {
25 /// a blank item, will turn into one of the other variants when `.load()` depending on the page
25 None, 26 None,
27 /// main channel display page
26 Main { 28 Main {
27 channel: Item, 29 channel: Item,
28 iteminfo: ItemInfo, 30 iteminfo: ItemInfo,
29 }, 31 },
32 /// latest videos
30 Videos { 33 Videos {
31 videos: Vec<Item>, 34 videos: Vec<Item>,
32 textlist: TextList, 35 textlist: TextList,
33 iteminfo: ItemInfo, 36 iteminfo: ItemInfo,
34 grid: Grid, 37 grid: Grid,
35 }, 38 },
39 /// created playlists
36 Playlists { 40 Playlists {
37 playlists: Vec<Item>, 41 playlists: Vec<Item>,
38 textlist: TextList, 42 textlist: TextList,
@@ -48,6 +52,7 @@ impl Default for ChannelDisplay {
48} 52}
49 53
50impl ChannelDisplay { 54impl ChannelDisplay {
55 /// update the style of the item (colours, etc), ran on ever render
51 fn update_appearance( 56 fn update_appearance(
52 &mut self, 57 &mut self,
53 info: &tui_additions::framework::ItemInfo, 58 info: &tui_additions::framework::ItemInfo,
@@ -95,6 +100,8 @@ impl ChannelDisplay {
95 } 100 }
96 } 101 }
97 102
103 /// handles when select (enter) is pressed, generally loads the hovered item in a
104 /// `SingleItemPage`
98 fn select_at_cursor(&self, framework: &mut FrameworkClean) { 105 fn select_at_cursor(&self, framework: &mut FrameworkClean) {
99 match self { 106 match self {
100 Self::None | Self::Main { .. } => {} 107 Self::None | Self::Main { .. } => {}
@@ -144,6 +151,7 @@ impl ChannelDisplay {
144 } 151 }
145 } 152 }
146 153
154 /// updates the video/playlist preview
147 fn update(&mut self) { 155 fn update(&mut self) {
148 match self { 156 match self {
149 Self::Videos { 157 Self::Videos {
@@ -168,6 +176,7 @@ impl ChannelDisplay {
168 } 176 }
169 } 177 }
170 178
179 /// check if self should be able to be selected
171 pub fn selectable(&self) -> bool { 180 pub fn selectable(&self) -> bool {
172 !(matches!(self, Self::Main { .. }) || matches!(self, Self::None)) 181 !(matches!(self, Self::Main { .. }) || matches!(self, Self::None))
173 } 182 }
src/items/iteminfo.rs −1
@@ -74,7 +74,6 @@ impl FrameworkItem for ItemInfo {
74 } as u32), 74 } as u32),
75 x: area.x, 75 x: area.x,
76 y: area.y as i16, 76 y: area.y as i16,
77 #[cfg(feature = "sixel")]
78 use_sixel: main_config.images.use_sixels(), 77 use_sixel: main_config.images.use_sixels(),
79 ..Default::default() 78 ..Default::default()
80 }; 79 };
src/items/itemlist.rs +1
@@ -69,6 +69,7 @@ impl ItemList {
69 } 69 }
70 } 70 }
71 71
72 /// handles select (enter)
72 fn select_at_cursor(&self, framework: &mut FrameworkClean) { 73 fn select_at_cursor(&self, framework: &mut FrameworkClean) {
73 let page_to_load = match &self.items[self.textlist.selected] { 74 let page_to_load = match &self.items[self.textlist.selected] {
74 Item::MiniVideo(MiniVideoItem { id, .. }) 75 Item::MiniVideo(MiniVideoItem { id, .. })
src/items/singleitem.rs +60 −72
@@ -2,14 +2,14 @@ use super::ItemInfo;
2use crate::{ 2use crate::{
3 config::{AppearanceConfig, CommandsConfig, KeyBindingsConfig, MainConfig, Provider}, 3 config::{AppearanceConfig, CommandsConfig, KeyBindingsConfig, MainConfig, Provider},
4 global::{ 4 global::{
5 functions::download_all_images, 5 functions::{apply_envs, download_all_images, set_envs},
6 structs::{ 6 structs::{
7 InvidiousClient, Item, KeyAction, Message, Page, SingleItemPage, Status, Task, Tasks, 7 InvidiousClient, Item, KeyAction, Message, Page, SingleItemPage, StateEnvs, Status,
8 WatchHistory, 8 Task, Tasks, WatchHistory,
9 }, 9 },
10 }, 10 },
11}; 11};
12use std::{collections::HashMap, thread}; 12use std::thread;
13use tui::{ 13use tui::{
14 layout::{Constraint, Rect}, 14 layout::{Constraint, Rect},
15 style::Style, 15 style::Style,
@@ -126,10 +126,10 @@ impl SingleVideoItem {
126 } 126 }
127 127
128 /// creates a hashmap from `self`, containing info of the current item 128 /// creates a hashmap from `self`, containing info of the current item
129 pub fn inflate_map(&self, mainconfig: &MainConfig, item: &Item) -> HashMap<String, String> { 129 pub fn inflate(&self, mainconfig: &MainConfig, item: &Item) -> Vec<(String, String)> {
130 let video_item = item.fullvideo().unwrap(); 130 let video_item = item.fullvideo().unwrap();
131 131
132 HashMap::from([ 132 vec![
133 ( 133 (
134 String::from("url"), 134 String::from("url"),
135 match self.provider { 135 match self.provider {
@@ -151,9 +151,9 @@ impl SingleVideoItem {
151 Provider::YouTube => format!("'https://youtube.com/embed/{}'", video_item.id), 151 Provider::YouTube => format!("'https://youtube.com/embed/{}'", video_item.id),
152 }, 152 },
153 ), 153 ),
154 (String::from("channel_id"), video_item.channel_id.clone()), 154 (String::from("channel-id"), video_item.channel_id.clone()),
155 ( 155 (
156 String::from("channel_url"), 156 String::from("channel-url"),
157 match self.provider { 157 match self.provider {
158 Provider::YouTube => { 158 Provider::YouTube => {
159 format!("https://www.youtube.com/channel/{}", video_item.channel_id) 159 format!("https://www.youtube.com/channel/{}", video_item.channel_id)
@@ -164,18 +164,7 @@ impl SingleVideoItem {
164 ), 164 ),
165 }, 165 },
166 ), 166 ),
167 ]) 167 ]
168 }
169
170 /// add "env variables" from `self.inflate_map` to an existing hashmap
171 pub fn inflate(
172 &self,
173 mut env: HashMap<String, String>,
174 mainconfig: &MainConfig,
175 item: &Item,
176 ) -> HashMap<String, String> {
177 env.extend(self.inflate_map(mainconfig, item));
178 env
179 } 168 }
180} 169}
181 170
@@ -288,9 +277,9 @@ impl SinglePlaylistItem {
288 } 277 }
289 278
290 /// creates a hashmap from `self`, containing info of the current item 279 /// creates a hashmap from `self`, containing info of the current item
291 pub fn inflate_map(&self, mainconfig: &MainConfig, item: &Item) -> HashMap<String, String> { 280 pub fn inflate(&self, mainconfig: &MainConfig, item: &Item) -> Vec<(String, String)> {
292 let playlist_item = item.fullplaylist().unwrap(); 281 let playlist_item = item.fullplaylist().unwrap();
293 HashMap::from([ 282 vec![
294 ( 283 (
295 String::from("url"), 284 String::from("url"),
296 match self.provider { 285 match self.provider {
@@ -329,9 +318,9 @@ impl SinglePlaylistItem {
329 .join(" "), 318 .join(" "),
330 }, 319 },
331 ), 320 ),
332 (String::from("channel_id"), playlist_item.channel_id.clone()), 321 (String::from("channel-id"), playlist_item.channel_id.clone()),
333 ( 322 (
334 String::from("channel_url"), 323 String::from("channel-url"),
335 match self.provider { 324 match self.provider {
336 Provider::YouTube => format!( 325 Provider::YouTube => format!(
337 "https://www.youtube.com/channel/{}", 326 "https://www.youtube.com/channel/{}",
@@ -343,18 +332,7 @@ impl SinglePlaylistItem {
343 ), 332 ),
344 }, 333 },
345 ), 334 ),
346 ]) 335 ]
347 }
348
349 /// add "env variables" from `self.inflate_map` to an existing hashmap
350 pub fn inflate(
351 &self,
352 mut env: HashMap<String, String>,
353 mainconfig: &MainConfig,
354 item: &Item,
355 ) -> HashMap<String, String> {
356 env.extend(self.inflate_map(mainconfig, item));
357 env
358 } 336 }
359} 337}
360 338
@@ -377,6 +355,20 @@ impl SingleItemType {
377 Self::Video(videoitem) => videoitem.update_appearance(appearance, iteminfo), 355 Self::Video(videoitem) => videoitem.update_appearance(appearance, iteminfo),
378 } 356 }
379 } 357 }
358
359 pub fn inflate(&self, mainconfig: &MainConfig, item: &Option<Item>) -> Vec<(String, String)> {
360 let item = if let Some(item) = item.as_ref() {
361 item
362 } else {
363 return Vec::new();
364 };
365
366 match self {
367 Self::Video(singlevideoitem) => singlevideoitem.inflate(mainconfig, item),
368 Self::Playlist(singleplaylistitem) => singleplaylistitem.inflate(mainconfig, item),
369 Self::None => Vec::new(),
370 }
371 }
380} 372}
381 373
382impl SingleItem { 374impl SingleItem {
@@ -448,14 +440,8 @@ impl SingleItem {
448 ); 440 );
449 } 441 }
450 _ => { 442 _ => {
451 let mainconfig = framework.data.global.get::<MainConfig>().unwrap();
452 // joins the env from the one in mainconfig and video info 443 // joins the env from the one in mainconfig and video info
453 let env = singlevideoitem.inflate( 444 let command_string = apply_envs(command_string);
454 mainconfig.env.clone(),
455 mainconfig,
456 self.item.as_ref().unwrap(),
457 );
458 let command_string = apply_env(command_string, &env);
459 445
460 // check if the command starts with an ':' which case should be captured 446 // check if the command starts with an ':' which case should be captured
461 if &command_string[0..1] == ":" { 447 if &command_string[0..1] == ":" {
@@ -468,12 +454,13 @@ impl SingleItem {
468 .push(Task::Command(command_string[1..].to_string())) 454 .push(Task::Command(command_string[1..].to_string()))
469 } 455 }
470 456
471 *framework.data.global.get_mut::<Message>().unwrap() =
472 Message::Success(command_string.clone());
473
474 // this allows creating commands from string 457 // this allows creating commands from string
475 let mut command = execute::command(command_string); 458 let mut command = execute::command(command_string);
476 459
460 *framework.data.global.get_mut::<Message>().unwrap() = Message::Success(
461 format!("{:?} {:?}", command.get_program(), command.get_args()),
462 );
463
477 // run the command in a new thread so it doesn't freeze the current one 464 // run the command in a new thread so it doesn't freeze the current one
478 thread::spawn(move || { 465 thread::spawn(move || {
479 let _ = command.output(); 466 let _ = command.output();
@@ -504,13 +491,7 @@ impl SingleItem {
504 } 491 }
505 // same as before if string is not a special case then the run the command 492 // same as before if string is not a special case then the run the command
506 _ => { 493 _ => {
507 let mainconfig = framework.data.global.get::<MainConfig>().unwrap(); 494 let command_string = apply_envs(command_string);
508 let env = singleplaylistitem.inflate(
509 mainconfig.env.clone(),
510 mainconfig,
511 self.item.as_ref().unwrap(),
512 );
513 let command_string = apply_env(command_string, &env);
514 495
515 // check if the command starts with an ':' which case should be captured 496 // check if the command starts with an ':' which case should be captured
516 if &command_string[0..1] == ":" { 497 if &command_string[0..1] == ":" {
@@ -525,6 +506,7 @@ impl SingleItem {
525 506
526 *framework.data.global.get_mut::<Message>().unwrap() = 507 *framework.data.global.get_mut::<Message>().unwrap() =
527 Message::Success(command_string.clone()); 508 Message::Success(command_string.clone());
509
528 let mut command = execute::command(command_string); 510 let mut command = execute::command(command_string);
529 511
530 thread::spawn(move || { 512 thread::spawn(move || {
@@ -633,8 +615,8 @@ impl FrameworkItem for SingleItem {
633 }; 615 };
634 616
635 let client = &framework.data.global.get::<InvidiousClient>().unwrap().0; 617 let client = &framework.data.global.get::<InvidiousClient>().unwrap().0;
636 let mainconfig = framework.data.global.get::<MainConfig>().unwrap();
637 618
619 let mainconfig = framework.data.global.get::<MainConfig>().unwrap();
638 // load items using the invidious api 620 // load items using the invidious api
639 // gets the item that it needs to load from `data.state.Page` 621 // gets the item that it needs to load from `data.state.Page`
640 self.item = match r#type { 622 self.item = match r#type {
@@ -677,6 +659,10 @@ impl FrameworkItem for SingleItem {
677 // need to update provider every time the item loads or else it will display `${provider}` 659 // need to update provider every time the item loads or else it will display `${provider}`
678 // instead of the actual provider (e.g. `YouTube`) 660 // instead of the actual provider (e.g. `YouTube`)
679 self.update_provider(); 661 self.update_provider();
662 set_envs(
663 self.r#type.inflate(mainconfig, &self.item).into_iter(),
664 &mut framework.data.state.get_mut::<StateEnvs>().unwrap().0,
665 );
680 666
681 if let Some(item) = &self.item { 667 if let Some(item) = &self.item {
682 if item.is_unknown() { 668 if item.is_unknown() {
@@ -684,7 +670,12 @@ impl FrameworkItem for SingleItem {
684 } 670 }
685 671
686 let item = item.clone(); 672 let item = item.clone();
687 let max_watch_history = mainconfig.max_watch_history; 673 let max_watch_history = framework
674 .data
675 .global
676 .get::<MainConfig>()
677 .unwrap()
678 .max_watch_history;
688 679
689 // push to watch history 680 // push to watch history
690 let watch_history = framework.data.global.get_mut::<WatchHistory>().unwrap(); 681 let watch_history = framework.data.global.get_mut::<WatchHistory>().unwrap();
@@ -751,14 +742,7 @@ impl FrameworkItem for SingleItem {
751 // checks if it is updated, if it is and selected is not 0 (is hovering on 742 // checks if it is updated, if it is and selected is not 0 (is hovering on
752 // a video), then also need to update the iteminfo 743 // a video), then also need to update the iteminfo
753 KeyAction::MoveUp => { 744 KeyAction::MoveUp => {
754 let updated = singleplaylistitem.videos_view.up().is_ok(); 745 if singleplaylistitem.videos_view.selected == 1 {
755 if updated && singleplaylistitem.videos_view.selected != 0 {
756 singleplaylistitem.hovered_video.item = Some(
757 self.item.as_ref().unwrap().fullplaylist()?.videos
758 [singleplaylistitem.videos_view.selected - 1]
759 .clone(),
760 );
761 } else {
762 // going from a hovering video to not hovering will make the image 746 // going from a hovering video to not hovering will make the image
763 // stay on the screen, therefore it needs to be removed by clearing 747 // stay on the screen, therefore it needs to be removed by clearing
764 // the screen 748 // the screen
@@ -770,7 +754,15 @@ impl FrameworkItem for SingleItem {
770 .priority 754 .priority
771 .push(Task::ClearPage); 755 .push(Task::ClearPage);
772 } 756 }
773 updated 757
758 let updated = singleplaylistitem.videos_view.up().is_ok();
759 if singleplaylistitem.videos_view.selected != 0 {
760 singleplaylistitem.hovered_video.item = Some(
761 self.item.as_ref().unwrap().fullplaylist()?.videos
762 [singleplaylistitem.videos_view.selected - 1]
763 .clone(),
764 );
765 } updated
774 } 766 }
775 KeyAction::MoveDown => { 767 KeyAction::MoveDown => {
776 let updated = singleplaylistitem.videos_view.down().is_ok(); 768 let updated = singleplaylistitem.videos_view.down().is_ok();
@@ -889,6 +881,10 @@ impl FrameworkItem for SingleItem {
889 if singleplaylistitem.is_commands_view { 881 if singleplaylistitem.is_commands_view {
890 &mut singleplaylistitem.commands_view 882 &mut singleplaylistitem.commands_view
891 } else { 883 } else {
884 let y = (y - chunk.y) as usize + singleplaylistitem.videos_view.scroll;
885 if singleplaylistitem.videos_view.selected != 0 && y == 0 {
886 framework.data.state.get_mut::<Tasks>().unwrap().priority.push(Task::ClearPage);
887 }
892 &mut singleplaylistitem.videos_view 888 &mut singleplaylistitem.videos_view
893 } 889 }
894 } 890 }
@@ -930,11 +926,3 @@ impl FrameworkItem for SingleItem {
930 true 926 true
931 } 927 }
932} 928}
933
934/// apply the env hashmap to a command string
935pub fn apply_env(mut command: String, env: &HashMap<String, String>) -> String {
936 env.iter().for_each(|(key, value)| {
937 command = command.replace(&format!("${{{key}}}"), value);
938 });
939 command
940}
src/lib.rs −2
@@ -8,5 +8,3 @@ mod run;
8pub use run::*; 8pub use run::*;
9mod exit; 9mod exit;
10pub use exit::*; 10pub use exit::*;
11mod eggs;
12pub use eggs::*;
src/main.rs +11 −3
@@ -3,10 +3,10 @@ use crossterm::{
3 execute, 3 execute,
4 terminal::{disable_raw_mode, enable_raw_mode, EnterAlternateScreen, LeaveAlternateScreen}, 4 terminal::{disable_raw_mode, enable_raw_mode, EnterAlternateScreen, LeaveAlternateScreen},
5}; 5};
6use std::{error::Error, io}; 6use std::{env, error::Error, io};
7use tui::{backend::CrosstermBackend, Terminal}; 7use tui::{backend::CrosstermBackend, Terminal};
8use tui_additions::framework::{Framework, State}; 8use tui_additions::framework::{Framework, State};
9use youtube_tui::{exit, init, run}; 9use youtube_tui::{exit, global::functions::text_command, init, run};
10 10
11// stuff happening: 11// stuff happening:
12// 1. setup the terminal 12// 1. setup the terminal
@@ -14,6 +14,14 @@ use youtube_tui::{exit, init, run};
14// 3. restore the terminal 14// 3. restore the terminal
15// 4. unwrap errors 15// 4. unwrap errors
16fn main() -> Result<(), Box<dyn Error>> { 16fn main() -> Result<(), Box<dyn Error>> {
17 let args = env::args().skip(1).collect::<Vec<_>>();
18 let args_strs = args.iter().map(|s| s.as_str()).collect::<Vec<_>>();
19
20 if let Some(s) = text_command(&args_strs) {
21 println!("{s}");
22 return Ok(());
23 }
24
17 let state = State(Vec::new()); 25 let state = State(Vec::new());
18 let mut framework = Framework::new(state); 26 let mut framework = Framework::new(state);
19 27
@@ -24,7 +32,7 @@ fn main() -> Result<(), Box<dyn Error>> {
24 let mut terminal = Terminal::new(backend)?; 32 let mut terminal = Terminal::new(backend)?;
25 33
26 let res = (|| -> Result<(), Box<dyn Error>> { 34 let res = (|| -> Result<(), Box<dyn Error>> {
27 init(&mut framework, &mut terminal)?; 35 init(&mut framework, &mut terminal, &args_strs)?;
28 run(&mut terminal, &mut framework)?; 36 run(&mut terminal, &mut framework)?;
29 Ok(()) 37 Ok(())
30 })(); 38 })();
src/run.rs +10 −2
@@ -9,8 +9,8 @@ use tui_additions::{
9use crate::{ 9use crate::{
10 config::{KeyBindingsConfig, MainConfig}, 10 config::{KeyBindingsConfig, MainConfig},
11 global::{ 11 global::{
12 functions::command_capture, 12 functions::{clear_envs, command_capture, set_envs},
13 structs::{KeyAction, Message, Status, Task, Tasks}, 13 structs::{KeyAction, Message, StateEnvs, Status, Task, Tasks},
14 }, 14 },
15}; 15};
16 16
@@ -183,6 +183,11 @@ pub fn run(
183 .priority 183 .priority
184 .push(Task::Reload), 184 .push(Task::Reload),
185 KeyAction::Back => { 185 KeyAction::Back => {
186 if !framework.history.is_empty() {
187 clear_envs(
188 &mut framework.data.state.get::<StateEnvs>().unwrap().0.clone(),
189 );
190 }
186 if framework.revert_last_history().is_err() { 191 if framework.revert_last_history().is_err() {
187 *framework.data.global.get_mut::<Message>().unwrap() = 192 *framework.data.global.get_mut::<Message>().unwrap() =
188 Message::Error(String::from( 193 Message::Error(String::from(
@@ -202,6 +207,9 @@ pub fn run(
202 .unwrap() 207 .unwrap()
203 .priority 208 .priority
204 .push(Task::ClearPage); 209 .push(Task::ClearPage);
210 let state_envs =
211 framework.data.state.get_mut::<StateEnvs>().unwrap();
212 set_envs(state_envs.clone().0.into_iter(), &mut state_envs.0);
205 } 213 }
206 } 214 }
207 KeyAction::FirstHistory => { 215 KeyAction::FirstHistory => {