From 4d0112ed865a70020e9570ed3dd6d531ae27d758 Mon Sep 17 00:00:00 2001 From: Zastian Pretorius Date: Wed, 11 Jan 2023 00:50:19 +0000 Subject: [PATCH 1/4] added basic image support --- Cargo.lock | 579 ++++++++++++++++++++++++++++++++++++++++++- Cargo.toml | 1 + src/anime/anime.rs | 70 +++++- src/anime/scraper.rs | 21 +- 4 files changed, 649 insertions(+), 22 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index e9b4d3d..ef1e9ac 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2,6 +2,12 @@ # It is not intended for manual editing. version = 3 +[[package]] +name = "adler" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" + [[package]] name = "aho-corasick" version = "0.7.18" @@ -11,6 +17,15 @@ dependencies = [ "memchr", ] +[[package]] +name = "ansi_colours" +version = "1.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7db9d9767fde724f83933a716ee182539788f293828244e9d999695ce0f7ba1e" +dependencies = [ + "rgb", +] + [[package]] name = "async-channel" version = "1.6.1" @@ -28,7 +43,7 @@ version = "0.2.14" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8" dependencies = [ - "hermit-abi", + "hermit-abi 0.1.19", "libc", "winapi 0.3.9", ] @@ -45,12 +60,30 @@ version = "0.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "904dfeac50f3cdaba28fc6f57fdcddb75f49ed61346676a78c4ffe55877802fd" +[[package]] +name = "bit_field" +version = "0.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dcb6dd1c2376d2e096796e234a70e17e94cc2d5d54ff8ce42b28cef1d0d359a4" + [[package]] name = "bitflags" version = "1.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" +[[package]] +name = "bumpalo" +version = "3.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "572f695136211188308f16ad2ca5c851a712c464060ae6974944458eb83880ba" + +[[package]] +name = "bytemuck" +version = "1.12.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "aaa3a8d9a1ca92e282c96a32d6511b695d7d994d1d102ba85d279f9b2756947f" + [[package]] name = "byteorder" version = "1.4.3" @@ -93,6 +126,12 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" +[[package]] +name = "color_quant" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3d7b894f5411737b7867f4827955924d7c254fc9f4d91a6aad6b097804b1018b" + [[package]] name = "colored" version = "2.0.0" @@ -113,6 +152,61 @@ dependencies = [ "cache-padded", ] +[[package]] +name = "console" +version = "0.15.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c9b6515d269224923b26b5febea2ed42b2d5f2ce37284a4dd670fedd6cb8347a" +dependencies = [ + "encode_unicode", + "lazy_static", + "libc", + "windows-sys 0.42.0", +] + +[[package]] +name = "crc32fast" +version = "1.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b540bd8bc810d3885c6ea91e2018302f68baba2129ab3e88f32389ee9370880d" +dependencies = [ + "cfg-if", +] + +[[package]] +name = "crossbeam-channel" +version = "0.5.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c2dd04ddaf88237dc3b8d8f9a3c1004b506b54b3313403944054d23c0870c521" +dependencies = [ + "cfg-if", + "crossbeam-utils", +] + +[[package]] +name = "crossbeam-deque" +version = "0.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "715e8152b692bba2d374b53d4875445368fdf21a94751410af607a5ac677d1fc" +dependencies = [ + "cfg-if", + "crossbeam-epoch", + "crossbeam-utils", +] + +[[package]] +name = "crossbeam-epoch" +version = "0.9.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "01a9af1f4c2ef74bb8aa1f7e19706bc72d03598c8a570bb5de72243c7a9d9d5a" +dependencies = [ + "autocfg", + "cfg-if", + "crossbeam-utils", + "memoffset", + "scopeguard", +] + [[package]] name = "crossbeam-utils" version = "0.8.8" @@ -155,6 +249,22 @@ dependencies = [ "winapi 0.3.9", ] +[[package]] +name = "crossterm" +version = "0.25.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e64e6c0fbe2c17357405f7c758c1ef960fce08bdfb2c03d88d2a18d7e09c4b67" +dependencies = [ + "bitflags", + "crossterm_winapi", + "libc", + "mio", + "parking_lot", + "signal-hook", + "signal-hook-mio", + "winapi 0.3.9", +] + [[package]] name = "crossterm_winapi" version = "0.9.0" @@ -164,6 +274,12 @@ dependencies = [ "winapi 0.3.9", ] +[[package]] +name = "crunchy" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7a81dae078cea95a014a339291cec439d2f232ebe854a9d672b796c6afafa9b7" + [[package]] name = "curl" version = "0.4.43" @@ -221,6 +337,12 @@ version = "1.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "90e5c1c8368803113bf0c9584fc495a58b86dc8a29edbf8fe877d21d9507e797" +[[package]] +name = "encode_unicode" +version = "0.3.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a357d28ed41a50f9c765dbfe56cbc04a64e53e5fc58ba79fbc34c10ef3df831f" + [[package]] name = "encoding_rs" version = "0.8.31" @@ -236,6 +358,21 @@ version = "2.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "77f3309417938f28bf8228fcff79a4a37103981e3e186d2ccd19c74b38f4eb71" +[[package]] +name = "exr" +version = "1.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8eb5f255b5980bb0c8cf676b675d1a99be40f316881444f44e0462eaf5df5ded" +dependencies = [ + "bit_field", + "flume", + "half", + "lebe", + "miniz_oxide", + "smallvec", + "threadpool", +] + [[package]] name = "fastrand" version = "1.7.0" @@ -245,6 +382,29 @@ dependencies = [ "instant", ] +[[package]] +name = "flate2" +version = "1.0.25" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a8a2db397cb1c8772f31494cb8917e48cd1e64f0fa7efac59fbd741a0a8ce841" +dependencies = [ + "crc32fast", + "miniz_oxide", +] + +[[package]] +name = "flume" +version = "0.10.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1657b4441c3403d9f7b3409e47575237dac27b1b5726df654a6ecbf92f0f7577" +dependencies = [ + "futures-core", + "futures-sink", + "nanorand", + "pin-project", + "spin", +] + [[package]] name = "fnv" version = "1.0.7" @@ -303,6 +463,12 @@ dependencies = [ "waker-fn", ] +[[package]] +name = "futures-sink" +version = "0.3.25" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "39c15cf1a4aa79df40f1bb462fb39676d0ad9e366c2a33b590d7c66f4f81fcf9" + [[package]] name = "getrandom" version = "0.2.7" @@ -310,8 +476,29 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4eb1a864a501629691edf6c15a593b7a51eebaa1e8468e9ddc623de7c9b58ec6" dependencies = [ "cfg-if", + "js-sys", "libc", "wasi", + "wasm-bindgen", +] + +[[package]] +name = "gif" +version = "0.11.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3edd93c6756b4dfaf2709eafcc345ba2636565295c198a9cfbf75fa5e3e00b06" +dependencies = [ + "color_quant", + "weezl", +] + +[[package]] +name = "half" +version = "2.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "02b4af3693f1b705df946e9fe5631932443781d0aabb423b62fcd4d73f6d2fd0" +dependencies = [ + "crunchy", ] [[package]] @@ -323,6 +510,15 @@ dependencies = [ "libc", ] +[[package]] +name = "hermit-abi" +version = "0.2.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ee512640fe35acbfb4bb779db6f0d80704c2cacfa2e39b601ef3e3f47d1ae4c7" +dependencies = [ + "libc", +] + [[package]] name = "http" version = "0.2.8" @@ -345,6 +541,25 @@ dependencies = [ "unicode-normalization", ] +[[package]] +name = "image" +version = "0.24.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "69b7ea949b537b0fd0af141fff8c77690f2ce96f4f41f042ccb6c69c6c965945" +dependencies = [ + "bytemuck", + "byteorder", + "color_quant", + "exr", + "gif", + "jpeg-decoder", + "num-rational", + "num-traits", + "png", + "scoped_threadpool", + "tiff", +] + [[package]] name = "instant" version = "0.1.12" @@ -387,6 +602,24 @@ version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "112c678d4050afce233f4f2852bb2eb519230b3cf12f33585275537d7e41578d" +[[package]] +name = "jpeg-decoder" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bc0000e42512c92e31c2252315bda326620a4e034105e900c98ec492fa077b3e" +dependencies = [ + "rayon", +] + +[[package]] +name = "js-sys" +version = "0.3.60" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "49409df3e3bf0856b916e2ceaca09ee28e6871cf7d9ce97a692cacfdb2a25a47" +dependencies = [ + "wasm-bindgen", +] + [[package]] name = "kami" version = "0.6.0" @@ -402,6 +635,7 @@ dependencies = [ "termsize", "tui", "unicode-width", + "viuer", ] [[package]] @@ -420,6 +654,12 @@ version = "1.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" +[[package]] +name = "lebe" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "03087c2bad5e1034e8cace5926dec053fb3790248370865f5117a7d0213354c8" + [[package]] name = "libc" version = "0.2.126" @@ -467,6 +707,12 @@ dependencies = [ "cfg-if", ] +[[package]] +name = "make-cmd" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a8ca8afbe8af1785e09636acb5a41e08a765f5f0340568716c18a8700ba3c0d3" + [[package]] name = "matches" version = "0.1.9" @@ -479,12 +725,30 @@ version = "2.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d" +[[package]] +name = "memoffset" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5de893c32cde5f383baa4c04c5d6dbdd735cfd4a794b0debdb2bb1b421da5ff4" +dependencies = [ + "autocfg", +] + [[package]] name = "mime" version = "0.3.16" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2a60c7ce501c71e03a9c9c0d35b861413ae925bd979cc7a4e30d060069aaac8d" +[[package]] +name = "miniz_oxide" +version = "0.6.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b275950c28b37e794e8c55d88aeb5e139d0ce23fdbbeda68f8d7174abdf9e8fa" +dependencies = [ + "adler", +] + [[package]] name = "mio" version = "0.8.4" @@ -494,7 +758,56 @@ dependencies = [ "libc", "log", "wasi", - "windows-sys", + "windows-sys 0.36.1", +] + +[[package]] +name = "nanorand" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6a51313c5820b0b02bd422f4b44776fbf47961755c74ce64afc73bfad10226c3" +dependencies = [ + "getrandom", +] + +[[package]] +name = "num-integer" +version = "0.1.45" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "225d3389fb3509a24c93f5c29eb6bde2586b98d9f016636dff58d7c6f7569cd9" +dependencies = [ + "autocfg", + "num-traits", +] + +[[package]] +name = "num-rational" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0638a1c9d0a3c0914158145bc76cff373a75a627e6ecbfb71cbe6f453a5a19b0" +dependencies = [ + "autocfg", + "num-integer", + "num-traits", +] + +[[package]] +name = "num-traits" +version = "0.2.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "578ede34cf02f8924ab9447f50c28075b4d3e5b269972345e7e0372b38c6cdcd" +dependencies = [ + "autocfg", +] + +[[package]] +name = "num_cpus" +version = "1.15.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fac9e2da13b5eb447a6ce3d392f23a29d8694bff781bf03a16cd9ac8697593b" +dependencies = [ + "hermit-abi 0.2.6", + "libc", ] [[package]] @@ -580,7 +893,7 @@ dependencies = [ "libc", "redox_syscall", "smallvec", - "windows-sys", + "windows-sys 0.36.1", ] [[package]] @@ -621,6 +934,18 @@ version = "0.3.25" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1df8c4ec4b0627e53bdf214615ad287367e482558cf84b109250b37464dc03ae" +[[package]] +name = "png" +version = "0.17.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5d708eaf860a19b19ce538740d2b4bdeeb8337fa53f7738455e706623ad5c638" +dependencies = [ + "bitflags", + "crc32fast", + "flate2", + "miniz_oxide", +] + [[package]] name = "polling" version = "2.2.0" @@ -689,6 +1014,28 @@ dependencies = [ "proc-macro2", ] +[[package]] +name = "rayon" +version = "1.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6db3a213adf02b3bcfd2d3846bb41cb22857d131789e01df434fb7e7bc0759b7" +dependencies = [ + "either", + "rayon-core", +] + +[[package]] +name = "rayon-core" +version = "1.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cac410af5d00ab6884528b4ab69d1e8e146e8d471201800fa1b4524126de6ad3" +dependencies = [ + "crossbeam-channel", + "crossbeam-deque", + "crossbeam-utils", + "num_cpus", +] + [[package]] name = "redox_syscall" version = "0.2.13" @@ -744,6 +1091,15 @@ dependencies = [ "winapi 0.3.9", ] +[[package]] +name = "rgb" +version = "0.8.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3603b7d71ca82644f79b5a06d1220e9a58ede60bd32255f698cb1af8838b8db3" +dependencies = [ + "bytemuck", +] + [[package]] name = "rust_cast" version = "0.17.0" @@ -773,9 +1129,15 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "88d6731146462ea25d9244b2ed5fd1d716d25c52e4d54aa4fb0f3c4e9854dbe2" dependencies = [ "lazy_static", - "windows-sys", + "windows-sys 0.36.1", ] +[[package]] +name = "scoped_threadpool" +version = "0.1.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1d51f5df5af43ab3f1360b429fa5e0152ac5ce8c0bd6485cae490332e96846a8" + [[package]] name = "scopeguard" version = "1.1.0" @@ -840,6 +1202,24 @@ dependencies = [ "libc", ] +[[package]] +name = "sixel-rs" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cfa95c014543113a192d906e5971d0c8d1e8b4cc1e61026539687a7016644ce5" +dependencies = [ + "sixel-sys", +] + +[[package]] +name = "sixel-sys" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fb46e0cd5569bf910390844174a5a99d52dd40681fff92228d221d9f8bf87dea" +dependencies = [ + "make-cmd", +] + [[package]] name = "slab" version = "0.4.6" @@ -873,6 +1253,15 @@ dependencies = [ "winapi 0.3.9", ] +[[package]] +name = "spin" +version = "0.9.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7f6002a767bff9e83f8eeecf883ecb8011875a21ae8da43bffb817a57e78cc09" +dependencies = [ + "lock_api", +] + [[package]] name = "syn" version = "1.0.96" @@ -898,6 +1287,15 @@ dependencies = [ "winapi 0.3.9", ] +[[package]] +name = "termcolor" +version = "1.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bab24d30b911b2376f3a13cc2cd443142f0c81dda04c118693e35b3835757755" +dependencies = [ + "winapi-util", +] + [[package]] name = "termion" version = "1.5.6" @@ -943,6 +1341,26 @@ dependencies = [ "syn", ] +[[package]] +name = "threadpool" +version = "1.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d050e60b33d41c19108b32cea32164033a9013fe3b46cbd4457559bfbf77afaa" +dependencies = [ + "num_cpus", +] + +[[package]] +name = "tiff" +version = "0.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7449334f9ff2baf290d55d73983a7d6fa15e01198faef72af07e2a8db851e471" +dependencies = [ + "flate2", + "jpeg-decoder", + "weezl", +] + [[package]] name = "tinyvec" version = "1.6.0" @@ -1065,6 +1483,23 @@ version = "0.2.15" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426" +[[package]] +name = "viuer" +version = "0.6.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b511f7e9ae27b5750f12ca50c353a1179bd4cc964a47294eb0d2cdad40cb41c0" +dependencies = [ + "ansi_colours", + "base64", + "console", + "crossterm 0.25.0", + "image", + "lazy_static", + "sixel-rs", + "tempfile", + "termcolor", +] + [[package]] name = "waker-fn" version = "1.1.0" @@ -1077,6 +1512,66 @@ version = "0.11.0+wasi-snapshot-preview1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" +[[package]] +name = "wasm-bindgen" +version = "0.2.83" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eaf9f5aceeec8be17c128b2e93e031fb8a4d469bb9c4ae2d7dc1888b26887268" +dependencies = [ + "cfg-if", + "wasm-bindgen-macro", +] + +[[package]] +name = "wasm-bindgen-backend" +version = "0.2.83" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4c8ffb332579b0557b52d268b91feab8df3615f265d5270fec2a8c95b17c1142" +dependencies = [ + "bumpalo", + "log", + "once_cell", + "proc-macro2", + "quote", + "syn", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-macro" +version = "0.2.83" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "052be0f94026e6cbc75cdefc9bae13fd6052cdcaf532fa6c45e7ae33a1e6c810" +dependencies = [ + "quote", + "wasm-bindgen-macro-support", +] + +[[package]] +name = "wasm-bindgen-macro-support" +version = "0.2.83" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "07bc0c051dc5f23e307b13285f9d75df86bfdf816c5721e573dec1f9b8aa193c" +dependencies = [ + "proc-macro2", + "quote", + "syn", + "wasm-bindgen-backend", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-shared" +version = "0.2.83" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1c38c045535d93ec4f0b4defec448e4291638ee608530863b1e2ba115d4fff7f" + +[[package]] +name = "weezl" +version = "0.1.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9193164d4de03a926d909d3bc7c30543cecb35400c02114792c2cae20d5e2dbb" + [[package]] name = "wepoll-ffi" version = "0.1.2" @@ -1125,6 +1620,15 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" +[[package]] +name = "winapi-util" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "70ec6ce85bb158151cae5e5c87f95a8e97d2c0c4b001223f33a334e3ce5de178" +dependencies = [ + "winapi 0.3.9", +] + [[package]] name = "winapi-x86_64-pc-windows-gnu" version = "0.4.0" @@ -1137,39 +1641,96 @@ version = "0.36.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ea04155a16a59f9eab786fe12a4a450e75cdb175f9e0d80da1e17db09f55b8d2" dependencies = [ - "windows_aarch64_msvc", - "windows_i686_gnu", - "windows_i686_msvc", - "windows_x86_64_gnu", - "windows_x86_64_msvc", + "windows_aarch64_msvc 0.36.1", + "windows_i686_gnu 0.36.1", + "windows_i686_msvc 0.36.1", + "windows_x86_64_gnu 0.36.1", + "windows_x86_64_msvc 0.36.1", ] +[[package]] +name = "windows-sys" +version = "0.42.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5a3e1820f08b8513f676f7ab6c1f99ff312fb97b553d30ff4dd86f9f15728aa7" +dependencies = [ + "windows_aarch64_gnullvm", + "windows_aarch64_msvc 0.42.0", + "windows_i686_gnu 0.42.0", + "windows_i686_msvc 0.42.0", + "windows_x86_64_gnu 0.42.0", + "windows_x86_64_gnullvm", + "windows_x86_64_msvc 0.42.0", +] + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.42.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "41d2aa71f6f0cbe00ae5167d90ef3cfe66527d6f613ca78ac8024c3ccab9a19e" + [[package]] name = "windows_aarch64_msvc" version = "0.36.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9bb8c3fd39ade2d67e9874ac4f3db21f0d710bee00fe7cab16949ec184eeaa47" +[[package]] +name = "windows_aarch64_msvc" +version = "0.42.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dd0f252f5a35cac83d6311b2e795981f5ee6e67eb1f9a7f64eb4500fbc4dcdb4" + [[package]] name = "windows_i686_gnu" version = "0.36.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "180e6ccf01daf4c426b846dfc66db1fc518f074baa793aa7d9b9aaeffad6a3b6" +[[package]] +name = "windows_i686_gnu" +version = "0.42.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fbeae19f6716841636c28d695375df17562ca208b2b7d0dc47635a50ae6c5de7" + [[package]] name = "windows_i686_msvc" version = "0.36.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e2e7917148b2812d1eeafaeb22a97e4813dfa60a3f8f78ebe204bcc88f12f024" +[[package]] +name = "windows_i686_msvc" +version = "0.42.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "84c12f65daa39dd2babe6e442988fc329d6243fdce47d7d2d155b8d874862246" + [[package]] name = "windows_x86_64_gnu" version = "0.36.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4dcd171b8776c41b97521e5da127a2d86ad280114807d0b2ab1e462bc764d9e1" +[[package]] +name = "windows_x86_64_gnu" +version = "0.42.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bf7b1b21b5362cbc318f686150e5bcea75ecedc74dd157d874d754a2ca44b0ed" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.42.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09d525d2ba30eeb3297665bd434a54297e4170c7f1a44cad4ef58095b4cd2028" + [[package]] name = "windows_x86_64_msvc" version = "0.36.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c811ca4a8c853ef420abd8592ba53ddbbac90410fab6903b3e79972a631f7680" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.42.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f40009d85759725a34da6d89a94e63d7bdc50a862acf0dbc7c8e488f1edcb6f5" diff --git a/Cargo.toml b/Cargo.toml index 3841a4c..36eb959 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -19,3 +19,4 @@ tui = "0.18.0" crossterm = "0.24.0" unicode-width = "0.1.9" rust_cast = "0.17.0" +viuer = { version = "0.6", features = ["sixel"] } diff --git a/src/anime/anime.rs b/src/anime/anime.rs index 1f34c10..c1ac9b9 100644 --- a/src/anime/anime.rs +++ b/src/anime/anime.rs @@ -2,7 +2,7 @@ use crate::{ get_an_progress, get_anime_id, get_user_anime_progress, update_anime_progress, write_an_progress, }; -use crate::{get_anime_link, get_animes}; +use crate::{get_anime_link, get_animes, get_image}; use crate::{open_cast, open_video}; use crossterm::{ @@ -20,6 +20,7 @@ use tui::{ Frame, Terminal, }; use unicode_width::UnicodeWidthStr; +use viuer::{print_from_file, terminal_size, Config}; use super::scraper::get_anime_info; @@ -83,7 +84,7 @@ impl StatefulList { struct App { /// Current value of the input box input: String, - animes: (Vec, Vec), + animes: (Vec, Vec, Vec), /// Current input mode input_mode: InputMode, /// History of recorded messages @@ -102,7 +103,7 @@ impl<'a> App { fn default() -> App { App { input: String::new(), - animes: (Vec::new(), Vec::new()), + animes: (Vec::new(), Vec::new(), Vec::new()), input_mode: InputMode::Normal, messages: StatefulList::with_items(Vec::new()), title: String::new(), @@ -134,7 +135,19 @@ pub fn anime_ui( app.token = token; app.provider = provider; app.cast = cast; - let res = run_app(&mut terminal, app); + let (term_width, _term_height) = terminal_size(); + let width = 50; + let height = 24; + let conf = Config { + // set dimensions + x: (term_width - 33), + y: 2, + width: Some((width) as u32), + height: Some((height) as u32), + restore_cursor: true, + ..Default::default() + }; + let res = run_app(&mut terminal, app, conf); // restore terminal disable_raw_mode()?; @@ -152,8 +165,15 @@ pub fn anime_ui( Ok(()) } -fn run_app(terminal: &mut Terminal, mut app: App) -> io::Result<()> { +fn run_app(terminal: &mut Terminal, mut app: App, conf: Config) -> io::Result<()> { let mut ep_select = false; + fn change_image(conf: &Config, app: &App) { + let selected = app.messages.state.selected(); + let image_url = app.animes.2[selected.unwrap()].clone(); + get_image(&image_url); + print_from_file("/home/mrfluffy/.config/kami/temp.png", &conf) + .expect("Image printing failed."); + } loop { terminal.draw(|f| ui(f, &mut app))?; @@ -168,10 +188,22 @@ fn run_app(terminal: &mut Terminal, mut app: App) -> io::Result<( } KeyCode::Left => app.messages.unselect(), KeyCode::Char('h') => app.messages.unselect(), - KeyCode::Down => app.messages.next(), - KeyCode::Char('j') => app.messages.next(), - KeyCode::Up => app.messages.previous(), - KeyCode::Char('k') => app.messages.previous(), + KeyCode::Down => { + app.messages.next(); + change_image(&conf, &app); + } + KeyCode::Char('j') => { + app.messages.next(); + change_image(&conf, &app) + } + KeyCode::Up => { + app.messages.previous(); + change_image(&conf, &app); + } + KeyCode::Char('k') => { + app.messages.previous(); + change_image(&conf, &app) + } //if KeyCode::Enter => { KeyCode::Enter => { if ep_select == false { @@ -286,12 +318,18 @@ fn ui(f: &mut Frame, app: &mut App) { .as_ref(), ) .split(f.size()); + let block = Block::default() .borders(Borders::ALL) .title("kami") .border_type(BorderType::Rounded); f.render_widget(block, f.size()); + let top_chunks = Layout::default() + .direction(Direction::Horizontal) + .constraints([Constraint::Percentage(50), Constraint::Percentage(50)].as_ref()) + .split(chunks[0]); + let (msg, style) = match app.input_mode { InputMode::Normal => ( vec![ @@ -325,7 +363,12 @@ fn ui(f: &mut Frame, app: &mut App) { }) .collect(); let messages = List::new(messages) - .block(Block::default().borders(Borders::ALL).title("list")) + .block( + Block::default() + .borders(Borders::ALL) + .title("list") + .border_type(BorderType::Rounded), + ) .style(Style::default().fg(Color::White)) .highlight_style( Style::default() @@ -333,7 +376,12 @@ fn ui(f: &mut Frame, app: &mut App) { .add_modifier(Modifier::BOLD), ) .highlight_symbol(">>"); - f.render_stateful_widget(messages, chunks[0], &mut app.messages.state); + f.render_stateful_widget(messages, top_chunks[0], &mut app.messages.state); + let block = Block::default() + .borders(Borders::ALL) + .title("info") + .border_type(BorderType::Rounded); + f.render_widget(block, top_chunks[1]); let mut text = Text::from(Spans::from(msg)); text.patch_style(style); diff --git a/src/anime/scraper.rs b/src/anime/scraper.rs index 48df123..2c1eb1a 100644 --- a/src/anime/scraper.rs +++ b/src/anime/scraper.rs @@ -1,6 +1,9 @@ use isahc::config::Configurable; use isahc::{ReadResponseExt, Request, RequestExt}; use regex::Regex; +use std::fs::File; +use std::io::prelude::*; + //use serde_json::json; pub fn get_anime_html(url: &str) -> String { @@ -30,7 +33,7 @@ pub fn get_post(id: &str) -> String { resp } -pub fn get_animes(query: String) -> (Vec, Vec) { +pub fn get_animes(query: String) -> (Vec, Vec, Vec) { let query = query.replace(" ", "+"); let html = get_anime_html(&format!("https://yugen.to/search/?q={}", query)); let re = Regex::new(r#"href="(/anime[^"]*)""#).unwrap(); @@ -43,7 +46,12 @@ pub fn get_animes(query: String) -> (Vec, Vec) { for cap in re.captures_iter(&html) { animes_names.push(cap[1].to_string()); } - (animes_links, animes_names) + let re = Regex::new(r#"data-src="([^"]*)"#).unwrap(); + let mut animes_images = Vec::new(); + for cap in re.captures_iter(&html) { + animes_images.push(cap[1].to_string()); + } + (animes_links, animes_names, animes_images) } pub fn get_anime_info(url: &str) -> (i32, u16) { @@ -77,3 +85,12 @@ pub fn get_anime_link(url: &str, episode: u64) -> String { //return the link link.to_string() } + +pub fn get_image(url: &str) { + let url = url; + let mut response = isahc::get(url).unwrap(); + let mut buffer = Vec::new(); + response.copy_to(&mut buffer).unwrap(); + let mut file = File::create("/home/mrfluffy/.config/kami/temp.png").unwrap(); + file.write_all(&buffer).unwrap(); +} From d716fa1d499dc91b221bdb5fa79f2cc40c8e2ae6 Mon Sep 17 00:00:00 2001 From: Zastian Pretorius Date: Wed, 11 Jan 2023 01:00:17 +0000 Subject: [PATCH 2/4] made image path dinamic --- src/anime/anime.rs | 7 ++++--- src/anime/scraper.rs | 4 ++-- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/anime/anime.rs b/src/anime/anime.rs index c1ac9b9..3329cdb 100644 --- a/src/anime/anime.rs +++ b/src/anime/anime.rs @@ -168,11 +168,12 @@ pub fn anime_ui( fn run_app(terminal: &mut Terminal, mut app: App, conf: Config) -> io::Result<()> { let mut ep_select = false; fn change_image(conf: &Config, app: &App) { + let config_path = dirs::config_dir().unwrap().join("kami"); + let image_path = config_path.join("tmp.jpg"); let selected = app.messages.state.selected(); let image_url = app.animes.2[selected.unwrap()].clone(); - get_image(&image_url); - print_from_file("/home/mrfluffy/.config/kami/temp.png", &conf) - .expect("Image printing failed."); + get_image(&image_url, &image_path.to_str().unwrap()); + print_from_file(image_path, &conf).expect("Image printing failed."); } loop { terminal.draw(|f| ui(f, &mut app))?; diff --git a/src/anime/scraper.rs b/src/anime/scraper.rs index 2c1eb1a..2f43f8d 100644 --- a/src/anime/scraper.rs +++ b/src/anime/scraper.rs @@ -86,11 +86,11 @@ pub fn get_anime_link(url: &str, episode: u64) -> String { link.to_string() } -pub fn get_image(url: &str) { +pub fn get_image(url: &str, path: &str) { let url = url; let mut response = isahc::get(url).unwrap(); let mut buffer = Vec::new(); response.copy_to(&mut buffer).unwrap(); - let mut file = File::create("/home/mrfluffy/.config/kami/temp.png").unwrap(); + let mut file = File::create(path).unwrap(); file.write_all(&buffer).unwrap(); } From 7fc96dce6090cdc233c8645830c62c4e3e97af8b Mon Sep 17 00:00:00 2001 From: Zastian Pretorius Date: Mon, 16 Jan 2023 21:18:22 +0000 Subject: [PATCH 3/4] added state check to navigation for images --- src/anime/anime.rs | 51 +++++++++++++++++++++++++++++++++------------- 1 file changed, 37 insertions(+), 14 deletions(-) diff --git a/src/anime/anime.rs b/src/anime/anime.rs index 3329cdb..5d8e2a0 100644 --- a/src/anime/anime.rs +++ b/src/anime/anime.rs @@ -190,21 +190,44 @@ fn run_app(terminal: &mut Terminal, mut app: App, conf: Config) - KeyCode::Left => app.messages.unselect(), KeyCode::Char('h') => app.messages.unselect(), KeyCode::Down => { - app.messages.next(); - change_image(&conf, &app); - } - KeyCode::Char('j') => { - app.messages.next(); - change_image(&conf, &app) - } - KeyCode::Up => { - app.messages.previous(); - change_image(&conf, &app); - } - KeyCode::Char('k') => { - app.messages.previous(); - change_image(&conf, &app) + //match ep_select + match ep_select { + true => { + app.messages.next(); + } + false => { + app.messages.next(); + change_image(&conf, &app); + } + } } + KeyCode::Char('j') => match ep_select { + true => { + app.messages.next(); + } + false => { + app.messages.next(); + change_image(&conf, &app); + } + }, + KeyCode::Up => match ep_select { + true => { + app.messages.previous(); + } + false => { + app.messages.previous(); + change_image(&conf, &app); + } + }, + KeyCode::Char('k') => match ep_select { + true => { + app.messages.previous(); + } + false => { + app.messages.previous(); + change_image(&conf, &app); + } + }, //if KeyCode::Enter => { KeyCode::Enter => { if ep_select == false { From 6b58d42af715341a976076cc6a554147c84923bf Mon Sep 17 00:00:00 2001 From: Zastian Pretorius Date: Mon, 16 Jan 2023 22:16:24 +0000 Subject: [PATCH 4/4] dynamic image sizing --- src/anime/anime.rs | 69 ++++++++++++++++++++++++++-------------------- 1 file changed, 39 insertions(+), 30 deletions(-) diff --git a/src/anime/anime.rs b/src/anime/anime.rs index 5d8e2a0..d909483 100644 --- a/src/anime/anime.rs +++ b/src/anime/anime.rs @@ -135,19 +135,7 @@ pub fn anime_ui( app.token = token; app.provider = provider; app.cast = cast; - let (term_width, _term_height) = terminal_size(); - let width = 50; - let height = 24; - let conf = Config { - // set dimensions - x: (term_width - 33), - y: 2, - width: Some((width) as u32), - height: Some((height) as u32), - restore_cursor: true, - ..Default::default() - }; - let res = run_app(&mut terminal, app, conf); + let res = run_app(&mut terminal, app); // restore terminal disable_raw_mode()?; @@ -165,15 +153,39 @@ pub fn anime_ui( Ok(()) } -fn run_app(terminal: &mut Terminal, mut app: App, conf: Config) -> io::Result<()> { +fn run_app(terminal: &mut Terminal, mut app: App) -> io::Result<()> { let mut ep_select = false; - fn change_image(conf: &Config, app: &App) { + fn change_image(app: &App) { + //save as f32 + let (width, height) = terminal_size().to_owned(); + let width = width as f32; + let height = height as f32; + let sixel_support = viuer::is_sixel_supported(); + let config = match sixel_support { + true => Config { + x: ((width / 2.0) + 1.0).round() as u16, + y: 2, + width: Some((width / 1.3).round() as u32), + height: Some((height * 1.5) as u32), + restore_cursor: true, + ..Default::default() + }, + false => Config { + x: ((width / 2.0) + 1.0).round() as u16, + y: 2, + width: Some(((width / 2.0) - 4.0).round() as u32), + height: Some((height / 1.3).round() as u32), + restore_cursor: true, + ..Default::default() + }, + }; + let config_path = dirs::config_dir().unwrap().join("kami"); let image_path = config_path.join("tmp.jpg"); let selected = app.messages.state.selected(); let image_url = app.animes.2[selected.unwrap()].clone(); get_image(&image_url, &image_path.to_str().unwrap()); - print_from_file(image_path, &conf).expect("Image printing failed."); + print_from_file(image_path, &config).expect("Image printing failed."); } loop { terminal.draw(|f| ui(f, &mut app))?; @@ -189,25 +201,22 @@ fn run_app(terminal: &mut Terminal, mut app: App, conf: Config) - } KeyCode::Left => app.messages.unselect(), KeyCode::Char('h') => app.messages.unselect(), - KeyCode::Down => { - //match ep_select - match ep_select { - true => { - app.messages.next(); - } - false => { - app.messages.next(); - change_image(&conf, &app); - } + KeyCode::Down => match ep_select { + true => { + app.messages.next(); } - } + false => { + app.messages.next(); + change_image(&app); + } + }, KeyCode::Char('j') => match ep_select { true => { app.messages.next(); } false => { app.messages.next(); - change_image(&conf, &app); + change_image(&app); } }, KeyCode::Up => match ep_select { @@ -216,7 +225,7 @@ fn run_app(terminal: &mut Terminal, mut app: App, conf: Config) - } false => { app.messages.previous(); - change_image(&conf, &app); + change_image(&app); } }, KeyCode::Char('k') => match ep_select { @@ -225,7 +234,7 @@ fn run_app(terminal: &mut Terminal, mut app: App, conf: Config) - } false => { app.messages.previous(); - change_image(&conf, &app); + change_image(&app); } }, //if KeyCode::Enter => {