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"
150150
151151[[package]]
152152name = "console"
153version = "0.15.2"
153version = "0.15.3"
154154source = "registry+https://github.com/rust-lang/crates.io-index"
155checksum = "c050367d967ced717c04b65d8c619d863ef9292ce0c5760028655a2fb298718c"
155checksum = "5556015fe3aad8b968e5d4124980fbe2f6aaee7aeec6b749de1faaa2ca5d0a4c"
156156dependencies = [
157157 "encode_unicode",
158158 "lazy_static",
159159 "libc",
160 "terminal_size",
161 "winapi",
160 "windows-sys 0.42.0",
162161]
163162
164163[[package]]
@@ -263,9 +262,9 @@ checksum = "7a81dae078cea95a014a339291cec439d2f232ebe854a9d672b796c6afafa9b7"
263262
264263[[package]]
265264name = "cxx"
266version = "1.0.83"
265version = "1.0.85"
267266source = "registry+https://github.com/rust-lang/crates.io-index"
268checksum = "bdf07d07d6531bfcdbe9b8b739b104610c6508dcc4d63b410585faf338241daf"
267checksum = "5add3fc1717409d029b20c5b6903fc0c0b02fa6741d820054f4a2efa5e5816fd"
269268dependencies = [
270269 "cc",
271270 "cxxbridge-flags",
@@ -275,9 +274,9 @@ dependencies = [
275274
276275[[package]]
277276name = "cxx-build"
278version = "1.0.83"
277version = "1.0.85"
279278source = "registry+https://github.com/rust-lang/crates.io-index"
280checksum = "d2eb5b96ecdc99f72657332953d4d9c50135af1bac34277801cc3937906ebd39"
279checksum = "b4c87959ba14bc6fbc61df77c3fcfe180fc32b93538c4f1031dd802ccb5f2ff0"
281280dependencies = [
282281 "cc",
283282 "codespan-reporting",
@@ -290,15 +289,15 @@ dependencies = [
290289
291290[[package]]
292291name = "cxxbridge-flags"
293version = "1.0.83"
292version = "1.0.85"
294293source = "registry+https://github.com/rust-lang/crates.io-index"
295checksum = "ac040a39517fd1674e0f32177648334b0f4074625b5588a64519804ba0553b12"
294checksum = "69a3e162fde4e594ed2b07d0f83c6c67b745e7f28ce58c6df5e6b6bef99dfb59"
296295
297296[[package]]
298297name = "cxxbridge-macro"
299version = "1.0.83"
298version = "1.0.85"
300299source = "registry+https://github.com/rust-lang/crates.io-index"
301checksum = "1362b0ddcfc4eb0a1f57b68bd77dd99f0e826958a96abd0ae9bd092e114ffed6"
300checksum = "3e7e2adeb6a0d4a282e581096b06e1791532b7d576dcde5ccd9382acf55db8e6"
302301dependencies = [
303302 "proc-macro2",
304303 "quote",
@@ -307,9 +306,9 @@ dependencies = [
307306
308307[[package]]
309308name = "dyn-clone"
310version = "1.0.9"
309version = "1.0.10"
311310source = "registry+https://github.com/rust-lang/crates.io-index"
312checksum = "4f94fa09c2aeea5b8839e414b7b841bf429fd25b9c522116ac97ee87856d88b2"
311checksum = "c9b0705efd4599c15a38151f4721f7bc388306f61084d3bfd50bd07fbca5cb60"
313312
314313[[package]]
315314name = "either"
@@ -564,9 +563,9 @@ dependencies = [
564563
565564[[package]]
566565name = "half"
567version = "2.1.0"
566version = "2.2.0"
568567source = "registry+https://github.com/rust-lang/crates.io-index"
569checksum = "ad6a9459c9c30b177b925162351f97e7d967c7ea8bab3b8352805327daf45554"
568checksum = "6c467d36af040b7b2681f5fddd27427f6da8d3d072f575a265e181d2f8e8d157"
570569dependencies = [
571570 "crunchy",
572571]
@@ -579,9 +578,9 @@ checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888"
579578
580579[[package]]
581580name = "hermit-abi"
582version = "0.1.19"
581version = "0.2.6"
583582source = "registry+https://github.com/rust-lang/crates.io-index"
584checksum = "62b467343b94ba476dcb2500d242dadbb39557df889310ac77c5d99100aaac33"
583checksum = "ee512640fe35acbfb4bb779db6f0d80704c2cacfa2e39b601ef3e3f47d1ae4c7"
585584dependencies = [
586585 "libc",
587586]
@@ -757,9 +756,9 @@ checksum = "11b0d96e660696543b251e58030cf9787df56da39dab19ad60eae7353040917e"
757756
758757[[package]]
759758name = "itoa"
760version = "1.0.4"
759version = "1.0.5"
761760source = "registry+https://github.com/rust-lang/crates.io-index"
762checksum = "4217ad341ebadf8d8e724e264f13e593e0648f5b3e94b3896a5df283be015ecc"
761checksum = "fad582f4b9e86b6caa621cabeb0963332d92eea04729ab12892c2533951e6440"
763762
764763[[package]]
765764name = "jpeg-decoder"
@@ -793,15 +792,15 @@ checksum = "03087c2bad5e1034e8cace5926dec053fb3790248370865f5117a7d0213354c8"
793792
794793[[package]]
795794name = "libc"
796version = "0.2.138"
795version = "0.2.139"
797796source = "registry+https://github.com/rust-lang/crates.io-index"
798checksum = "db6d7e329c562c5dfab7a46a2afabc8b987ab9a4834c9d1ca04dc54c1546cef8"
797checksum = "201de327520df007757c1f0adce6e827fe8562fbc28bfd9c15571c66ca1f5f79"
799798
800799[[package]]
801800name = "link-cplusplus"
802version = "1.0.7"
801version = "1.0.8"
803802source = "registry+https://github.com/rust-lang/crates.io-index"
804checksum = "9272ab7b96c9046fbc5bc56c06c117cb639fe2d509df0c421cad82d2915cf369"
803checksum = "ecd207c9c713c34f95a097a5b029ac2ce6010530c7b49d7fea24d977dede04f5"
805804dependencies = [
806805 "cc",
807806]
@@ -941,9 +940,9 @@ dependencies = [
941940
942941[[package]]
943942name = "num_cpus"
944version = "1.14.0"
943version = "1.15.0"
945944source = "registry+https://github.com/rust-lang/crates.io-index"
946checksum = "f6058e64324c71e02bc2b150e4f3bc8286db6c83092132ffa3f6b1eab0f9def5"
945checksum = "0fac9e2da13b5eb447a6ce3d392f23a29d8694bff781bf03a16cd9ac8697593b"
947946dependencies = [
948947 "hermit-abi",
949948 "libc",
@@ -980,15 +979,15 @@ dependencies = [
980979
981980[[package]]
982981name = "once_cell"
983version = "1.16.0"
982version = "1.17.0"
984983source = "registry+https://github.com/rust-lang/crates.io-index"
985checksum = "86f0b0d4bf799edbc74508c1e8bf170ff5f41238e5f8225603ca7caaae2b7860"
984checksum = "6f61fba1741ea2b3d6a1e3178721804bb716a68a6aeba1149b5d52e3d464ea66"
986985
987986[[package]]
988987name = "openssl"
989version = "0.10.44"
988version = "0.10.45"
990989source = "registry+https://github.com/rust-lang/crates.io-index"
991checksum = "29d971fd5722fec23977260f6e81aa67d2f22cadbdc2aa049f1022d9a3be1566"
990checksum = "b102428fd03bc5edf97f62620f7298614c45cedf287c271e7ed450bbaf83f2e1"
992991dependencies = [
993992 "bitflags",
994993 "cfg-if",
@@ -1018,9 +1017,9 @@ checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf"
10181017
10191018[[package]]
10201019name = "openssl-sys"
1021version = "0.9.79"
1020version = "0.9.80"
10221021source = "registry+https://github.com/rust-lang/crates.io-index"
1023checksum = "5454462c0eced1e97f2ec09036abc8da362e66802f66fd20f86854d9d8cbcbc4"
1022checksum = "23bbbf7854cd45b83958ebe919f0e8e516793727652e27fda10a8384cfc790b7"
10241023dependencies = [
10251024 "autocfg",
10261025 "cc",
@@ -1110,18 +1109,18 @@ dependencies = [
11101109
11111110[[package]]
11121111name = "proc-macro2"
1113version = "1.0.47"
1112version = "1.0.49"
11141113source = "registry+https://github.com/rust-lang/crates.io-index"
1115checksum = "5ea3d908b0e36316caf9e9e2c4625cdde190a7e6f440d794667ed17a1855e725"
1114checksum = "57a8eca9f9c4ffde41714334dee777596264c7825420f521abc92b5b5deb63a5"
11161115dependencies = [
11171116 "unicode-ident",
11181117]
11191118
11201119[[package]]
11211120name = "quote"
1122version = "1.0.21"
1121version = "1.0.23"
11231122source = "registry+https://github.com/rust-lang/crates.io-index"
1124checksum = "bbe448f377a7d6961e30f5955f9b8d106c3f5e449d493ee1b125c1d43c2b5179"
1123checksum = "8856d8364d252a14d474036ea1358d63c9e6965c8e5c1885c18f73d70bff9c7b"
11251124dependencies = [
11261125 "proc-macro2",
11271126]
@@ -1214,9 +1213,9 @@ dependencies = [
12141213
12151214[[package]]
12161215name = "ryu"
1217version = "1.0.11"
1216version = "1.0.12"
12181217source = "registry+https://github.com/rust-lang/crates.io-index"
1219checksum = "4501abdff3ae82a1c1b477a17252eb69cee9e66eb915c1abaa4f44d873df9f09"
1218checksum = "7b4b9743ed687d4b4bcedf9ff5eaa7398495ae14e61cba0a295704edbc7decde"
12201219
12211220[[package]]
12221221name = "schannel"
@@ -1242,9 +1241,9 @@ checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd"
12421241
12431242[[package]]
12441243name = "scratch"
1245version = "1.0.2"
1244version = "1.0.3"
12461245source = "registry+https://github.com/rust-lang/crates.io-index"
1247checksum = "9c8132065adcfd6e02db789d9285a0deb2f3fcb04002865ab67d5fb103533898"
1246checksum = "ddccb15bcce173023b3fedd9436f882a0739b8dfb45e4f6b6002bee5929f61b2"
12481247
12491248[[package]]
12501249name = "security-framework"
@@ -1271,18 +1270,18 @@ dependencies = [
12711270
12721271[[package]]
12731272name = "serde"
1274version = "1.0.151"
1273version = "1.0.152"
12751274source = "registry+https://github.com/rust-lang/crates.io-index"
1276checksum = "97fed41fc1a24994d044e6db6935e69511a1153b52c15eb42493b26fa87feba0"
1275checksum = "bb7d1f0d3021d347a83e556fc4683dea2ea09d87bccdf88ff5c12545d89d5efb"
12771276dependencies = [
12781277 "serde_derive",
12791278]
12801279
12811280[[package]]
12821281name = "serde_derive"
1283version = "1.0.151"
1282version = "1.0.152"
12841283source = "registry+https://github.com/rust-lang/crates.io-index"
1285checksum = "255abe9a125a985c05190d687b320c12f9b1f0b99445e608c21ba0782c719ad8"
1284checksum = "af487d118eecd09402d70a5d72551860e788df87b464af30e5ea6a38c75c541e"
12861285dependencies = [
12871286 "proc-macro2",
12881287 "quote",
@@ -1291,9 +1290,9 @@ dependencies = [
12911290
12921291[[package]]
12931292name = "serde_json"
1294version = "1.0.89"
1293version = "1.0.91"
12951294source = "registry+https://github.com/rust-lang/crates.io-index"
1296checksum = "020ff22c755c2ed3f8cf162dbb41a7268d934702f3ed3631656ea597e08fc3db"
1295checksum = "877c235533714907a8c2464236f5c4b2a17262ef1bd71f38f35ea592c8da6883"
12971296dependencies = [
12981297 "itoa",
12991298 "ryu",
@@ -1314,9 +1313,9 @@ dependencies = [
13141313
13151314[[package]]
13161315name = "serde_yaml"
1317version = "0.9.14"
1316version = "0.9.16"
13181317source = "registry+https://github.com/rust-lang/crates.io-index"
1319checksum = "6d232d893b10de3eb7258ff01974d6ee20663d8e833263c99409d4b13a0209da"
1318checksum = "92b5b431e8907b50339b51223b97d102db8d987ced36f6e4d03621db9316c834"
13201319dependencies = [
13211320 "indexmap",
13221321 "itoa",
@@ -1409,9 +1408,9 @@ dependencies = [
14091408
14101409[[package]]
14111410name = "syn"
1412version = "1.0.105"
1411version = "1.0.107"
14131412source = "registry+https://github.com/rust-lang/crates.io-index"
1414checksum = "60b9b43d45702de4c839cb9b51d9f529c5dd26a4aff255b42b1ebc03e88ee908"
1413checksum = "1f4064b5b16e03ae50984a5a8ed5d4f8803e6bc1fd170a3cda91a1be4b18e3f5"
14151414dependencies = [
14161415 "proc-macro2",
14171416 "quote",
@@ -1441,16 +1440,6 @@ dependencies = [
14411440 "winapi-util",
14421441]
14431442
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
14541443[[package]]
14551444name = "threadpool"
14561445version = "1.8.1"
@@ -1615,9 +1604,9 @@ checksum = "099b7128301d285f79ddd55b9a83d5e6b9e97c92e0ea0daebee7263e932de992"
16151604
16161605[[package]]
16171606name = "unicode-ident"
1618version = "1.0.5"
1607version = "1.0.6"
16191608source = "registry+https://github.com/rust-lang/crates.io-index"
1620checksum = "6ceab39d59e4c9499d4e5a8ee0e2735b891bb7308ac83dfb4e80cad195c9f6f3"
1609checksum = "84a22b9f218b40614adcb3f4ff08b703773ad44fa9423e4e0d346d5db86e4ebc"
16211610
16221611[[package]]
16231612name = "unicode-normalization"
@@ -1651,9 +1640,9 @@ dependencies = [
16511640
16521641[[package]]
16531642name = "unsafe-libyaml"
1654version = "0.2.4"
1643version = "0.2.5"
16551644source = "registry+https://github.com/rust-lang/crates.io-index"
1656checksum = "c1e5fa573d8ac5f1a856f8d7be41d390ee973daf97c806b2c1a465e4e1406e68"
1645checksum = "bc7ed8ba44ca06be78ea1ad2c3682a43349126c8818054231ee6f4748012aed2"
16571646
16581647[[package]]
16591648name = "url"
docs/src/README.md +2 −3
@@ -53,12 +53,11 @@ It also includes features like:
5353
5454### What it doesn't have
5555
56- Command line args (first priority)
57- Bootleg Vimscript? (will implement)
56- Binding commands to keys (first priority)
57- Bootleg Vimscript? (first priority)
5858- Channel search (will implement)
5959- Channel videos sorting (will implement)
6060- Subscriptions (will implement)
61- Recommendations/comments (probably will not implement)
6261
6362## How to contribute
6463
docs/src/changelogs.md +13 −1
@@ -1,9 +1,21 @@
11# Changelogs
22
3## v0.6.0
3## v0.6.1
44
55### Added
66
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
719- Mouse support
820- Vim-like commands
921- Pasting with `Ctrl + V` in search bar and command mode
docs/src/commands.md +26 −13
@@ -2,6 +2,10 @@
22
33Commands 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.
44
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
59Below are the avaliable commands:
610
711## Loadpage
@@ -9,13 +13,13 @@ Below are the avaliable commands:
913`loadpage` can be used to load a specific page.
1014
1115```vim
12:loadpage popular (alt: `popular`)
13:loadpage trending (alt: `trending`)
14:loadpage watchhistory (alt: `watchhistory`)
15:loadpage search [search query] (alt: `search [search query]`)
16:loadpage video [id or url] (alt: `video [id or url]`)
17:loadpage playlist [id or url] (alt: `playlist [id or url] `)
18:loadpage channel [id or url] (alt: `channel [id or url] `)
16loadpage popular (alt: `popular`)
17loadpage trending (alt: `trending`)
18loadpage watchhistory (alt: `watchhistory`)
19loadpage search [search query] (alt: `search [search query]`)
20loadpage video [id or url] (alt: `video [id or url]`)
21loadpage playlist [id or url] (alt: `playlist [id or url] `)
22loadpage channel [id or url] (alt: `channel [id or url] `)
1923```
2024
2125## History
@@ -23,19 +27,28 @@ Below are the avaliable commands:
2327`history` is used to manage page history (`Backspace` equivalent).
2428
2529```vim
26:history back (alt: `back`)
27:history clear
30history back (alt: `back`)
31history clear
2832```
2933
3034## Utility
3135
3236```vim
33:reload (alt `r`)
34:reload configs (alt `reload/r config/configs`)
35:flush
36:quit (alt `q`, `exit`, `x`)
37reload (alt `r`)
38reload configs (alt `reload/r config/configs`)
39flush
40quit (alt `q`, `exit`, `x`)
3741```
3842
3943> The `flush` command is used to run all tasks in queue immediately, this is usually done automatically.
4044>
4145> 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:
99- Play video: ${video-player} ${embed-url}
1010- Play audio: ${terminal-emulator} ${video-player} ${embed-url} --no-video
1111- 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}
1313- Open in browser: ${browser} ${url}
1414- Download video (webm): ${terminal-emulator} ${youtube-downloader} -o ${download-path} ${embed-url}
1515- Download audio (opus): ${terminal-emulator} ${youtube-downloader} -o ${download-path} ${embed-url} -x
@@ -20,7 +20,7 @@ playlist:
2020- Play all audio: ${terminal-emulator} ${video-player} ${all-videos} --no-video
2121- Shuffle play all audio: ${terminal-emulator} ${video-player} ${all-videos} --no-video --shuffle
2222- 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}
2424- Open in browser: ${browser} ${url}
2525- Download all video (webm): ${terminal-emulator} ${youtube-downloader} -o ${download-path} ${all-videos}
2626- 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`.
8484|Name|Page|Value|
8585|---|---|---|
8686|`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|
8789|`embed-url`|video|String url to the embed video (required to play video using mpv from Invidious)|
8890|`all-videos`|playlist|String url***s*** separated by space to all embed videos in a playlist|
8991|`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
2525Use 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.
2626
2727```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
2931```
3032
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
3533## Build from source
3634
3735Use the `cargo` command:
src/config/commands.rs +2 −2
@@ -77,7 +77,7 @@ fn video_default() -> Vec<HashMap<String, String>> {
7777 )]),
7878 HashMap::from([(
7979 String::from("View channel"),
80 String::from(":channel ${channel_id}"),
80 String::from(":channel ${channel-id}"),
8181 )]),
8282 HashMap::from([(
8383 String::from("Open in browser"),
@@ -123,7 +123,7 @@ fn playlist_default() -> Vec<HashMap<String, String>> {
123123 )]),
124124 HashMap::from([(
125125 String::from("View channel"),
126 String::from(":channel ${channel_id}"),
126 String::from(":channel ${channel-id}"),
127127 )]),
128128 HashMap::from([(
129129 String::from("Open in browser"),
src/config/keybindings.rs −4
@@ -109,10 +109,6 @@ impl Default for KeyBindingsConfigSerde {
109109 HashMap::from([(0, KeyAction::FirstHistory)]),
110110 ),
111111 // clipboard
112 (
113 KeyCodeSerde::Char('c'),
114 HashMap::from([(2, KeyAction::Copy)]),
115 ),
116112 (
117113 KeyCodeSerde::Char('v'),
118114 HashMap::from([(2, KeyAction::Paste)]),
src/config/main.rs −1
@@ -80,7 +80,6 @@ impl Images {
8080pub enum Provider {
8181 YouTube,
8282 Invidious,
83 // Piped,
8483}
8584
8685impl 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};
22use crate::{
33 config::KeyBindingsConfig,
44 global::structs::{KeyAction, Message, Status, Task, Tasks},
@@ -66,7 +66,7 @@ pub fn command_capture(framework: &mut FrameworkClean, key: KeyEvent) -> bool {
6666 .get_mut::<Tasks>()
6767 .unwrap()
6868 .priority
69 .push(Task::Command(textfield.content.clone()));
69 .push(Task::Command(apply_envs(textfield.content.clone())));
7070 framework
7171 .data
7272 .global
src/global/functions/from_url.rs +11 −3
@@ -1,3 +1,4 @@
1/// gets the channel id from it's url
12pub fn from_channel_url(identifier: &str) -> Result<String, String> {
23 // a youtube channel id is exactly 24 characters long, so if the identifier to 24 chars
34 // long, then just assume its the channel id
@@ -27,14 +28,18 @@ pub fn from_channel_url(identifier: &str) -> Result<String, String> {
2728}
2829
2930pub 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
3033 if identifier.len() == 11 {
3134 Ok(identifier.to_string())
3235 } else {
36 // the id can come after "?v=" in an url
3337 let index = if let Some(index) = identifier.find("?v=") {
3438 if identifier.len() < index + 15 {
3539 return Err(format!("Cannot find video id from string `{}`", identifier));
3640 }
3741 index + 3
42 // and also "youtu.be/"
3843 } else if let Some(index) = identifier.find("youtu.be/") {
3944 if identifier.len() < index + 21 {
4045 return Err(format!("Cannot find video id from string `{}`", identifier));
@@ -49,17 +54,20 @@ pub fn from_video_url(identifier: &str) -> Result<String, String> {
4954}
5055
5156pub 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
5259 if identifier.len() == 34 {
5360 Ok(identifier.to_string())
5461 } else {
55 let index = if let Some(index) = identifier.find("playlist?list=") {
56 if identifier.len() < index + 48 {
62 // the id can come after "list=" in urls
63 let index = if let Some(index) = identifier.find("list=") {
64 if identifier.len() < index + 39 {
5765 return Err(format!(
5866 "Cannot find plalyist id from string `{}`",
5967 identifier
6068 ));
6169 }
62 index + 14
70 index + 5
6371 } else {
6472 return Err(format!(
6573 "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;
1010mod popup_area;
1111pub use popup_area::popup_area;
1212mod run_command;
13pub use run_command::run_command;
13pub use run_command::*;
1414mod command_capture;
1515pub use command_capture::command_capture;
1616mod fake_rand;
1717pub use fake_rand::*;
1818mod clipboard;
1919pub use self::clipboard::*;
20mod type_name_of_val;
21pub use type_name_of_val::*;
2220mod from_url;
2321pub use from_url::*;
22mod envs;
23pub use envs::*;
src/global/functions/run_command.rs +136 −24
@@ -6,29 +6,44 @@ use crate::{
66 },
77 load_configs,
88};
9use std::io::Stdout;
9use std::{io::Stdout, thread};
1010use tui::{backend::CrosstermBackend, Terminal};
1111use tui_additions::framework::Framework;
1212
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};
1414
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
1629pub fn run_command(
1730 command: &[&str],
1831 framework: &mut Framework,
1932 terminal: &mut Terminal<CrosstermBackend<Stdout>>,
20) {
33) -> bool {
2134 // match a command splitted by space to a bunch of avaliable commands
2235 match command {
23 [] => {}
36 [] => false,
2437 ["help"] | ["h"] => {
2538 *framework.data.global.get_mut::<Message>().unwrap() = Message::Message(String::from(
2639 "Avaliable commands can be viewed by running `youtube-tui help` in terminal",
27 ))
40 ));
41 false
2842 }
2943 ["loadpage"] => {
3044 *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
3247 }
3348 // loads a given page
3449 ["loadpage", page, ..] => {
@@ -40,7 +55,7 @@ pub fn run_command(
4055 if command.len() == 2 {
4156 *framework.data.global.get_mut::<Message>().unwrap() =
4257 Message::Message(String::from("Usage: `loadpage channel {id/url}`"));
43 return;
58 return false;
4459 }
4560
4661 match from_channel_url(command[2]) {
@@ -51,7 +66,7 @@ pub fn run_command(
5166 Err(e) => {
5267 *framework.data.global.get_mut::<Message>().unwrap() =
5368 Message::Error(e);
54 return;
69 return false;
5570 }
5671 }
5772 }
@@ -59,7 +74,7 @@ pub fn run_command(
5974 if command.len() == 2 {
6075 *framework.data.global.get_mut::<Message>().unwrap() =
6176 Message::Message(String::from("Usage: `loadpage video {id/url}`"));
62 return;
77 return false;
6378 }
6479
6580 match from_video_url(command[2]) {
@@ -67,7 +82,7 @@ pub fn run_command(
6782 Err(e) => {
6883 *framework.data.global.get_mut::<Message>().unwrap() =
6984 Message::Error(e);
70 return;
85 return false;
7186 }
7287 }
7388 }
@@ -75,7 +90,7 @@ pub fn run_command(
7590 if command.len() == 2 {
7691 *framework.data.global.get_mut::<Message>().unwrap() =
7792 Message::Message(String::from("Usage: `loadpage playlist {id/url}`"));
78 return;
93 return false;
7994 }
8095
8196 match from_playlist_url(command[2]) {
@@ -83,7 +98,7 @@ pub fn run_command(
8398 Err(e) => {
8499 *framework.data.global.get_mut::<Message>().unwrap() =
85100 Message::Error(e);
86 return;
101 return false;
87102 }
88103 }
89104 }
@@ -91,7 +106,7 @@ pub fn run_command(
91106 if command.len() == 2 {
92107 *framework.data.global.get_mut::<Message>().unwrap() =
93108 Message::Message(String::from("Usage: `search {query}`"));
94 return;
109 return true;
95110 }
96111
97112 // search for a query, although the command is matched as an array, the original query can
@@ -117,6 +132,8 @@ pub fn run_command(
117132 .priority
118133 .push(Task::LoadPage(page))
119134 }
135
136 true
120137 }
121138 // redirects to the relevant `loadpage` command
122139 ["popular"] => run_command(&["loadpage", "popular"], framework, terminal),
@@ -142,42 +159,95 @@ pub fn run_command(
142159 ["playlist", identifier] => {
143160 run_command(&["loadpage", "playlist", *identifier], framework, terminal)
144161 }
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 }
146167 ["history", "back"] | ["back"] => {
147168 let _ = framework.revert_last_history();
148 framework.data.state.get_mut::<Tasks>().unwrap().priority.push(Task::ClearPage);
149 framework.data.state.get_mut::<Tasks>().unwrap().priority.push(Task::RenderAll);
169 framework
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);
150183 run_command(&["flush"], framework, terminal);
151 framework.data.global.get_mut::<Status>().unwrap().render_image = true;
152 },
153 ["history", "clear"] => framework.clear_history(),
184 framework
185 .data
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 }
154196 ["flush"] => loop {
155197 // runs all stacked actions
156198 if let Some(tasks) = framework.data.state.get_mut::<Tasks>().unwrap().pop() {
157199 let _res = tasks.run(framework, terminal);
158200 continue;
159201 }
160 break;
202 break false;
161203 },
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 }
163214 ["reload", "config"] | ["reload", "configs"] | ["r", "config"] | ["r", "configs"] => {
164215 *framework.data.global.get_mut::<Message>().unwrap() =
165216 match load_configs(&mut framework.split_clean().0) {
166217 Ok(()) => Message::Success(String::from("Config files have been reloaded")),
167218 Err(e) => Message::Error(e.to_string()),
168 }
219 };
220 false
169221 }
170222 ["q"] | ["quit"] | ["x"] | ["exit"] => {
171223 framework.data.global.get_mut::<Status>().unwrap().exit = true;
224 false
172225 }
173226 ["hello", "world"] => {
174227 let index = fake_rand_range(0, HELLO_WORLDS.len() as i64) as usize;
175228 *framework.data.global.get_mut::<Message>().unwrap() =
176229 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
177246 }
178247 _ => {
179248 *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
181251 }
182252 }
183253}
@@ -212,3 +282,45 @@ const HELLO_WORLDS: &[&str] = &[
212282 "print *, \"Hello World\"",
213283 "<h1>Hello World<\\h1>",
214284];
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 {
2828 Unknown(SearchItemTransition),
2929}
3030
31/// stores information of a previewed video
3132#[derive(Clone, Serialize, Deserialize)]
3233pub struct MiniVideoItem {
3334 pub title: String,
@@ -41,6 +42,7 @@ pub struct MiniVideoItem {
4142 pub description: Option<String>,
4243}
4344
45/// stores information of a previewed playlist
4446#[derive(Clone, Serialize, Deserialize)]
4547pub struct MiniPlaylistItem {
4648 pub title: String,
@@ -51,6 +53,7 @@ pub struct MiniPlaylistItem {
5153 pub thumbnail_url: String,
5254}
5355
56/// stores information of a previewed channel
5457#[derive(Clone, Serialize, Deserialize)]
5558pub struct MiniChannelItem {
5659 pub name: String,
@@ -62,6 +65,7 @@ pub struct MiniChannelItem {
6265 pub description: String,
6366}
6467
68/// stores information of a viewed video
6569#[derive(Clone, Serialize, Deserialize)]
6670pub struct FullVideoItem {
6771 pub title: String,
@@ -79,6 +83,7 @@ pub struct FullVideoItem {
7983 pub genre: String,
8084}
8185
86/// stores information of a viewed playlist
8287#[derive(Clone, Serialize, Deserialize)]
8388pub struct FullPlaylistItem {
8489 pub title: String,
@@ -92,6 +97,7 @@ pub struct FullPlaylistItem {
9297 pub videos: Vec<Item>,
9398}
9499
100/// stores information of a viewed channel
95101#[derive(Clone, Serialize, Deserialize)]
96102pub struct FullChannelItem {
97103 pub name: String,
@@ -127,6 +133,7 @@ impl Display for Item {
127133}
128134
129135impl Item {
136 /// returns the id of an item, `None` is self is Unknown
130137 pub fn id(&self) -> Option<&str> {
131138 match self {
132139 Self::MiniVideo(MiniVideoItem { id, .. })
@@ -135,16 +142,18 @@ impl Item {
135142 | Self::FullVideo(FullVideoItem { id, .. })
136143 | Self::FullChannel(FullChannelItem { id, .. })
137144 | Self::FullPlaylist(FullPlaylistItem { id, .. }) => Some(id),
138 _ => None,
145 Self::Unknown(_) | Self::Page(_) => None,
139146 }
140147 }
141148
149 /// check if self is Self::Unknown
142150 pub fn is_unknown(&self) -> bool {
143151 matches!(self, Self::Unknown(_))
144152 }
145153}
146154
147155impl Item {
156 /// stript self into a FullVideoItem
148157 pub fn fullvideo(&self) -> Result<&FullVideoItem, Errors> {
149158 match self {
150159 Self::FullVideo(fullvideo) => Ok(fullvideo),
@@ -152,6 +161,7 @@ impl Item {
152161 }
153162 }
154163
164 /// stript self into a MiniVideoItem
155165 pub fn minivideo(&self) -> Result<&MiniVideoItem, Errors> {
156166 match self {
157167 Self::MiniVideo(minivideo) => Ok(minivideo),
@@ -159,6 +169,7 @@ impl Item {
159169 }
160170 }
161171
172 /// stript self into a MiniPlaylistItem
162173 pub fn miniplaylist(&self) -> Result<&MiniPlaylistItem, Errors> {
163174 match self {
164175 Self::MiniPlaylist(miniplaylist) => Ok(miniplaylist),
@@ -166,6 +177,7 @@ impl Item {
166177 }
167178 }
168179
180 /// stript self into a FullPlaylistItem
169181 pub fn fullplaylist(&self) -> Result<&FullPlaylistItem, Errors> {
170182 match self {
171183 Self::FullPlaylist(fullplaylist) => Ok(fullplaylist),
@@ -173,6 +185,7 @@ impl Item {
173185 }
174186 }
175187
188 /// stript self into a MiniChannelItem
176189 pub fn minichannel(&self) -> Result<&MiniChannelItem, Errors> {
177190 match self {
178191 Self::MiniChannel(minichannel) => Ok(minichannel),
@@ -182,7 +195,8 @@ impl Item {
182195}
183196
184197impl 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
186200 pub fn thumbnail_id(&self) -> &str {
187201 match self {
188202 Self::MiniVideo(video) => &video.id,
@@ -195,7 +209,7 @@ impl Item {
195209 }
196210 }
197211
198 // cannot impl From<T> because it also need `image_index`
212 /// parse `TrendingVideo` into `Self`
199213 pub fn from_trending_video(original: TrendingVideo, image_index: usize) -> Self {
200214 Self::MiniVideo(MiniVideoItem {
201215 title: original.title,
@@ -214,6 +228,7 @@ impl Item {
214228 })
215229 }
216230
231 /// parse `PopularItem` into `Self`
217232 pub fn from_popular_item(original: PopularItem, image_index: usize) -> Self {
218233 Self::MiniVideo(MiniVideoItem {
219234 title: original.title,
@@ -232,6 +247,7 @@ impl Item {
232247 })
233248 }
234249
250 /// parse `Playlist` into `Self`
235251 pub fn from_mini_playlist(original: Playlist) -> Self {
236252 Self::MiniPlaylist(MiniPlaylistItem {
237253 title: original.title,
@@ -243,6 +259,7 @@ impl Item {
243259 })
244260 }
245261
262 /// parse `SearchItem` into `Self`
246263 pub fn from_search_item(original: SearchItem, image_index: usize) -> Self {
247264 match original {
248265 SearchItem::Video {
@@ -305,6 +322,7 @@ impl Item {
305322 }
306323 }
307324
325 /// parse `Video` into `Self`
308326 pub fn from_full_video(original: Video, image_index: usize) -> Self {
309327 Self::FullVideo(FullVideoItem {
310328 title: original.title,
@@ -326,6 +344,7 @@ impl Item {
326344 })
327345 }
328346
347 /// parse `FullPlaylist` into `Self`
329348 pub fn from_full_playlist(original: FullPlaylist, image_index: usize) -> Self {
330349 Self::FullPlaylist(FullPlaylistItem {
331350 title: original.title,
@@ -344,6 +363,7 @@ impl Item {
344363 })
345364 }
346365
366 /// parse `PlaylistItem` into `Self`
347367 pub fn from_playlist_item(original: PlaylistItem, image_index: usize) -> Self {
348368 Self::MiniVideo(MiniVideoItem {
349369 title: original.title,
@@ -358,6 +378,7 @@ impl Item {
358378 })
359379 }
360380
381 /// parse `Channel` into `Self`
361382 pub fn from_full_channel(original: Channel, image_index: usize) -> Self {
362383 Self::FullChannel(FullChannelItem {
363384 name: original.name,
@@ -372,6 +393,7 @@ impl Item {
372393 })
373394 }
374395
396 /// parse `ChannelVideo` into `Self`
375397 pub fn from_channel_video(original: ChannelVideo, image_index: usize) -> Self {
376398 Self::MiniVideo(MiniVideoItem {
377399 title: original.title,
@@ -390,6 +412,7 @@ impl Item {
390412 })
391413 }
392414
415 /// parse `Playlist` into `Self`
393416 pub fn from_channel_playlist(original: Playlist) -> Self {
394417 Self::MiniPlaylist(MiniPlaylistItem {
395418 title: original.title,
src/global/structs/keyaction.rs −2
@@ -28,8 +28,6 @@ pub enum KeyAction {
2828 Reload,
2929 /// start command capture
3030 StartCommandCapture,
31 /// copy text
32 r#Copy,
3331 /// paste text
3432 Paste,
3533}
src/global/structs/mod.rs +2
@@ -5,6 +5,7 @@ mod item;
55mod keyaction;
66mod message;
77mod page;
8mod state_env;
89mod status;
910mod tasks;
1011mod watchhistory;
@@ -15,6 +16,7 @@ pub use item::*;
1516pub use keyaction::*;
1617pub use message::*;
1718pub use page::*;
19pub use state_env::*;
1820pub use status::*;
1921pub use tasks::*;
2022pub use watchhistory::*;
src/global/structs/status.rs +2
@@ -5,7 +5,9 @@ use typemap::Key;
55/// a struct for storing different info, currently only stores one info
66#[derive(Clone)]
77pub struct Status {
8 /// is there is a popup opened
89 pub popup_opened: bool,
10 /// is search filter popup opened
911 pub search_filter_opened: bool,
1012 /// to prevent rerendering the same image
1113 pub render_image: bool,
src/global/structs/tasks.rs +38 −8
@@ -1,9 +1,9 @@
11use crate::{
2 config::{AppearanceConfig, MinDimentions},
3 global::functions::run_command,
2 config::{AppearanceConfig, MainConfig, MinDimentions},
3 global::functions::{clear_envs, run_command, set_envs},
44};
55
6use super::{message::Message, page::Page, status::Status};
6use super::{message::Message, page::Page, status::Status, StateEnvs};
77use std::{error::Error, io::Stdout, mem};
88use tui::{
99 backend::CrosstermBackend, layout::Alignment, style::Style, widgets::Paragraph, Frame, Terminal,
@@ -48,7 +48,7 @@ impl Default for TaskQueue {
4848}
4949
5050impl TaskQueue {
51 // add task to queue
51 /// add task to queue
5252 pub fn push(&mut self, task: Task) {
5353 match task {
5454 Task::RenderAll => self.render = RenderTask::All,
@@ -67,7 +67,6 @@ impl TaskQueue {
6767 Task::ClearPage => self.clear_all = true,
6868 Task::LazyRendered => self.lazy_rendered = true,
6969 Task::Command(s) => self.commands.push(s),
70 // _ => {}
7170 }
7271 }
7372
@@ -75,7 +74,7 @@ impl TaskQueue {
7574 self == &Self::default()
7675 }
7776
78 // runs all tasks in a task queue
77 /// runs all tasks in a task queue
7978 pub fn run(
8079 self,
8180 framework: &mut Framework,
@@ -109,6 +108,22 @@ impl TaskQueue {
109108 *framework.data.global.get_mut::<Message>().unwrap() =
110109 Message::Message(page.load_msg(framework));
111110 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
112127 framework.cursor = CursorState::default();
113128
114129 let page_config = page.to_page_config(framework);
@@ -132,6 +147,20 @@ impl TaskQueue {
132147 }
133148
134149 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
135164 // reload simply runs `.load()` on all items
136165 *framework.data.global.get_mut::<Message>().unwrap() =
137166 Message::Message(String::from("Reloading page..."));
@@ -159,7 +188,7 @@ impl TaskQueue {
159188 Ok(())
160189 }
161190
162 // the render task runs this function
191 /// the render task runs this function
163192 pub fn render(
164193 framework: &mut Framework,
165194 terminal: &mut Terminal<CrosstermBackend<Stdout>>,
@@ -171,7 +200,7 @@ impl TaskQueue {
171200 Ok(())
172201 }
173202
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
175204 pub fn render_force_clear(
176205 framework: &mut Framework,
177206 terminal: &mut Terminal<CrosstermBackend<Stdout>>,
@@ -184,6 +213,7 @@ impl TaskQueue {
184213 Ok(())
185214 }
186215
216 /// this function renders onto the given frame
187217 pub fn render_with_frame(
188218 framework: &mut Framework,
189219 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
22pub trait AsUrlString {
33 const TAG: &'static str;
44 fn as_url_string(&self) -> String
src/init.rs +10 −5
@@ -5,9 +5,9 @@ use crate::{
55 },
66 global::{
77 functions::run_command,
8 structs::{InvidiousClient, Message, Page, Status, Tasks, WatchHistory},
8 structs::{InvidiousClient, Message, Page, StateEnvs, Status, Tasks, WatchHistory},
99 traits::ConfigTrait,
10 }, egg,
10 },
1111};
1212use home::home_dir;
1313use std::{error::Error, fs, io::Stdout};
@@ -22,6 +22,7 @@ use tui_additions::framework::{Framework, FrameworkClean};
2222pub fn init(
2323 framework: &mut Framework,
2424 terminal: &mut Terminal<CrosstermBackend<Stdout>>,
25 command: &[&str],
2526) -> Result<(), Box<dyn Error>> {
2627 // creating files
2728 let home_dir = home_dir().unwrap();
@@ -52,7 +53,9 @@ pub fn init(
5253
5354 load_configs(&mut framework.split_clean().0).ok();
5455
55 run_command(&["loadpage", "popular"], framework, terminal);
56 if !run_command(command, framework, terminal) {
57 run_command(&["loadpage", "popular"], framework, terminal);
58 }
5659 run_command(&["flush"], framework, terminal);
5760 run_command(&["history", "clear"], framework, terminal);
5861 Ok(())
@@ -95,8 +98,10 @@ pub fn load_configs(framework: &mut FrameworkClean) -> Result<(), Box<dyn Error>
9598 .global
9699 .insert::<KeyBindingsConfig>(KeyBindingsConfig::load()?);
97100 framework.data.state.insert::<Search>(*Search::load()?);
98
99 egg();
101 framework
102 .data
103 .state
104 .insert::<StateEnvs>(StateEnvs::default());
100105
101106 Ok(())
102107}
src/items/channeldisplay.rs +9
@@ -22,17 +22,21 @@ use tui_additions::{
2222/// the 4 pages that a channel has (including the default "blank" page when loading)
2323#[derive(Clone)]
2424pub enum ChannelDisplay {
25 /// a blank item, will turn into one of the other variants when `.load()` depending on the page
2526 None,
27 /// main channel display page
2628 Main {
2729 channel: Item,
2830 iteminfo: ItemInfo,
2931 },
32 /// latest videos
3033 Videos {
3134 videos: Vec<Item>,
3235 textlist: TextList,
3336 iteminfo: ItemInfo,
3437 grid: Grid,
3538 },
39 /// created playlists
3640 Playlists {
3741 playlists: Vec<Item>,
3842 textlist: TextList,
@@ -48,6 +52,7 @@ impl Default for ChannelDisplay {
4852}
4953
5054impl ChannelDisplay {
55 /// update the style of the item (colours, etc), ran on ever render
5156 fn update_appearance(
5257 &mut self,
5358 info: &tui_additions::framework::ItemInfo,
@@ -95,6 +100,8 @@ impl ChannelDisplay {
95100 }
96101 }
97102
103 /// handles when select (enter) is pressed, generally loads the hovered item in a
104 /// `SingleItemPage`
98105 fn select_at_cursor(&self, framework: &mut FrameworkClean) {
99106 match self {
100107 Self::None | Self::Main { .. } => {}
@@ -144,6 +151,7 @@ impl ChannelDisplay {
144151 }
145152 }
146153
154 /// updates the video/playlist preview
147155 fn update(&mut self) {
148156 match self {
149157 Self::Videos {
@@ -168,6 +176,7 @@ impl ChannelDisplay {
168176 }
169177 }
170178
179 /// check if self should be able to be selected
171180 pub fn selectable(&self) -> bool {
172181 !(matches!(self, Self::Main { .. }) || matches!(self, Self::None))
173182 }
src/items/iteminfo.rs −1
@@ -74,7 +74,6 @@ impl FrameworkItem for ItemInfo {
7474 } as u32),
7575 x: area.x,
7676 y: area.y as i16,
77 #[cfg(feature = "sixel")]
7877 use_sixel: main_config.images.use_sixels(),
7978 ..Default::default()
8079 };
src/items/itemlist.rs +1
@@ -69,6 +69,7 @@ impl ItemList {
6969 }
7070 }
7171
72 /// handles select (enter)
7273 fn select_at_cursor(&self, framework: &mut FrameworkClean) {
7374 let page_to_load = match &self.items[self.textlist.selected] {
7475 Item::MiniVideo(MiniVideoItem { id, .. })
src/items/singleitem.rs +60 −72
@@ -2,14 +2,14 @@ use super::ItemInfo;
22use crate::{
33 config::{AppearanceConfig, CommandsConfig, KeyBindingsConfig, MainConfig, Provider},
44 global::{
5 functions::download_all_images,
5 functions::{apply_envs, download_all_images, set_envs},
66 structs::{
7 InvidiousClient, Item, KeyAction, Message, Page, SingleItemPage, Status, Task, Tasks,
8 WatchHistory,
7 InvidiousClient, Item, KeyAction, Message, Page, SingleItemPage, StateEnvs, Status,
8 Task, Tasks, WatchHistory,
99 },
1010 },
1111};
12use std::{collections::HashMap, thread};
12use std::thread;
1313use tui::{
1414 layout::{Constraint, Rect},
1515 style::Style,
@@ -126,10 +126,10 @@ impl SingleVideoItem {
126126 }
127127
128128 /// 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)> {
130130 let video_item = item.fullvideo().unwrap();
131131
132 HashMap::from([
132 vec![
133133 (
134134 String::from("url"),
135135 match self.provider {
@@ -151,9 +151,9 @@ impl SingleVideoItem {
151151 Provider::YouTube => format!("'https://youtube.com/embed/{}'", video_item.id),
152152 },
153153 ),
154 (String::from("channel_id"), video_item.channel_id.clone()),
154 (String::from("channel-id"), video_item.channel_id.clone()),
155155 (
156 String::from("channel_url"),
156 String::from("channel-url"),
157157 match self.provider {
158158 Provider::YouTube => {
159159 format!("https://www.youtube.com/channel/{}", video_item.channel_id)
@@ -164,18 +164,7 @@ impl SingleVideoItem {
164164 ),
165165 },
166166 ),
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
167 ]
179168 }
180169}
181170
@@ -288,9 +277,9 @@ impl SinglePlaylistItem {
288277 }
289278
290279 /// 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)> {
292281 let playlist_item = item.fullplaylist().unwrap();
293 HashMap::from([
282 vec![
294283 (
295284 String::from("url"),
296285 match self.provider {
@@ -329,9 +318,9 @@ impl SinglePlaylistItem {
329318 .join(" "),
330319 },
331320 ),
332 (String::from("channel_id"), playlist_item.channel_id.clone()),
321 (String::from("channel-id"), playlist_item.channel_id.clone()),
333322 (
334 String::from("channel_url"),
323 String::from("channel-url"),
335324 match self.provider {
336325 Provider::YouTube => format!(
337326 "https://www.youtube.com/channel/{}",
@@ -343,18 +332,7 @@ impl SinglePlaylistItem {
343332 ),
344333 },
345334 ),
346 ])
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
335 ]
358336 }
359337}
360338
@@ -377,6 +355,20 @@ impl SingleItemType {
377355 Self::Video(videoitem) => videoitem.update_appearance(appearance, iteminfo),
378356 }
379357 }
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 }
380372}
381373
382374impl SingleItem {
@@ -448,14 +440,8 @@ impl SingleItem {
448440 );
449441 }
450442 _ => {
451 let mainconfig = framework.data.global.get::<MainConfig>().unwrap();
452443 // joins the env from the one in mainconfig and video info
453 let env = singlevideoitem.inflate(
454 mainconfig.env.clone(),
455 mainconfig,
456 self.item.as_ref().unwrap(),
457 );
458 let command_string = apply_env(command_string, &env);
444 let command_string = apply_envs(command_string);
459445
460446 // check if the command starts with an ':' which case should be captured
461447 if &command_string[0..1] == ":" {
@@ -468,12 +454,13 @@ impl SingleItem {
468454 .push(Task::Command(command_string[1..].to_string()))
469455 }
470456
471 *framework.data.global.get_mut::<Message>().unwrap() =
472 Message::Success(command_string.clone());
473
474457 // this allows creating commands from string
475458 let mut command = execute::command(command_string);
476459
460 *framework.data.global.get_mut::<Message>().unwrap() = Message::Success(
461 format!("{:?} {:?}", command.get_program(), command.get_args()),
462 );
463
477464 // run the command in a new thread so it doesn't freeze the current one
478465 thread::spawn(move || {
479466 let _ = command.output();
@@ -504,13 +491,7 @@ impl SingleItem {
504491 }
505492 // same as before if string is not a special case then the run the command
506493 _ => {
507 let mainconfig = framework.data.global.get::<MainConfig>().unwrap();
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);
494 let command_string = apply_envs(command_string);
514495
515496 // check if the command starts with an ':' which case should be captured
516497 if &command_string[0..1] == ":" {
@@ -525,6 +506,7 @@ impl SingleItem {
525506
526507 *framework.data.global.get_mut::<Message>().unwrap() =
527508 Message::Success(command_string.clone());
509
528510 let mut command = execute::command(command_string);
529511
530512 thread::spawn(move || {
@@ -633,8 +615,8 @@ impl FrameworkItem for SingleItem {
633615 };
634616
635617 let client = &framework.data.global.get::<InvidiousClient>().unwrap().0;
636 let mainconfig = framework.data.global.get::<MainConfig>().unwrap();
637618
619 let mainconfig = framework.data.global.get::<MainConfig>().unwrap();
638620 // load items using the invidious api
639621 // gets the item that it needs to load from `data.state.Page`
640622 self.item = match r#type {
@@ -677,6 +659,10 @@ impl FrameworkItem for SingleItem {
677659 // need to update provider every time the item loads or else it will display `${provider}`
678660 // instead of the actual provider (e.g. `YouTube`)
679661 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 );
680666
681667 if let Some(item) = &self.item {
682668 if item.is_unknown() {
@@ -684,7 +670,12 @@ impl FrameworkItem for SingleItem {
684670 }
685671
686672 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;
688679
689680 // push to watch history
690681 let watch_history = framework.data.global.get_mut::<WatchHistory>().unwrap();
@@ -751,14 +742,7 @@ impl FrameworkItem for SingleItem {
751742 // checks if it is updated, if it is and selected is not 0 (is hovering on
752743 // a video), then also need to update the iteminfo
753744 KeyAction::MoveUp => {
754 let updated = singleplaylistitem.videos_view.up().is_ok();
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 {
745 if singleplaylistitem.videos_view.selected == 1 {
762746 // going from a hovering video to not hovering will make the image
763747 // stay on the screen, therefore it needs to be removed by clearing
764748 // the screen
@@ -770,7 +754,15 @@ impl FrameworkItem for SingleItem {
770754 .priority
771755 .push(Task::ClearPage);
772756 }
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
774766 }
775767 KeyAction::MoveDown => {
776768 let updated = singleplaylistitem.videos_view.down().is_ok();
@@ -889,6 +881,10 @@ impl FrameworkItem for SingleItem {
889881 if singleplaylistitem.is_commands_view {
890882 &mut singleplaylistitem.commands_view
891883 } 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 }
892888 &mut singleplaylistitem.videos_view
893889 }
894890 }
@@ -930,11 +926,3 @@ impl FrameworkItem for SingleItem {
930926 true
931927 }
932928}
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;
88pub use run::*;
99mod exit;
1010pub use exit::*;
11mod eggs;
12pub use eggs::*;
src/main.rs +11 −3
@@ -3,10 +3,10 @@ use crossterm::{
33 execute,
44 terminal::{disable_raw_mode, enable_raw_mode, EnterAlternateScreen, LeaveAlternateScreen},
55};
6use std::{error::Error, io};
6use std::{env, error::Error, io};
77use tui::{backend::CrosstermBackend, Terminal};
88use tui_additions::framework::{Framework, State};
9use youtube_tui::{exit, init, run};
9use youtube_tui::{exit, global::functions::text_command, init, run};
1010
1111// stuff happening:
1212// 1. setup the terminal
@@ -14,6 +14,14 @@ use youtube_tui::{exit, init, run};
1414// 3. restore the terminal
1515// 4. unwrap errors
1616fn 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
1725 let state = State(Vec::new());
1826 let mut framework = Framework::new(state);
1927
@@ -24,7 +32,7 @@ fn main() -> Result<(), Box<dyn Error>> {
2432 let mut terminal = Terminal::new(backend)?;
2533
2634 let res = (|| -> Result<(), Box<dyn Error>> {
27 init(&mut framework, &mut terminal)?;
35 init(&mut framework, &mut terminal, &args_strs)?;
2836 run(&mut terminal, &mut framework)?;
2937 Ok(())
3038 })();
src/run.rs +10 −2
@@ -9,8 +9,8 @@ use tui_additions::{
99use crate::{
1010 config::{KeyBindingsConfig, MainConfig},
1111 global::{
12 functions::command_capture,
13 structs::{KeyAction, Message, Status, Task, Tasks},
12 functions::{clear_envs, command_capture, set_envs},
13 structs::{KeyAction, Message, StateEnvs, Status, Task, Tasks},
1414 },
1515};
1616
@@ -183,6 +183,11 @@ pub fn run(
183183 .priority
184184 .push(Task::Reload),
185185 KeyAction::Back => {
186 if !framework.history.is_empty() {
187 clear_envs(
188 &mut framework.data.state.get::<StateEnvs>().unwrap().0.clone(),
189 );
190 }
186191 if framework.revert_last_history().is_err() {
187192 *framework.data.global.get_mut::<Message>().unwrap() =
188193 Message::Error(String::from(
@@ -202,6 +207,9 @@ pub fn run(
202207 .unwrap()
203208 .priority
204209 .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);
205213 }
206214 }
207215 KeyAction::FirstHistory => {