mirror of
https://github.com/mrfluffy-dev/kami.git
synced 2026-01-17 12:50:32 +00:00
Compare commits
28 Commits
img
...
newbee1905
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c2ca356940 | ||
|
|
676edb1d98 | ||
|
|
21f81cb68d | ||
|
|
7b605f40b8 | ||
|
|
578e773b04 | ||
|
|
3ebb06cc1b | ||
|
|
ba8c24dc4c | ||
|
|
6bd2ad922c | ||
|
|
c0d17dd230 | ||
|
|
5b9f060da3 | ||
|
|
c289177f65 | ||
|
|
e82cdc2040 | ||
|
|
1ad8e8d12e | ||
|
|
1bad59ccb9 | ||
|
|
bf399d4a7f | ||
|
|
9f0df00b19 | ||
|
|
e573b8066c | ||
|
|
2b4c1079ac | ||
|
|
03166deb7e | ||
|
|
6fadcadba1 | ||
|
|
2dea2c86ec | ||
|
|
330eb6239a | ||
|
|
652548057b | ||
|
|
edbebf4b4e | ||
|
|
634643657e | ||
|
|
f435f290ac | ||
|
|
97fe7e30a7 | ||
|
|
2c3d883f1f |
1
.gitignore
vendored
1
.gitignore
vendored
@@ -1 +1,2 @@
|
|||||||
/target
|
/target
|
||||||
|
test.json
|
||||||
|
|||||||
228
Cargo.lock
generated
228
Cargo.lock
generated
@@ -126,6 +126,43 @@ version = "1.0.0"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
|
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "clap"
|
||||||
|
version = "4.1.4"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "f13b9c79b5d1dd500d20ef541215a6423c75829ef43117e1b4d17fd8af0b5d76"
|
||||||
|
dependencies = [
|
||||||
|
"bitflags",
|
||||||
|
"clap_derive",
|
||||||
|
"clap_lex",
|
||||||
|
"is-terminal",
|
||||||
|
"once_cell",
|
||||||
|
"strsim",
|
||||||
|
"termcolor",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "clap_derive"
|
||||||
|
version = "4.1.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "684a277d672e91966334af371f1a7b5833f9aa00b07c84e92fbce95e00208ce8"
|
||||||
|
dependencies = [
|
||||||
|
"heck",
|
||||||
|
"proc-macro-error",
|
||||||
|
"proc-macro2",
|
||||||
|
"quote",
|
||||||
|
"syn",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "clap_lex"
|
||||||
|
version = "0.3.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "783fe232adfca04f90f56201b26d79682d4cd2625e0bc7290b95123afe558ade"
|
||||||
|
dependencies = [
|
||||||
|
"os_str_bytes",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "color_quant"
|
name = "color_quant"
|
||||||
version = "1.1.0"
|
version = "1.1.0"
|
||||||
@@ -352,6 +389,27 @@ dependencies = [
|
|||||||
"cfg-if",
|
"cfg-if",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "errno"
|
||||||
|
version = "0.2.8"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "f639046355ee4f37944e44f60642c6f3a7efa3cf6b78c78a0d989a8ce6c396a1"
|
||||||
|
dependencies = [
|
||||||
|
"errno-dragonfly",
|
||||||
|
"libc",
|
||||||
|
"winapi 0.3.9",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "errno-dragonfly"
|
||||||
|
version = "0.1.2"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "aa68f1b12764fab894d2755d2518754e71b4fd80ecfb822714a1206c2aab39bf"
|
||||||
|
dependencies = [
|
||||||
|
"cc",
|
||||||
|
"libc",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "event-listener"
|
name = "event-listener"
|
||||||
version = "2.5.2"
|
version = "2.5.2"
|
||||||
@@ -501,6 +559,12 @@ dependencies = [
|
|||||||
"crunchy",
|
"crunchy",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "heck"
|
||||||
|
version = "0.4.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "hermit-abi"
|
name = "hermit-abi"
|
||||||
version = "0.1.19"
|
version = "0.1.19"
|
||||||
@@ -519,6 +583,12 @@ dependencies = [
|
|||||||
"libc",
|
"libc",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "hermit-abi"
|
||||||
|
version = "0.3.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "856b5cb0902c2b6d65d5fd97dfa30f9b70c7538e770b98eab5ed52d8db923e01"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "http"
|
name = "http"
|
||||||
version = "0.2.8"
|
version = "0.2.8"
|
||||||
@@ -569,6 +639,28 @@ dependencies = [
|
|||||||
"cfg-if",
|
"cfg-if",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "io-lifetimes"
|
||||||
|
version = "1.0.5"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "1abeb7a0dd0f8181267ff8adc397075586500b81b28a73e8a0208b00fc170fb3"
|
||||||
|
dependencies = [
|
||||||
|
"libc",
|
||||||
|
"windows-sys 0.45.0",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "is-terminal"
|
||||||
|
version = "0.4.3"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "22e18b0a45d56fe973d6db23972bf5bc46f988a4a2385deac9cc29572f09daef"
|
||||||
|
dependencies = [
|
||||||
|
"hermit-abi 0.3.0",
|
||||||
|
"io-lifetimes",
|
||||||
|
"rustix",
|
||||||
|
"windows-sys 0.45.0",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "isahc"
|
name = "isahc"
|
||||||
version = "1.7.2"
|
version = "1.7.2"
|
||||||
@@ -625,10 +717,12 @@ name = "kami"
|
|||||||
version = "0.6.0"
|
version = "0.6.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"base64",
|
"base64",
|
||||||
|
"clap",
|
||||||
"colored",
|
"colored",
|
||||||
"crossterm 0.24.0",
|
"crossterm 0.24.0",
|
||||||
"dirs",
|
"dirs",
|
||||||
"isahc",
|
"isahc",
|
||||||
|
"lazy_static",
|
||||||
"regex",
|
"regex",
|
||||||
"rust_cast",
|
"rust_cast",
|
||||||
"serde_json",
|
"serde_json",
|
||||||
@@ -662,9 +756,9 @@ checksum = "03087c2bad5e1034e8cace5926dec053fb3790248370865f5117a7d0213354c8"
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "libc"
|
name = "libc"
|
||||||
version = "0.2.126"
|
version = "0.2.139"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "349d5a591cd28b49e1d1037471617a32ddcda5731b99419008085f72d5a53836"
|
checksum = "201de327520df007757c1f0adce6e827fe8562fbc28bfd9c15571c66ca1f5f79"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "libnghttp2-sys"
|
name = "libnghttp2-sys"
|
||||||
@@ -688,6 +782,12 @@ dependencies = [
|
|||||||
"vcpkg",
|
"vcpkg",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "linux-raw-sys"
|
||||||
|
version = "0.1.4"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "f051f77a7c8e6957c0696eac88f26b0117e54f52d3fc682ab19397a8812846a4"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "lock_api"
|
name = "lock_api"
|
||||||
version = "0.4.7"
|
version = "0.4.7"
|
||||||
@@ -867,6 +967,12 @@ dependencies = [
|
|||||||
"vcpkg",
|
"vcpkg",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "os_str_bytes"
|
||||||
|
version = "6.4.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "9b7820b9daea5457c9f21c69448905d723fbd21136ccf521748f23fd49e723ee"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "parking"
|
name = "parking"
|
||||||
version = "2.0.0"
|
version = "2.0.0"
|
||||||
@@ -960,10 +1066,34 @@ dependencies = [
|
|||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "proc-macro2"
|
name = "proc-macro-error"
|
||||||
version = "1.0.39"
|
version = "1.0.4"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "c54b25569025b7fc9651de43004ae593a75ad88543b17178aa5e1b9c4f15f56f"
|
checksum = "da25490ff9892aab3fcf7c36f08cfb902dd3e71ca0f9f9517bea02a73a5ce38c"
|
||||||
|
dependencies = [
|
||||||
|
"proc-macro-error-attr",
|
||||||
|
"proc-macro2",
|
||||||
|
"quote",
|
||||||
|
"syn",
|
||||||
|
"version_check",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "proc-macro-error-attr"
|
||||||
|
version = "1.0.4"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "a1be40180e52ecc98ad80b184934baf3d0d29f979574e439af5a55274b35f869"
|
||||||
|
dependencies = [
|
||||||
|
"proc-macro2",
|
||||||
|
"quote",
|
||||||
|
"version_check",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "proc-macro2"
|
||||||
|
version = "1.0.50"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "6ef7d57beacfaf2d8aee5937dab7b7f28de3cb8b1828479bb5de2a7106f2bae2"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"unicode-ident",
|
"unicode-ident",
|
||||||
]
|
]
|
||||||
@@ -1116,6 +1246,20 @@ dependencies = [
|
|||||||
"serde_json",
|
"serde_json",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "rustix"
|
||||||
|
version = "0.36.8"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "f43abb88211988493c1abb44a70efa56ff0ce98f233b7b276146f1f3f7ba9644"
|
||||||
|
dependencies = [
|
||||||
|
"bitflags",
|
||||||
|
"errno",
|
||||||
|
"io-lifetimes",
|
||||||
|
"libc",
|
||||||
|
"linux-raw-sys",
|
||||||
|
"windows-sys 0.45.0",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "ryu"
|
name = "ryu"
|
||||||
version = "1.0.11"
|
version = "1.0.11"
|
||||||
@@ -1262,6 +1406,12 @@ dependencies = [
|
|||||||
"lock_api",
|
"lock_api",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "strsim"
|
||||||
|
version = "0.10.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "syn"
|
name = "syn"
|
||||||
version = "1.0.96"
|
version = "1.0.96"
|
||||||
@@ -1483,6 +1633,12 @@ version = "0.2.15"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426"
|
checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "version_check"
|
||||||
|
version = "0.9.4"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "viuer"
|
name = "viuer"
|
||||||
version = "0.6.2"
|
version = "0.6.2"
|
||||||
@@ -1655,19 +1811,43 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||||||
checksum = "5a3e1820f08b8513f676f7ab6c1f99ff312fb97b553d30ff4dd86f9f15728aa7"
|
checksum = "5a3e1820f08b8513f676f7ab6c1f99ff312fb97b553d30ff4dd86f9f15728aa7"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"windows_aarch64_gnullvm",
|
"windows_aarch64_gnullvm",
|
||||||
"windows_aarch64_msvc 0.42.0",
|
"windows_aarch64_msvc 0.42.1",
|
||||||
"windows_i686_gnu 0.42.0",
|
"windows_i686_gnu 0.42.1",
|
||||||
"windows_i686_msvc 0.42.0",
|
"windows_i686_msvc 0.42.1",
|
||||||
"windows_x86_64_gnu 0.42.0",
|
"windows_x86_64_gnu 0.42.1",
|
||||||
"windows_x86_64_gnullvm",
|
"windows_x86_64_gnullvm",
|
||||||
"windows_x86_64_msvc 0.42.0",
|
"windows_x86_64_msvc 0.42.1",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "windows-sys"
|
||||||
|
version = "0.45.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "75283be5efb2831d37ea142365f009c02ec203cd29a3ebecbc093d52315b66d0"
|
||||||
|
dependencies = [
|
||||||
|
"windows-targets",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "windows-targets"
|
||||||
|
version = "0.42.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "8e2522491fbfcd58cc84d47aeb2958948c4b8982e9a2d8a2a35bbaed431390e7"
|
||||||
|
dependencies = [
|
||||||
|
"windows_aarch64_gnullvm",
|
||||||
|
"windows_aarch64_msvc 0.42.1",
|
||||||
|
"windows_i686_gnu 0.42.1",
|
||||||
|
"windows_i686_msvc 0.42.1",
|
||||||
|
"windows_x86_64_gnu 0.42.1",
|
||||||
|
"windows_x86_64_gnullvm",
|
||||||
|
"windows_x86_64_msvc 0.42.1",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "windows_aarch64_gnullvm"
|
name = "windows_aarch64_gnullvm"
|
||||||
version = "0.42.0"
|
version = "0.42.1"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "41d2aa71f6f0cbe00ae5167d90ef3cfe66527d6f613ca78ac8024c3ccab9a19e"
|
checksum = "8c9864e83243fdec7fc9c5444389dcbbfd258f745e7853198f365e3c4968a608"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "windows_aarch64_msvc"
|
name = "windows_aarch64_msvc"
|
||||||
@@ -1677,9 +1857,9 @@ checksum = "9bb8c3fd39ade2d67e9874ac4f3db21f0d710bee00fe7cab16949ec184eeaa47"
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "windows_aarch64_msvc"
|
name = "windows_aarch64_msvc"
|
||||||
version = "0.42.0"
|
version = "0.42.1"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "dd0f252f5a35cac83d6311b2e795981f5ee6e67eb1f9a7f64eb4500fbc4dcdb4"
|
checksum = "4c8b1b673ffc16c47a9ff48570a9d85e25d265735c503681332589af6253c6c7"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "windows_i686_gnu"
|
name = "windows_i686_gnu"
|
||||||
@@ -1689,9 +1869,9 @@ checksum = "180e6ccf01daf4c426b846dfc66db1fc518f074baa793aa7d9b9aaeffad6a3b6"
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "windows_i686_gnu"
|
name = "windows_i686_gnu"
|
||||||
version = "0.42.0"
|
version = "0.42.1"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "fbeae19f6716841636c28d695375df17562ca208b2b7d0dc47635a50ae6c5de7"
|
checksum = "de3887528ad530ba7bdbb1faa8275ec7a1155a45ffa57c37993960277145d640"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "windows_i686_msvc"
|
name = "windows_i686_msvc"
|
||||||
@@ -1701,9 +1881,9 @@ checksum = "e2e7917148b2812d1eeafaeb22a97e4813dfa60a3f8f78ebe204bcc88f12f024"
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "windows_i686_msvc"
|
name = "windows_i686_msvc"
|
||||||
version = "0.42.0"
|
version = "0.42.1"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "84c12f65daa39dd2babe6e442988fc329d6243fdce47d7d2d155b8d874862246"
|
checksum = "bf4d1122317eddd6ff351aa852118a2418ad4214e6613a50e0191f7004372605"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "windows_x86_64_gnu"
|
name = "windows_x86_64_gnu"
|
||||||
@@ -1713,15 +1893,15 @@ checksum = "4dcd171b8776c41b97521e5da127a2d86ad280114807d0b2ab1e462bc764d9e1"
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "windows_x86_64_gnu"
|
name = "windows_x86_64_gnu"
|
||||||
version = "0.42.0"
|
version = "0.42.1"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "bf7b1b21b5362cbc318f686150e5bcea75ecedc74dd157d874d754a2ca44b0ed"
|
checksum = "c1040f221285e17ebccbc2591ffdc2d44ee1f9186324dd3e84e99ac68d699c45"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "windows_x86_64_gnullvm"
|
name = "windows_x86_64_gnullvm"
|
||||||
version = "0.42.0"
|
version = "0.42.1"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "09d525d2ba30eeb3297665bd434a54297e4170c7f1a44cad4ef58095b4cd2028"
|
checksum = "628bfdf232daa22b0d64fdb62b09fcc36bb01f05a3939e20ab73aaf9470d0463"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "windows_x86_64_msvc"
|
name = "windows_x86_64_msvc"
|
||||||
@@ -1731,6 +1911,6 @@ checksum = "c811ca4a8c853ef420abd8592ba53ddbbac90410fab6903b3e79972a631f7680"
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "windows_x86_64_msvc"
|
name = "windows_x86_64_msvc"
|
||||||
version = "0.42.0"
|
version = "0.42.1"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "f40009d85759725a34da6d89a94e63d7bdc50a862acf0dbc7c8e488f1edcb6f5"
|
checksum = "447660ad36a13288b1db4d4248e857b510e8c3a225c822ba4fb748c0aafecffd"
|
||||||
|
|||||||
@@ -20,3 +20,5 @@ crossterm = "0.24.0"
|
|||||||
unicode-width = "0.1.9"
|
unicode-width = "0.1.9"
|
||||||
rust_cast = "0.17.0"
|
rust_cast = "0.17.0"
|
||||||
viuer = { version = "0.6", features = ["sixel"] }
|
viuer = { version = "0.6", features = ["sixel"] }
|
||||||
|
clap = { version = "4.1.4", features = ["derive"] }
|
||||||
|
lazy_static = "1.4.0"
|
||||||
@@ -1,124 +1,12 @@
|
|||||||
use crate::{
|
|
||||||
get_an_history, get_an_progress, get_anime_id, get_user_anime_progress, update_anime_progress,
|
|
||||||
write_an_progress,
|
|
||||||
};
|
|
||||||
use crate::{get_anime_link, get_animes, get_image};
|
|
||||||
use crate::{open_cast, open_video};
|
|
||||||
|
|
||||||
use crossterm::{
|
use crossterm::{
|
||||||
event::{self, DisableMouseCapture, EnableMouseCapture, Event, KeyCode},
|
event::{DisableMouseCapture, EnableMouseCapture},
|
||||||
execute,
|
execute,
|
||||||
terminal::{disable_raw_mode, enable_raw_mode, EnterAlternateScreen, LeaveAlternateScreen},
|
terminal::{disable_raw_mode, enable_raw_mode, EnterAlternateScreen, LeaveAlternateScreen},
|
||||||
};
|
};
|
||||||
use std::{error::Error, io};
|
use std::{error::Error, io};
|
||||||
use tui::{
|
use tui::{backend::CrosstermBackend, Terminal};
|
||||||
backend::{Backend, CrosstermBackend},
|
|
||||||
layout::{Constraint, Direction, Layout},
|
|
||||||
style::{Color, Modifier, Style},
|
|
||||||
text::{Span, Spans, Text},
|
|
||||||
widgets::{Block, BorderType, Borders, List, ListItem, ListState, Paragraph},
|
|
||||||
Frame, Terminal,
|
|
||||||
};
|
|
||||||
use unicode_width::UnicodeWidthStr;
|
|
||||||
use viuer::{print_from_file, terminal_size, Config};
|
|
||||||
|
|
||||||
use super::scraper::get_anime_info;
|
use crate::ui::app::{anime::App, app::KamiApp};
|
||||||
|
|
||||||
enum InputMode {
|
|
||||||
Normal,
|
|
||||||
Editing,
|
|
||||||
}
|
|
||||||
|
|
||||||
struct StatefulList<T> {
|
|
||||||
state: ListState,
|
|
||||||
items: Vec<T>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<T> StatefulList<T> {
|
|
||||||
fn with_items(items: Vec<T>) -> StatefulList<T> {
|
|
||||||
StatefulList {
|
|
||||||
state: ListState::default(),
|
|
||||||
items,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn next(&mut self) {
|
|
||||||
let i = match self.state.selected() {
|
|
||||||
Some(i) => {
|
|
||||||
if i >= self.items.len() - 1 {
|
|
||||||
0
|
|
||||||
} else {
|
|
||||||
i + 1
|
|
||||||
}
|
|
||||||
}
|
|
||||||
None => 0,
|
|
||||||
};
|
|
||||||
self.state.select(Some(i));
|
|
||||||
}
|
|
||||||
|
|
||||||
fn previous(&mut self) {
|
|
||||||
let i = match self.state.selected() {
|
|
||||||
Some(i) => {
|
|
||||||
if i == 0 {
|
|
||||||
self.items.len() - 1
|
|
||||||
} else {
|
|
||||||
i - 1
|
|
||||||
}
|
|
||||||
}
|
|
||||||
None => 0,
|
|
||||||
};
|
|
||||||
self.state.select(Some(i));
|
|
||||||
}
|
|
||||||
|
|
||||||
fn unselect(&mut self) {
|
|
||||||
self.state.select(None);
|
|
||||||
}
|
|
||||||
fn push(&mut self, item: T) {
|
|
||||||
self.items.push(item);
|
|
||||||
}
|
|
||||||
fn iter(&self) -> impl Iterator<Item = &T> {
|
|
||||||
self.items.iter()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
struct App {
|
|
||||||
/// Current value of the input box
|
|
||||||
input: String,
|
|
||||||
animes: (Vec<String>, Vec<String>, Vec<String>),
|
|
||||||
image: String,
|
|
||||||
/// Current input mode
|
|
||||||
input_mode: InputMode,
|
|
||||||
/// History of recorded messages
|
|
||||||
messages: StatefulList<String>,
|
|
||||||
title: String,
|
|
||||||
link: String,
|
|
||||||
ep: u64,
|
|
||||||
progress: i32,
|
|
||||||
anime_id: i32,
|
|
||||||
token: String,
|
|
||||||
provider: String,
|
|
||||||
cast: (bool, String),
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<'a> App {
|
|
||||||
fn default() -> App {
|
|
||||||
App {
|
|
||||||
input: String::new(),
|
|
||||||
animes: get_an_history(),
|
|
||||||
image: String::new(),
|
|
||||||
input_mode: InputMode::Normal,
|
|
||||||
messages: StatefulList::with_items(Vec::new()),
|
|
||||||
title: String::new(),
|
|
||||||
link: String::new(),
|
|
||||||
ep: 0,
|
|
||||||
progress: 0,
|
|
||||||
anime_id: 0,
|
|
||||||
token: String::new(),
|
|
||||||
provider: String::new(),
|
|
||||||
cast: (false, "0".to_string()),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn anime_ui(
|
pub fn anime_ui(
|
||||||
token: String,
|
token: String,
|
||||||
@@ -133,11 +21,11 @@ pub fn anime_ui(
|
|||||||
let mut terminal = Terminal::new(backend)?;
|
let mut terminal = Terminal::new(backend)?;
|
||||||
|
|
||||||
// create app and run it
|
// create app and run it
|
||||||
let mut app = App::default();
|
let mut app = App::new();
|
||||||
app.token = token;
|
app.token = token;
|
||||||
app.provider = provider;
|
app.provider = provider;
|
||||||
app.cast = cast;
|
app.cast = cast;
|
||||||
let res = run_app(&mut terminal, app);
|
let res = app.run(&mut terminal);
|
||||||
|
|
||||||
// restore terminal
|
// restore terminal
|
||||||
disable_raw_mode()?;
|
disable_raw_mode()?;
|
||||||
@@ -154,312 +42,3 @@ pub fn anime_ui(
|
|||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn run_app<B: Backend>(terminal: &mut Terminal<B>, mut app: App) -> io::Result<()> {
|
|
||||||
let mut ep_select = false;
|
|
||||||
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");
|
|
||||||
get_image(&app.image, &image_path.to_str().unwrap());
|
|
||||||
print_from_file(image_path, &config).expect("Image printing failed.");
|
|
||||||
}
|
|
||||||
app.messages.items.clear();
|
|
||||||
for anime in &app.animes.1 {
|
|
||||||
app.messages.push(anime.to_string());
|
|
||||||
}
|
|
||||||
app.input_mode = InputMode::Normal;
|
|
||||||
|
|
||||||
loop {
|
|
||||||
terminal.draw(|f| ui(f, &mut app))?;
|
|
||||||
|
|
||||||
if let Event::Key(key) = event::read()? {
|
|
||||||
match app.input_mode {
|
|
||||||
InputMode::Normal => match key.code {
|
|
||||||
KeyCode::Char('i') => {
|
|
||||||
app.input_mode = InputMode::Editing;
|
|
||||||
}
|
|
||||||
KeyCode::Char('q') => {
|
|
||||||
return Ok(());
|
|
||||||
}
|
|
||||||
KeyCode::Left => app.messages.unselect(),
|
|
||||||
KeyCode::Char('h') => app.messages.unselect(),
|
|
||||||
KeyCode::Down => match ep_select {
|
|
||||||
true => {
|
|
||||||
app.messages.next();
|
|
||||||
}
|
|
||||||
false => {
|
|
||||||
app.messages.next();
|
|
||||||
let selected = app.messages.state.selected();
|
|
||||||
app.image = app.animes.2[selected.unwrap()].clone();
|
|
||||||
change_image(&app);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
KeyCode::Char('j') => match ep_select {
|
|
||||||
true => {
|
|
||||||
app.messages.next();
|
|
||||||
}
|
|
||||||
false => {
|
|
||||||
app.messages.next();
|
|
||||||
let selected = app.messages.state.selected();
|
|
||||||
app.image = app.animes.2[selected.unwrap()].clone();
|
|
||||||
change_image(&app);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
KeyCode::Up => match ep_select {
|
|
||||||
true => {
|
|
||||||
app.messages.previous();
|
|
||||||
}
|
|
||||||
false => {
|
|
||||||
app.messages.previous();
|
|
||||||
let selected = app.messages.state.selected();
|
|
||||||
app.image = app.animes.2[selected.unwrap()].clone();
|
|
||||||
change_image(&app);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
KeyCode::Char('k') => match ep_select {
|
|
||||||
true => {
|
|
||||||
app.messages.previous();
|
|
||||||
}
|
|
||||||
false => {
|
|
||||||
app.messages.previous();
|
|
||||||
let selected = app.messages.state.selected();
|
|
||||||
app.image = app.animes.2[selected.unwrap()].clone();
|
|
||||||
change_image(&app);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
//if KeyCode::Enter => {
|
|
||||||
KeyCode::Enter => {
|
|
||||||
if ep_select == false {
|
|
||||||
app.progress = 0;
|
|
||||||
let selected = app.messages.state.selected();
|
|
||||||
app.title = app.messages.items[selected.unwrap()].clone();
|
|
||||||
app.link = app.animes.0[selected.unwrap()].clone();
|
|
||||||
let anime_info = get_anime_info(&app.animes.0[selected.unwrap()]);
|
|
||||||
app.anime_id = get_anime_id(anime_info.0);
|
|
||||||
app.messages.items.clear();
|
|
||||||
if app.token == "local" || app.anime_id == 0 {
|
|
||||||
app.progress = get_an_progress(&app.title) as i32;
|
|
||||||
app.messages.state.select(Some(app.progress as usize));
|
|
||||||
} else {
|
|
||||||
app.progress =
|
|
||||||
get_user_anime_progress(app.anime_id, app.token.as_str());
|
|
||||||
app.messages.state.select(Some(app.progress as usize));
|
|
||||||
}
|
|
||||||
if anime_info.1 == 1 {
|
|
||||||
let link = get_anime_link(&app.link, 1);
|
|
||||||
if !app.cast.0 {
|
|
||||||
open_video((link, format!("{} Episode 1", &app.title)));
|
|
||||||
} else {
|
|
||||||
open_cast(
|
|
||||||
(link, format!("{} Episode 1", &app.title)),
|
|
||||||
&app.cast.1,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
let selected = app.messages.state.selected();
|
|
||||||
let image_url = app.animes.2[selected.unwrap()].clone();
|
|
||||||
if app.token == "local" || app.anime_id == 0 {
|
|
||||||
write_an_progress((&app.title, &app.link, &image_url), &1);
|
|
||||||
} else {
|
|
||||||
update_anime_progress(app.anime_id, 1, app.token.as_str());
|
|
||||||
write_an_progress((&app.title, &app.link, &image_url), &1);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
for ep in 1..anime_info.1 + 1 {
|
|
||||||
app.messages.push(format!("Episode {}", ep));
|
|
||||||
}
|
|
||||||
ep_select = true;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
let selected = app.messages.state.selected();
|
|
||||||
app.ep = app
|
|
||||||
.messages
|
|
||||||
.iter()
|
|
||||||
.nth(selected.unwrap())
|
|
||||||
.unwrap()
|
|
||||||
.replace("Episode ", "")
|
|
||||||
.parse::<u64>()
|
|
||||||
.unwrap();
|
|
||||||
let link = get_anime_link(&app.link, app.ep);
|
|
||||||
if !app.cast.0 {
|
|
||||||
open_video((link, format!("{} Episode {}", &app.title, app.ep)));
|
|
||||||
} else {
|
|
||||||
open_cast(
|
|
||||||
(link, format!("{} Episode {}", &app.title, app.ep)),
|
|
||||||
&app.cast.1,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
let image_url = &app.image;
|
|
||||||
if app.ep > app.progress as u64 {
|
|
||||||
if app.token == "local" || app.anime_id == 0 {
|
|
||||||
write_an_progress((&app.title, &app.link, &image_url), &app.ep);
|
|
||||||
} else {
|
|
||||||
update_anime_progress(
|
|
||||||
app.anime_id,
|
|
||||||
app.ep as usize,
|
|
||||||
app.token.as_str(),
|
|
||||||
);
|
|
||||||
write_an_progress((&app.title, &app.link, &image_url), &app.ep);
|
|
||||||
}
|
|
||||||
app.progress = app.ep as i32;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
_ => {}
|
|
||||||
},
|
|
||||||
InputMode::Editing => match key.code {
|
|
||||||
KeyCode::Enter => {
|
|
||||||
//push app.input into app.messages with '
|
|
||||||
app.animes = get_animes(app.input.drain(..).collect());
|
|
||||||
app.messages.items.clear();
|
|
||||||
for anime in &app.animes.1 {
|
|
||||||
app.messages.push(anime.to_string());
|
|
||||||
}
|
|
||||||
ep_select = false;
|
|
||||||
app.input_mode = InputMode::Normal;
|
|
||||||
}
|
|
||||||
KeyCode::Char(c) => {
|
|
||||||
app.input.push(c);
|
|
||||||
}
|
|
||||||
KeyCode::Backspace => {
|
|
||||||
app.input.pop();
|
|
||||||
}
|
|
||||||
KeyCode::Esc => {
|
|
||||||
app.input_mode = InputMode::Normal;
|
|
||||||
}
|
|
||||||
_ => {}
|
|
||||||
},
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn ui<B: Backend>(f: &mut Frame<B>, app: &mut App) {
|
|
||||||
let chunks = Layout::default()
|
|
||||||
.direction(Direction::Vertical)
|
|
||||||
.margin(1)
|
|
||||||
.constraints(
|
|
||||||
[
|
|
||||||
Constraint::Min(1),
|
|
||||||
Constraint::Length(1),
|
|
||||||
Constraint::Length(3),
|
|
||||||
]
|
|
||||||
.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![
|
|
||||||
Span::raw("Press "),
|
|
||||||
Span::styled("q", Style::default().add_modifier(Modifier::BOLD)),
|
|
||||||
Span::raw(" to exit, "),
|
|
||||||
Span::styled("i", Style::default().add_modifier(Modifier::BOLD)),
|
|
||||||
Span::raw(" to search."),
|
|
||||||
],
|
|
||||||
Style::default().add_modifier(Modifier::RAPID_BLINK),
|
|
||||||
),
|
|
||||||
InputMode::Editing => (
|
|
||||||
vec![
|
|
||||||
Span::raw("Press "),
|
|
||||||
Span::styled("Esc", Style::default().add_modifier(Modifier::BOLD)),
|
|
||||||
Span::raw(" to stop editing, "),
|
|
||||||
Span::styled("Enter", Style::default().add_modifier(Modifier::BOLD)),
|
|
||||||
Span::raw(" to select."),
|
|
||||||
],
|
|
||||||
Style::default(),
|
|
||||||
),
|
|
||||||
};
|
|
||||||
|
|
||||||
let messages: Vec<ListItem> = app
|
|
||||||
.messages
|
|
||||||
.iter()
|
|
||||||
.enumerate()
|
|
||||||
.map(|(i, m)| {
|
|
||||||
let content = vec![Spans::from(Span::raw(format!("{}: {}", i, m)))];
|
|
||||||
ListItem::new(content)
|
|
||||||
})
|
|
||||||
.collect();
|
|
||||||
let messages = List::new(messages)
|
|
||||||
.block(
|
|
||||||
Block::default()
|
|
||||||
.borders(Borders::ALL)
|
|
||||||
.title("list")
|
|
||||||
.border_type(BorderType::Rounded),
|
|
||||||
)
|
|
||||||
.style(Style::default().fg(Color::White))
|
|
||||||
.highlight_style(
|
|
||||||
Style::default()
|
|
||||||
.bg(Color::Rgb(183, 142, 241))
|
|
||||||
.add_modifier(Modifier::BOLD),
|
|
||||||
)
|
|
||||||
.highlight_symbol(">>");
|
|
||||||
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);
|
|
||||||
let help_message = Paragraph::new(text);
|
|
||||||
f.render_widget(help_message, chunks[1]);
|
|
||||||
|
|
||||||
let input = Paragraph::new(app.input.as_ref())
|
|
||||||
.style(match app.input_mode {
|
|
||||||
InputMode::Normal => Style::default(),
|
|
||||||
InputMode::Editing => Style::default().fg(Color::Rgb(183, 142, 241)),
|
|
||||||
})
|
|
||||||
.block(Block::default().borders(Borders::all()).title("Input"));
|
|
||||||
f.render_widget(input, chunks[2]);
|
|
||||||
match app.input_mode {
|
|
||||||
InputMode::Normal =>
|
|
||||||
// Hide the cursor. `Frame` does this by default, so we don't need to do anything here
|
|
||||||
{}
|
|
||||||
|
|
||||||
InputMode::Editing => {
|
|
||||||
// Make the cursor visible and ask tui-rs to put it at the specified coordinates after rendering
|
|
||||||
f.set_cursor(
|
|
||||||
// Put cursor past the end of the input text
|
|
||||||
chunks[2].x + app.input.width() as u16 + 1,
|
|
||||||
// Move one line down, from the border to the input line
|
|
||||||
chunks[2].y + 1,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -8,16 +8,28 @@ use rust_cast::{
|
|||||||
};
|
};
|
||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
|
|
||||||
pub fn open_video(link: (String, String)) {
|
pub fn open_video(link: (String, String, String)) {
|
||||||
let title = link.1;
|
if link.2 == "null" {
|
||||||
let title = title.replace("-", " ");
|
let title = link.1;
|
||||||
let arg: String = format!("--force-media-title={}", title);
|
let title = title.replace("-", " ");
|
||||||
let _ = std::process::Command::new("mpv")
|
let arg: String = format!("--force-media-title={}", title);
|
||||||
.arg(link.0)
|
let _ = std::process::Command::new("mpv")
|
||||||
.arg(arg)
|
.arg(link.0)
|
||||||
.output()
|
.arg(arg)
|
||||||
.expect("failed to open mpv");
|
.output()
|
||||||
|
.expect("failed to open mpv");
|
||||||
|
} else {
|
||||||
|
let title = link.1;
|
||||||
|
let title = title.replace("-", " ");
|
||||||
|
let arg1: String = format!("--force-media-title={}", title);
|
||||||
|
let arg2: String = format!("--sub-files={}", link.2);
|
||||||
|
let _ = std::process::Command::new("mpv")
|
||||||
|
.arg(link.0)
|
||||||
|
.arg(arg1)
|
||||||
|
.arg(arg2)
|
||||||
|
.output()
|
||||||
|
.expect("failed to open mpv");
|
||||||
|
}
|
||||||
// clear terminal
|
// clear terminal
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,89 +1,110 @@
|
|||||||
use isahc::config::Configurable;
|
use isahc::config::Configurable;
|
||||||
use isahc::{ReadResponseExt, Request, RequestExt};
|
use isahc::{ReadResponseExt, Request, RequestExt};
|
||||||
use regex::Regex;
|
|
||||||
use std::fs::File;
|
use std::fs::File;
|
||||||
use std::io::prelude::*;
|
use std::io::prelude::*;
|
||||||
|
|
||||||
|
use crate::helpers::{fixing_text::htmlise, scraper};
|
||||||
|
|
||||||
//use serde_json::json;
|
//use serde_json::json;
|
||||||
|
|
||||||
pub fn get_anime_html(url: &str) -> String {
|
pub fn search_anime(query: String) -> (Vec<String>, Vec<String>, Vec<String>) {
|
||||||
let req = Request::builder()
|
let req = Request::builder()
|
||||||
.uri(url)
|
.uri(format!(
|
||||||
|
"https://api.consumet.org/meta/anilist/{}",
|
||||||
|
htmlise(query)
|
||||||
|
))
|
||||||
.redirect_policy(isahc::config::RedirectPolicy::Follow)
|
.redirect_policy(isahc::config::RedirectPolicy::Follow)
|
||||||
.header(
|
.header("user-agent", *scraper::USER_AGENT)
|
||||||
"user-agent",
|
|
||||||
"Mozilla/5.0 (X11; Linux x86_64; rv:99.0) Gecko/20100101 Firefox/100.0",
|
|
||||||
)
|
|
||||||
.body(())
|
.body(())
|
||||||
.unwrap();
|
.unwrap();
|
||||||
req.send().unwrap().text().unwrap()
|
let json = req.send().unwrap().text().unwrap();
|
||||||
}
|
let json: serde_json::Value = serde_json::from_str(&json).unwrap();
|
||||||
|
|
||||||
pub fn get_post(id: &str) -> String {
|
let mut titles = Vec::new();
|
||||||
let resp = Request::builder()
|
let mut ids = Vec::new();
|
||||||
.method("POST")
|
let mut images = Vec::new();
|
||||||
.uri("https://yugen.to/api/embed/")
|
|
||||||
.header("x-requested-with", "XMLHttpRequest")
|
|
||||||
.body(id)
|
|
||||||
.unwrap()
|
|
||||||
.send()
|
|
||||||
.unwrap()
|
|
||||||
.text();
|
|
||||||
let resp: String = resp.as_ref().unwrap().to_string();
|
|
||||||
resp
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn get_animes(query: String) -> (Vec<String>, Vec<String>, Vec<String>) {
|
for anime in json["results"].as_array().unwrap().iter() {
|
||||||
let query = query.replace(" ", "+");
|
titles.push(
|
||||||
let html = get_anime_html(&format!("https://yugen.to/search/?q={}", query));
|
anime["title"]["userPreferred"]
|
||||||
let re = Regex::new(r#"href="(/anime[^"]*)""#).unwrap();
|
.as_str()
|
||||||
let mut animes_links = Vec::new();
|
.unwrap()
|
||||||
for cap in re.captures_iter(&html) {
|
.to_string(),
|
||||||
animes_links.push(cap[1].to_string());
|
);
|
||||||
|
|
||||||
|
ids.push(anime["id"].as_str().unwrap().to_string());
|
||||||
|
images.push(anime["image"].as_str().unwrap().to_string());
|
||||||
}
|
}
|
||||||
let re = Regex::new(r#"/" title="([^"]*)""#).unwrap();
|
|
||||||
let mut animes_names = Vec::new();
|
(ids, titles, images)
|
||||||
for cap in re.captures_iter(&html) {
|
|
||||||
animes_names.push(cap[1].to_string());
|
|
||||||
}
|
|
||||||
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) {
|
pub fn get_episodes(id: &i32, provider: &str) -> (Vec<String>, Vec<String>) {
|
||||||
let url = format!("https://yugen.to{}watch", url);
|
let req = Request::builder()
|
||||||
let html = get_anime_html(&url);
|
.uri(format!(
|
||||||
//print html and exit
|
"https://api.consumet.org/meta/anilist/info/{}?provider={}",
|
||||||
let re = Regex::new(r#""mal_id":(\d*)"#).unwrap();
|
id, provider
|
||||||
let mal_id = re.captures(&html).unwrap()[1].parse().unwrap();
|
))
|
||||||
let re =
|
.redirect_policy(isahc::config::RedirectPolicy::Follow)
|
||||||
Regex::new(r#"Episodes</div><span class="description" style="font-size: \d*px;">(\d*)"#)
|
.header("user-agent", *scraper::USER_AGENT)
|
||||||
.unwrap();
|
.body(())
|
||||||
let episodes = re.captures(&html).unwrap()[1].parse().unwrap();
|
.unwrap();
|
||||||
(mal_id, episodes)
|
let json = req.send().unwrap().text().unwrap();
|
||||||
|
let json: serde_json::Value = serde_json::from_str(&json).unwrap();
|
||||||
|
|
||||||
|
let mut titles = Vec::new();
|
||||||
|
let mut ids = Vec::new();
|
||||||
|
|
||||||
|
for episode in json["episodes"].as_array().unwrap().iter() {
|
||||||
|
titles.push(episode["title"].as_str().unwrap().to_string());
|
||||||
|
ids.push(episode["id"].as_str().unwrap().to_string());
|
||||||
|
}
|
||||||
|
(titles, ids)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_anime_link(url: &str, episode: u64) -> String {
|
pub fn get_episode_link(ep_id: &str, provider: &str) -> (String, String) {
|
||||||
let url = &format!(
|
let req = Request::builder()
|
||||||
"https://yugen.to/watch{}{}/",
|
.uri(format!(
|
||||||
url.replace("/anime", ""),
|
"https://api.consumet.org/meta/anilist/watch/{}?provider={}",
|
||||||
episode
|
ep_id, provider
|
||||||
);
|
))
|
||||||
let html = get_anime_html(url);
|
.redirect_policy(isahc::config::RedirectPolicy::Follow)
|
||||||
let re = Regex::new(r#"/e/([^/]*)"#).unwrap();
|
.header("user-agent", *scraper::USER_AGENT)
|
||||||
let capture = re.captures(&html).unwrap();
|
.body(())
|
||||||
let id = &capture[1];
|
.unwrap();
|
||||||
let id = format!("id={}%3D&ac=0", id);
|
let json = req.send().unwrap().text().unwrap();
|
||||||
let json = get_post(&id);
|
let json: serde_json::Value = serde_json::from_str(&json).unwrap();
|
||||||
let re = Regex::new(r#"hls": \["(.*)","#).unwrap();
|
|
||||||
let capture = re.captures(&json).unwrap();
|
let mut url = String::new();
|
||||||
let link = &capture[1];
|
std::fs::write("test.json", json.to_string()).unwrap();
|
||||||
//return the link
|
|
||||||
link.to_string()
|
let mut subtitle = String::new();
|
||||||
|
let _error_vec = Vec::new();
|
||||||
|
|
||||||
|
let sub_array = json["subtitles"].as_array().unwrap_or(&_error_vec);
|
||||||
|
|
||||||
|
for sub in sub_array.iter() {
|
||||||
|
//set subtitle to lang = English
|
||||||
|
if sub["lang"].as_str().unwrap_or("null") == "English" {
|
||||||
|
subtitle = sub["url"].as_str().unwrap_or("null").to_string();
|
||||||
|
// add \ before the first : in the url
|
||||||
|
subtitle = subtitle.replace(":", "\\:");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
let mut highest_quality = 0;
|
||||||
|
for source in json["sources"].as_array().unwrap().iter() {
|
||||||
|
let quality = source["quality"]
|
||||||
|
.as_str()
|
||||||
|
.unwrap()
|
||||||
|
.replace("p", "")
|
||||||
|
.parse::<i32>()
|
||||||
|
.unwrap_or(0);
|
||||||
|
if quality > highest_quality {
|
||||||
|
highest_quality = quality;
|
||||||
|
url = source["url"].as_str().unwrap().to_string();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
(url, subtitle)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_image(url: &str, path: &str) {
|
pub fn get_image(url: &str, path: &str) {
|
||||||
|
|||||||
@@ -40,54 +40,6 @@ pub fn get_token() -> String {
|
|||||||
token
|
token
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_anime_id(mal_id: i32) -> i32 {
|
|
||||||
const QUERY: &str = "
|
|
||||||
query ($id: Int, $search: Int) {
|
|
||||||
Media (id: $id, idMal: $search, type: ANIME) {
|
|
||||||
id
|
|
||||||
title {
|
|
||||||
native
|
|
||||||
romaji
|
|
||||||
english
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
";
|
|
||||||
let json = json!({
|
|
||||||
"query": QUERY,
|
|
||||||
"variables": {
|
|
||||||
"search": mal_id
|
|
||||||
}
|
|
||||||
});
|
|
||||||
let resp = Request::builder()
|
|
||||||
.method("POST")
|
|
||||||
.uri("https://graphql.anilist.co/")
|
|
||||||
.header("Content-Type", "application/json")
|
|
||||||
.header("Accept", "application/json")
|
|
||||||
.body(json.to_string())
|
|
||||||
.unwrap()
|
|
||||||
.send()
|
|
||||||
.unwrap()
|
|
||||||
.text();
|
|
||||||
let regex = regex::Regex::new(r#"id":(.*?),"#).unwrap();
|
|
||||||
let resp: String = resp.as_ref().unwrap().to_string();
|
|
||||||
//if error let id = 0
|
|
||||||
let id = match regex.captures(&resp) {
|
|
||||||
Some(captures) => captures[1].parse::<i32>().unwrap(),
|
|
||||||
None => 0,
|
|
||||||
};
|
|
||||||
|
|
||||||
// let id = regex
|
|
||||||
// .captures(&resp)
|
|
||||||
// .unwrap()
|
|
||||||
// .get(1)
|
|
||||||
// .unwrap()
|
|
||||||
// .as_str()
|
|
||||||
// .parse::<i32>()
|
|
||||||
// .unwrap();
|
|
||||||
id
|
|
||||||
}
|
|
||||||
|
|
||||||
//get the user id from the token
|
//get the user id from the token
|
||||||
fn get_user_id(token: &str) -> i32 {
|
fn get_user_id(token: &str) -> i32 {
|
||||||
const QUERY: &str = "query {
|
const QUERY: &str = "query {
|
||||||
@@ -264,7 +216,6 @@ pub fn get_an_history() -> (Vec<String>, Vec<String>, Vec<String>) {
|
|||||||
titles.push(key.to_string());
|
titles.push(key.to_string());
|
||||||
links.push(value["link"].as_str().unwrap().to_string());
|
links.push(value["link"].as_str().unwrap().to_string());
|
||||||
images.push(value["image"].as_str().unwrap().to_string());
|
images.push(value["image"].as_str().unwrap().to_string());
|
||||||
println!("{}", value["updated"].as_u64().unwrap());
|
|
||||||
last_updated.push(value["updated"].as_u64().unwrap());
|
last_updated.push(value["updated"].as_u64().unwrap());
|
||||||
}
|
}
|
||||||
let mut indices: Vec<usize> = (0..last_updated.len()).collect();
|
let mut indices: Vec<usize> = (0..last_updated.len()).collect();
|
||||||
|
|||||||
@@ -59,3 +59,12 @@ pub fn fix_html_encoding(ln_text: &Vec<String>) -> Vec<String> {
|
|||||||
}
|
}
|
||||||
ln_text_new
|
ln_text_new
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn htmlise(query: String) -> String {
|
||||||
|
query
|
||||||
|
.replace(" ", "%20")
|
||||||
|
.replace(":", "%3A")
|
||||||
|
.replace("!", "%21")
|
||||||
|
.replace("?", "%3F")
|
||||||
|
.replace("'", "%27")
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,2 +1,3 @@
|
|||||||
pub mod fixing_text;
|
pub mod fixing_text;
|
||||||
|
pub mod scraper;
|
||||||
pub mod take_input;
|
pub mod take_input;
|
||||||
|
|||||||
4
src/helpers/scraper.rs
Normal file
4
src/helpers/scraper.rs
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
lazy_static! {
|
||||||
|
pub static ref USER_AGENT: &'static str =
|
||||||
|
"Mozilla/5.0 (X11; Linux x86_64; rv:99.0) Gecko/20100101 Firefox/100.0";
|
||||||
|
}
|
||||||
358
src/ln/ln.rs
358
src/ln/ln.rs
@@ -1,119 +1,15 @@
|
|||||||
use crate::ln::open_text::*;
|
|
||||||
use crate::ln::scraper::*;
|
|
||||||
use crate::ln::tracker::*;
|
use crate::ln::tracker::*;
|
||||||
|
use crate::ui::app::{app::KamiApp, ln::App};
|
||||||
use crossterm::{
|
use crossterm::{
|
||||||
event::{self, DisableMouseCapture, EnableMouseCapture, Event, KeyCode},
|
event::{DisableMouseCapture, EnableMouseCapture},
|
||||||
execute,
|
execute,
|
||||||
terminal::{disable_raw_mode, enable_raw_mode, EnterAlternateScreen, LeaveAlternateScreen},
|
terminal::{disable_raw_mode, enable_raw_mode, EnterAlternateScreen, LeaveAlternateScreen},
|
||||||
};
|
};
|
||||||
use std::fs::File;
|
|
||||||
use std::io::Write;
|
|
||||||
use std::{error::Error, io};
|
use std::{error::Error, io};
|
||||||
use tui::{
|
use tui::{backend::CrosstermBackend, Terminal};
|
||||||
backend::{Backend, CrosstermBackend},
|
|
||||||
layout::{Constraint, Direction, Layout},
|
|
||||||
style::{Color, Modifier, Style},
|
|
||||||
text::{Span, Spans, Text},
|
|
||||||
widgets::{Block, BorderType, Borders, List, ListItem, ListState, Paragraph},
|
|
||||||
Frame, Terminal,
|
|
||||||
};
|
|
||||||
use unicode_width::UnicodeWidthStr;
|
|
||||||
|
|
||||||
enum InputMode {
|
pub fn ln_ui(chapter: u32, reader: String) -> Result<(), Box<dyn Error>> {
|
||||||
Normal,
|
|
||||||
Editing,
|
|
||||||
}
|
|
||||||
|
|
||||||
struct StatefulList<T> {
|
|
||||||
state: ListState,
|
|
||||||
items: Vec<T>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<T> StatefulList<T> {
|
|
||||||
fn with_items(items: Vec<T>) -> StatefulList<T> {
|
|
||||||
StatefulList {
|
|
||||||
state: ListState::default(),
|
|
||||||
items,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn next(&mut self) {
|
|
||||||
let i = match self.state.selected() {
|
|
||||||
Some(i) => {
|
|
||||||
if i >= self.items.len() - 1 {
|
|
||||||
0
|
|
||||||
} else {
|
|
||||||
i + 1
|
|
||||||
}
|
|
||||||
}
|
|
||||||
None => 0,
|
|
||||||
};
|
|
||||||
self.state.select(Some(i));
|
|
||||||
}
|
|
||||||
|
|
||||||
fn previous(&mut self) {
|
|
||||||
let i = match self.state.selected() {
|
|
||||||
Some(i) => {
|
|
||||||
if i == 0 {
|
|
||||||
self.items.len() - 1
|
|
||||||
} else {
|
|
||||||
i - 1
|
|
||||||
}
|
|
||||||
}
|
|
||||||
None => 0,
|
|
||||||
};
|
|
||||||
self.state.select(Some(i));
|
|
||||||
}
|
|
||||||
|
|
||||||
fn unselect(&mut self) {
|
|
||||||
self.state.select(None);
|
|
||||||
}
|
|
||||||
fn push(&mut self, item: T) {
|
|
||||||
self.items.push(item);
|
|
||||||
}
|
|
||||||
fn iter(&self) -> impl Iterator<Item = &T> {
|
|
||||||
self.items.iter()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
struct App {
|
|
||||||
/// Current value of the input box
|
|
||||||
input: String,
|
|
||||||
/// Current input mode
|
|
||||||
input_mode: InputMode,
|
|
||||||
/// History of recorded messages
|
|
||||||
messages: StatefulList<String>,
|
|
||||||
ln_titles: Vec<String>,
|
|
||||||
ln_links: Vec<String>,
|
|
||||||
title: String,
|
|
||||||
ln_id: String,
|
|
||||||
ln_chapters: Vec<String>,
|
|
||||||
ln_chapters_links: Vec<String>,
|
|
||||||
last_page: String,
|
|
||||||
current_page: String,
|
|
||||||
current_page_number: u32,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<'a> App {
|
|
||||||
fn default() -> App {
|
|
||||||
App {
|
|
||||||
input: String::new(),
|
|
||||||
input_mode: InputMode::Normal,
|
|
||||||
messages: StatefulList::with_items(Vec::new()),
|
|
||||||
ln_titles: Vec::new(),
|
|
||||||
ln_links: Vec::new(),
|
|
||||||
title: String::new(),
|
|
||||||
ln_id: String::new(),
|
|
||||||
ln_chapters: Vec::new(),
|
|
||||||
ln_chapters_links: Vec::new(),
|
|
||||||
last_page: String::new(),
|
|
||||||
current_page: String::new(),
|
|
||||||
current_page_number: 0,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn ln_ui(chapter: u32) -> Result<(), Box<dyn Error>> {
|
|
||||||
// setup terminal
|
// setup terminal
|
||||||
let _ = get_ln_json();
|
let _ = get_ln_json();
|
||||||
enable_raw_mode()?;
|
enable_raw_mode()?;
|
||||||
@@ -123,14 +19,15 @@ pub fn ln_ui(chapter: u32) -> Result<(), Box<dyn Error>> {
|
|||||||
let mut terminal = Terminal::new(backend)?;
|
let mut terminal = Terminal::new(backend)?;
|
||||||
|
|
||||||
// create app and run it
|
// create app and run it
|
||||||
let mut app = App::default();
|
let mut app = App::new();
|
||||||
|
app.reader = reader;
|
||||||
let chapter = chapter as f64;
|
let chapter = chapter as f64;
|
||||||
app.current_page_number = 1;
|
app.current_page_number = 1;
|
||||||
if chapter != 0.0 {
|
if chapter != 0.0 {
|
||||||
app.current_page_number = (chapter / 48.0).ceil() as u32;
|
app.current_page_number = (chapter / 48.0).ceil() as u32;
|
||||||
}
|
}
|
||||||
|
|
||||||
let res = run_app(&mut terminal, app);
|
let res = app.run(&mut terminal);
|
||||||
|
|
||||||
// restore terminal
|
// restore terminal
|
||||||
disable_raw_mode()?;
|
disable_raw_mode()?;
|
||||||
@@ -147,242 +44,3 @@ pub fn ln_ui(chapter: u32) -> Result<(), Box<dyn Error>> {
|
|||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn run_app<B: Backend>(terminal: &mut Terminal<B>, mut app: App) -> io::Result<()> {
|
|
||||||
let mut chapter_select = false;
|
|
||||||
|
|
||||||
loop {
|
|
||||||
terminal.draw(|f| ui(f, &mut app))?;
|
|
||||||
if let Event::Key(key) = event::read()? {
|
|
||||||
match app.input_mode {
|
|
||||||
InputMode::Normal => match key.code {
|
|
||||||
KeyCode::Char('i') => {
|
|
||||||
app.input_mode = InputMode::Editing;
|
|
||||||
}
|
|
||||||
KeyCode::Char('q') => {
|
|
||||||
terminal.clear()?;
|
|
||||||
return Ok(());
|
|
||||||
}
|
|
||||||
KeyCode::Left => app.messages.unselect(),
|
|
||||||
KeyCode::Char('h') => {
|
|
||||||
if app.current_page_number > 0 {
|
|
||||||
app.current_page_number -= 1;
|
|
||||||
}
|
|
||||||
app.current_page = get_ln_next_page(&app.ln_id, &app.current_page_number);
|
|
||||||
app.ln_chapters = get_ln_chapters(&app.current_page);
|
|
||||||
app.ln_chapters_links = get_ln_chapters_urls(&app.current_page);
|
|
||||||
app.messages.items.clear();
|
|
||||||
for chapter in app.ln_chapters.iter() {
|
|
||||||
app.messages.push(chapter.to_string());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
KeyCode::Down => app.messages.next(),
|
|
||||||
KeyCode::Char('j') => app.messages.next(),
|
|
||||||
KeyCode::Up => app.messages.previous(),
|
|
||||||
KeyCode::Char('k') => app.messages.previous(),
|
|
||||||
KeyCode::Char('l') => {
|
|
||||||
if app.current_page_number < app.last_page.parse::<u32>().unwrap() {
|
|
||||||
app.current_page_number += 1;
|
|
||||||
}
|
|
||||||
app.current_page = get_ln_next_page(&app.ln_id, &app.current_page_number);
|
|
||||||
app.ln_chapters = get_ln_chapters(&app.current_page);
|
|
||||||
app.ln_chapters_links = get_ln_chapters_urls(&app.current_page);
|
|
||||||
app.messages.items.clear();
|
|
||||||
for chapter in app.ln_chapters.iter() {
|
|
||||||
app.messages.push(chapter.to_string());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
//if KeyCode::Enter => {
|
|
||||||
KeyCode::Enter => {
|
|
||||||
if chapter_select == false {
|
|
||||||
let selected = app.messages.state.selected();
|
|
||||||
app.title = app
|
|
||||||
.messages
|
|
||||||
.iter()
|
|
||||||
.nth(selected.unwrap())
|
|
||||||
.unwrap()
|
|
||||||
.to_string();
|
|
||||||
if app.current_page_number == 1 {
|
|
||||||
let progress = get_ln_progress(&app.title);
|
|
||||||
app.current_page_number = progress.0;
|
|
||||||
app.messages.state.select(Some(progress.1));
|
|
||||||
}
|
|
||||||
let link = app.ln_links[selected.unwrap()].to_string();
|
|
||||||
let html = get_html(&link);
|
|
||||||
app.ln_id = get_ln_id(&html).to_string();
|
|
||||||
app.last_page = get_ln_last_page(&html);
|
|
||||||
app.current_page =
|
|
||||||
get_ln_next_page(&app.ln_id.to_string(), &app.current_page_number);
|
|
||||||
app.ln_chapters = get_ln_chapters(&app.current_page);
|
|
||||||
app.ln_chapters_links = get_ln_chapters_urls(&app.current_page);
|
|
||||||
app.messages.items.clear();
|
|
||||||
for chapter in app.ln_chapters.iter() {
|
|
||||||
app.messages.push(chapter.to_string());
|
|
||||||
}
|
|
||||||
chapter_select = true;
|
|
||||||
} else {
|
|
||||||
let selected = app.messages.state.selected();
|
|
||||||
let chapter_url = app.ln_chapters_links[selected.unwrap()].to_string();
|
|
||||||
let full_text = get_full_text(&chapter_url);
|
|
||||||
if cfg!(target_os = "windows") {
|
|
||||||
use dirs::home_dir;
|
|
||||||
let mut home = format!("{:?}", home_dir()).replace("\\\\", "/");
|
|
||||||
home.drain(0..6);
|
|
||||||
home.drain(home.len() - 2..home.len());
|
|
||||||
let mut file =
|
|
||||||
File::create(format!("{}/AppData/Roaming/log_e", home))
|
|
||||||
.expect("Unable to create file");
|
|
||||||
file.write_all(full_text.as_bytes())
|
|
||||||
.expect("Unable to write to file");
|
|
||||||
file.sync_all().expect("Unable to sync file");
|
|
||||||
} else {
|
|
||||||
let mut file =
|
|
||||||
File::create("/tmp/log_e").expect("Unable to create file");
|
|
||||||
file.write_all(full_text.as_bytes())
|
|
||||||
.expect("Unable to write to file");
|
|
||||||
file.sync_all().expect("Unable to sync file");
|
|
||||||
};
|
|
||||||
terminal.clear()?;
|
|
||||||
let _ = open_bat();
|
|
||||||
write_ln_progress(
|
|
||||||
&app.title,
|
|
||||||
&app.current_page_number,
|
|
||||||
&app.messages.state.selected().unwrap(),
|
|
||||||
);
|
|
||||||
terminal.clear()?;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
_ => {}
|
|
||||||
},
|
|
||||||
InputMode::Editing => match key.code {
|
|
||||||
KeyCode::Enter => {
|
|
||||||
//push app.input into app.messages with '1
|
|
||||||
let search: String = app.input.drain(..).collect();
|
|
||||||
let search = search.replace(" ", "+");
|
|
||||||
let url = "https://readlightnovels.net/?s=".to_string();
|
|
||||||
let url = format!("{}{}", url, search.trim()).trim().to_string();
|
|
||||||
let html = get_html(&url);
|
|
||||||
let ln_list = get_ln_list(html.as_str());
|
|
||||||
app.ln_titles = get_ln_titles(&ln_list);
|
|
||||||
app.ln_links = get_ln_urls(&ln_list);
|
|
||||||
app.messages.items.clear();
|
|
||||||
//remove index 0 of app.ln_titles and app.ln_links
|
|
||||||
app.ln_titles.remove(0);
|
|
||||||
app.ln_links.remove(0);
|
|
||||||
for ln in &app.ln_titles {
|
|
||||||
app.messages.push(ln.to_string());
|
|
||||||
}
|
|
||||||
chapter_select = false;
|
|
||||||
app.input_mode = InputMode::Normal;
|
|
||||||
}
|
|
||||||
KeyCode::Char(c) => {
|
|
||||||
app.input.push(c);
|
|
||||||
}
|
|
||||||
KeyCode::Backspace => {
|
|
||||||
app.input.pop();
|
|
||||||
}
|
|
||||||
KeyCode::Esc => {
|
|
||||||
app.input_mode = InputMode::Normal;
|
|
||||||
}
|
|
||||||
_ => {}
|
|
||||||
},
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn ui<B: Backend>(f: &mut Frame<B>, app: &mut App) {
|
|
||||||
let chunks = Layout::default()
|
|
||||||
.direction(Direction::Vertical)
|
|
||||||
.margin(1)
|
|
||||||
.constraints(
|
|
||||||
[
|
|
||||||
Constraint::Min(1),
|
|
||||||
Constraint::Length(1),
|
|
||||||
Constraint::Length(3),
|
|
||||||
]
|
|
||||||
.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 (msg, style) = match app.input_mode {
|
|
||||||
InputMode::Normal => (
|
|
||||||
vec![
|
|
||||||
Span::raw("Press "),
|
|
||||||
Span::styled("q", Style::default().add_modifier(Modifier::BOLD)),
|
|
||||||
Span::raw(" to exit, "),
|
|
||||||
Span::styled("i", Style::default().add_modifier(Modifier::BOLD)),
|
|
||||||
Span::raw(" to search, "),
|
|
||||||
Span::styled("h", Style::default().add_modifier(Modifier::BOLD)),
|
|
||||||
Span::raw(" to go to the previous page, "),
|
|
||||||
Span::styled("l", Style::default().add_modifier(Modifier::BOLD)),
|
|
||||||
Span::raw(" to go to the next page."),
|
|
||||||
],
|
|
||||||
Style::default().add_modifier(Modifier::RAPID_BLINK),
|
|
||||||
),
|
|
||||||
InputMode::Editing => (
|
|
||||||
vec![
|
|
||||||
Span::raw("Press "),
|
|
||||||
Span::styled("Esc", Style::default().add_modifier(Modifier::BOLD)),
|
|
||||||
Span::raw(" to stop editing, "),
|
|
||||||
Span::styled("Enter", Style::default().add_modifier(Modifier::BOLD)),
|
|
||||||
Span::raw(" to select."),
|
|
||||||
],
|
|
||||||
Style::default(),
|
|
||||||
),
|
|
||||||
};
|
|
||||||
|
|
||||||
let messages: Vec<ListItem> = app
|
|
||||||
.messages
|
|
||||||
.iter()
|
|
||||||
.enumerate()
|
|
||||||
.map(|(i, m)| {
|
|
||||||
let content = vec![Spans::from(Span::raw(format!("{}: {}", i, m)))];
|
|
||||||
ListItem::new(content)
|
|
||||||
})
|
|
||||||
.collect();
|
|
||||||
let messages = List::new(messages)
|
|
||||||
.block(Block::default().borders(Borders::ALL).title("list"))
|
|
||||||
.style(Style::default().fg(Color::White))
|
|
||||||
.highlight_style(
|
|
||||||
Style::default()
|
|
||||||
.bg(Color::Rgb(183, 142, 241))
|
|
||||||
.add_modifier(Modifier::BOLD),
|
|
||||||
)
|
|
||||||
.highlight_symbol(">>");
|
|
||||||
f.render_stateful_widget(messages, chunks[0], &mut app.messages.state);
|
|
||||||
|
|
||||||
let mut text = Text::from(Spans::from(msg));
|
|
||||||
text.patch_style(style);
|
|
||||||
let help_message = Paragraph::new(text);
|
|
||||||
f.render_widget(help_message, chunks[1]);
|
|
||||||
|
|
||||||
let input = Paragraph::new(app.input.as_ref())
|
|
||||||
.style(match app.input_mode {
|
|
||||||
InputMode::Normal => Style::default(),
|
|
||||||
InputMode::Editing => Style::default().fg(Color::Rgb(183, 142, 241)),
|
|
||||||
})
|
|
||||||
.block(Block::default().borders(Borders::all()).title("Input"));
|
|
||||||
f.render_widget(input, chunks[2]);
|
|
||||||
match app.input_mode {
|
|
||||||
InputMode::Normal =>
|
|
||||||
// Hide the cursor. `Frame` does this by default, so we don't need to do anything here
|
|
||||||
{}
|
|
||||||
|
|
||||||
InputMode::Editing => {
|
|
||||||
// Make the cursor visible and ask tui-rs to put it at the specified coordinates after rendering
|
|
||||||
f.set_cursor(
|
|
||||||
// Put cursor past the end of the input text
|
|
||||||
chunks[2].x + app.input.width() as u16 + 1,
|
|
||||||
// Move one line down, from the border to the input line
|
|
||||||
chunks[2].y + 1,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -3,16 +3,15 @@ use std::process::{Command, ExitStatus, Stdio};
|
|||||||
|
|
||||||
#[allow(unused_assignments)]
|
#[allow(unused_assignments)]
|
||||||
pub fn open_bat() -> Result<ExitStatus> {
|
pub fn open_bat() -> Result<ExitStatus> {
|
||||||
let termsize::Size {rows: _, cols} = termsize::get().unwrap();
|
let termsize::Size { rows: _, cols } = termsize::get().unwrap();
|
||||||
let mut path = String::new();
|
let mut path = String::new();
|
||||||
if cfg!(target_os = "windows"){
|
if cfg!(target_os = "windows") {
|
||||||
use dirs::home_dir;
|
use dirs::home_dir;
|
||||||
let mut home = format!("{:?}",home_dir()).replace("\\\\","/");
|
let mut home = format!("{:?}", home_dir()).replace("\\\\", "/");
|
||||||
home.drain(0..6);
|
home.drain(0..6);
|
||||||
home.drain(home.len()-2..home.len());
|
home.drain(home.len() - 2..home.len());
|
||||||
path = format!("{}/AppData/Roaming/log_e",home).to_string();
|
path = format!("{}/AppData/Roaming/log_e", home).to_string();
|
||||||
}
|
} else {
|
||||||
else{
|
|
||||||
path = "/tmp/log_e".to_string();
|
path = "/tmp/log_e".to_string();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -37,3 +36,36 @@ pub fn open_bat() -> Result<ExitStatus> {
|
|||||||
.spawn()?
|
.spawn()?
|
||||||
.wait()
|
.wait()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[allow(unused_assignments)]
|
||||||
|
pub fn open_glow() -> Result<ExitStatus> {
|
||||||
|
let termsize::Size { rows: _, cols } = termsize::get().unwrap();
|
||||||
|
let mut path = String::new();
|
||||||
|
if cfg!(target_os = "windows") {
|
||||||
|
use dirs::home_dir;
|
||||||
|
let mut home = format!("{:?}", home_dir()).replace("\\\\", "/");
|
||||||
|
home.drain(0..6);
|
||||||
|
home.drain(home.len() - 2..home.len());
|
||||||
|
path = format!("{}/AppData/Roaming/log_e", home).to_string();
|
||||||
|
} else {
|
||||||
|
path = "/tmp/log_e".to_string();
|
||||||
|
}
|
||||||
|
|
||||||
|
let soft_wrap = match Command::new("fold")
|
||||||
|
.arg("-s")
|
||||||
|
.arg("-w")
|
||||||
|
.arg((cols - 9).to_string())
|
||||||
|
.arg(path)
|
||||||
|
.stdout(Stdio::piped())
|
||||||
|
.spawn()
|
||||||
|
{
|
||||||
|
Err(why) => panic!("couldn't spawn wc: {}", why),
|
||||||
|
Ok(soft_wrap) => soft_wrap,
|
||||||
|
};
|
||||||
|
|
||||||
|
Command::new("glow")
|
||||||
|
.arg("-p")
|
||||||
|
.stdin(soft_wrap.stdout.unwrap())
|
||||||
|
.spawn()?
|
||||||
|
.wait()
|
||||||
|
}
|
||||||
|
|||||||
189
src/main.rs
189
src/main.rs
@@ -1,136 +1,83 @@
|
|||||||
mod anime;
|
mod anime;
|
||||||
mod helpers;
|
mod helpers;
|
||||||
mod ln;
|
mod ln;
|
||||||
|
mod ui;
|
||||||
|
|
||||||
|
#[macro_use]
|
||||||
|
extern crate lazy_static;
|
||||||
|
|
||||||
use anime::anime::anime_ui;
|
use anime::anime::anime_ui;
|
||||||
use colored::Colorize;
|
|
||||||
//use ln::ui::ln_ui;
|
|
||||||
use ln::ln::ln_ui;
|
use ln::ln::ln_ui;
|
||||||
|
|
||||||
use crate::anime::{player::*, scraper::*, trackers::*};
|
use crate::anime::trackers::*;
|
||||||
use crate::get_token;
|
use crate::get_token;
|
||||||
use crate::helpers::take_input::{int_input, string_input};
|
use crate::helpers::take_input::{int_input, string_input};
|
||||||
|
|
||||||
|
use clap::{Parser, Subcommand};
|
||||||
|
|
||||||
|
#[derive(Subcommand, Debug)]
|
||||||
|
enum KamiMode {
|
||||||
|
#[command(name = "ln", about = "Search Light Novel to read.")]
|
||||||
|
LightNovel,
|
||||||
|
#[command(about = "Search Anime to read.")]
|
||||||
|
Anime,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Parser, Debug)]
|
||||||
|
#[command(author, version, about = "A scraper to read light novels and watch anime in your terminal.", long_about = None)]
|
||||||
|
struct Args {
|
||||||
|
#[command(subcommand)]
|
||||||
|
mode: Option<KamiMode>,
|
||||||
|
|
||||||
|
/// Use anime mode
|
||||||
|
#[arg(short, long)]
|
||||||
|
anime: bool,
|
||||||
|
/// Use light novel mode
|
||||||
|
#[arg(short, long)]
|
||||||
|
ln: bool,
|
||||||
|
|
||||||
|
#[arg(short, long, default_value_t = 0)]
|
||||||
|
chapter: u32,
|
||||||
|
|
||||||
|
#[arg(short = 'C', long, default_value = "0")]
|
||||||
|
cast: String,
|
||||||
|
|
||||||
|
/// Provider for anime or light novel
|
||||||
|
#[arg(short = 'r', long, default_value = "gogo")]
|
||||||
|
provider: String,
|
||||||
|
|
||||||
|
/// Text renderer for light novel
|
||||||
|
#[arg(short = 'R', long, default_value = "bat")]
|
||||||
|
reader: String,
|
||||||
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let mut help = false;
|
let args = Args::parse();
|
||||||
let mut anime = false;
|
|
||||||
let mut ln = false;
|
let mode = match &args.mode {
|
||||||
let mut chapter: u32 = 0;
|
None => {
|
||||||
//let search = option string
|
println!("1: Anime");
|
||||||
let mut count = 0;
|
println!("2: Light Novel");
|
||||||
let mut provider: String = "gogo".to_string();
|
|
||||||
let mut cast = (false, "0".to_string());
|
let opt = int_input("pick your poison: ");
|
||||||
for arg in std::env::args() {
|
|
||||||
if arg == "--help" || arg == "-h" {
|
match opt {
|
||||||
help = true;
|
1 => &KamiMode::Anime,
|
||||||
}
|
2 => &KamiMode::LightNovel,
|
||||||
if arg == "--anime" || arg == "-a" {
|
_ => {
|
||||||
anime = true;
|
println!("invalid option.");
|
||||||
}
|
std::process::exit(0);
|
||||||
if arg == "--provider" || arg == "-r" {
|
|
||||||
if let Some(arg) = std::env::args().nth(count + 1) {
|
|
||||||
//get the next argument and see if it is = to gogo of vrv
|
|
||||||
if arg == "vrv" {
|
|
||||||
provider = "vrv".to_string();
|
|
||||||
count += 1;
|
|
||||||
} else if arg == "gogo" {
|
|
||||||
provider = "gogo".to_string();
|
|
||||||
count += 1;
|
|
||||||
} else {
|
|
||||||
provider = "gogo".to_string();
|
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
provider = "vrv".to_string();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if arg == "--cast" || arg == "-C" {
|
Some(m) => m,
|
||||||
if let Some(arg) = std::env::args().nth(count + 1) {
|
};
|
||||||
cast = (true, String::from(arg))
|
|
||||||
} else {
|
let _ = match mode {
|
||||||
println!("{}", "please provide a ip address".red())
|
&KamiMode::LightNovel => ln_ui(args.chapter, args.reader),
|
||||||
}
|
&KamiMode::Anime => {
|
||||||
|
let token = get_token();
|
||||||
|
anime_ui(token, args.provider, (args.cast == "0", args.cast))
|
||||||
}
|
}
|
||||||
|
};
|
||||||
if arg == "--ln" || arg == "-l" {
|
|
||||||
ln = true;
|
|
||||||
}
|
|
||||||
if arg == "--chapter" || arg == "-c" {
|
|
||||||
if let Some(arg) = std::env::args().nth(count + 1) {
|
|
||||||
chapter = arg.parse::<u32>().unwrap();
|
|
||||||
} else {
|
|
||||||
chapter = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
count += 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if help == true {
|
|
||||||
print_help();
|
|
||||||
}
|
|
||||||
if anime == false && ln == false {
|
|
||||||
println!("1: Anime");
|
|
||||||
println!("2: Light Novel");
|
|
||||||
|
|
||||||
let a = int_input("pick your poison: ");
|
|
||||||
match a {
|
|
||||||
1 => anime = true,
|
|
||||||
2 => ln = true,
|
|
||||||
_ => println!("invalid option. "),
|
|
||||||
};
|
|
||||||
}
|
|
||||||
if anime == true && ln == true {
|
|
||||||
println!("you can only use one of the arguments at a time");
|
|
||||||
std::process::exit(0);
|
|
||||||
}
|
|
||||||
if ln == true {
|
|
||||||
//ln_read(&search, chapter);
|
|
||||||
_ = ln_ui(chapter);
|
|
||||||
} else if anime == true {
|
|
||||||
//anime_stream(search, episode, resume);
|
|
||||||
|
|
||||||
let token = get_token();
|
|
||||||
_ = anime_ui(token, provider, cast);
|
|
||||||
} else {
|
|
||||||
println!("Invalid argument");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn print_help() {
|
|
||||||
println!("anime:\t\t{}", format_args!("{}", "-a --anime".red()));
|
|
||||||
//print blank line
|
|
||||||
println!("");
|
|
||||||
println!(
|
|
||||||
"cast:\t\t{}",
|
|
||||||
format_args!("{} {}", "-C --cast".red(), "<IP Adress>".green())
|
|
||||||
);
|
|
||||||
println!("");
|
|
||||||
println!("light novel:\t{}", format_args!("{}", "-l --ln".red()));
|
|
||||||
//print blank line
|
|
||||||
println!("");
|
|
||||||
println!("chapter:\t{}", format_args!("{}", "-c --chapter".red()));
|
|
||||||
println!(
|
|
||||||
"{}",
|
|
||||||
"after this^^^ argument you can enter a chapter number".green()
|
|
||||||
);
|
|
||||||
println!("{}", "for exaple kami -c 200");
|
|
||||||
//print blank line
|
|
||||||
println!("");
|
|
||||||
println!("provider:\t{}", format_args!("{}", "-r --provider".red()));
|
|
||||||
println!(
|
|
||||||
"{}",
|
|
||||||
"after this^^^ argument you can enter a provider".green()
|
|
||||||
);
|
|
||||||
println!(
|
|
||||||
"if no provider is entered it will default to {}",
|
|
||||||
"vrv".green()
|
|
||||||
);
|
|
||||||
println!(
|
|
||||||
"if the -r argument is not used it will default to {}",
|
|
||||||
"gogo".green()
|
|
||||||
);
|
|
||||||
println!("the providers are {} or {}", "gogo".green(), "vrv".green());
|
|
||||||
println!("");
|
|
||||||
println!("help:\t\t{}", format_args!("{}", "-h --help".red()));
|
|
||||||
//kill the program
|
|
||||||
std::process::exit(0);
|
|
||||||
}
|
}
|
||||||
|
|||||||
411
src/ui/app/anime.rs
Normal file
411
src/ui/app/anime.rs
Normal file
@@ -0,0 +1,411 @@
|
|||||||
|
use crate::ui::{app::app::KamiApp, input::InputMode, list::StatefulList};
|
||||||
|
|
||||||
|
use crate::anime::player::{open_cast, open_video};
|
||||||
|
use crate::anime::scraper::{get_episode_link, get_episodes, get_image, search_anime};
|
||||||
|
use crate::anime::trackers::{
|
||||||
|
get_an_history, get_an_progress, get_user_anime_progress, update_anime_progress,
|
||||||
|
write_an_progress,
|
||||||
|
};
|
||||||
|
|
||||||
|
use crossterm::event::{self, Event, KeyCode};
|
||||||
|
use std::io;
|
||||||
|
use tui::{
|
||||||
|
backend::Backend,
|
||||||
|
layout::{Constraint, Direction, Layout},
|
||||||
|
style::{Color, Modifier, Style},
|
||||||
|
text::{Span, Spans, Text},
|
||||||
|
widgets::{Block, BorderType, Borders, List, ListItem, Paragraph},
|
||||||
|
Frame, Terminal,
|
||||||
|
};
|
||||||
|
use unicode_width::UnicodeWidthStr;
|
||||||
|
use viuer::{print_from_file, terminal_size, Config};
|
||||||
|
|
||||||
|
pub struct App {
|
||||||
|
/// Current value of the input box
|
||||||
|
input: String,
|
||||||
|
animes: (Vec<String>, Vec<String>, Vec<String>),
|
||||||
|
image: String,
|
||||||
|
/// Current input mode
|
||||||
|
input_mode: InputMode,
|
||||||
|
/// History of recorded messages
|
||||||
|
messages: StatefulList<String>,
|
||||||
|
episodes: (Vec<String>, Vec<String>),
|
||||||
|
title: String,
|
||||||
|
ep: u64,
|
||||||
|
progress: i32,
|
||||||
|
anime_id: i32,
|
||||||
|
pub token: String,
|
||||||
|
pub provider: String,
|
||||||
|
pub cast: (bool, String),
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'a> App {
|
||||||
|
fn change_image(&mut self) {
|
||||||
|
//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");
|
||||||
|
get_image(&self.image, &image_path.to_str().unwrap());
|
||||||
|
print_from_file(image_path, &config).expect("Image printing failed.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'a> KamiApp for App {
|
||||||
|
fn new() -> Self {
|
||||||
|
App {
|
||||||
|
input: String::new(),
|
||||||
|
animes: get_an_history(),
|
||||||
|
image: String::new(),
|
||||||
|
input_mode: InputMode::Normal,
|
||||||
|
messages: StatefulList::with_items(Vec::new()),
|
||||||
|
episodes: (Vec::new(), Vec::new()),
|
||||||
|
title: String::new(),
|
||||||
|
ep: 0,
|
||||||
|
progress: 0,
|
||||||
|
anime_id: 0,
|
||||||
|
token: String::new(),
|
||||||
|
provider: String::new(),
|
||||||
|
cast: (false, "0".to_string()),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn run<B: Backend>(&mut self, terminal: &mut Terminal<B>) -> io::Result<()> {
|
||||||
|
let mut ep_select = false;
|
||||||
|
self.messages.items.clear();
|
||||||
|
for anime in &self.animes.1 {
|
||||||
|
self.messages.push(anime.to_string());
|
||||||
|
}
|
||||||
|
self.input_mode = InputMode::Normal;
|
||||||
|
|
||||||
|
loop {
|
||||||
|
terminal.draw(|f| self.ui(f))?;
|
||||||
|
|
||||||
|
if let Event::Key(key) = event::read()? {
|
||||||
|
match self.input_mode {
|
||||||
|
InputMode::Normal => match key.code {
|
||||||
|
KeyCode::Char('i') => {
|
||||||
|
self.input_mode = InputMode::Editing;
|
||||||
|
}
|
||||||
|
KeyCode::Char('q') => {
|
||||||
|
return Ok(());
|
||||||
|
}
|
||||||
|
KeyCode::Left => self.messages.unselect(),
|
||||||
|
KeyCode::Char('h') => self.messages.unselect(),
|
||||||
|
KeyCode::Down => match ep_select {
|
||||||
|
true => {
|
||||||
|
self.messages.next();
|
||||||
|
}
|
||||||
|
false => {
|
||||||
|
self.messages.next();
|
||||||
|
let selected = self.messages.state.selected();
|
||||||
|
self.image = self.animes.2[selected.unwrap()].clone();
|
||||||
|
self.change_image();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
KeyCode::Char('j') => match ep_select {
|
||||||
|
true => {
|
||||||
|
self.messages.next();
|
||||||
|
}
|
||||||
|
false => {
|
||||||
|
self.messages.next();
|
||||||
|
let selected = self.messages.state.selected();
|
||||||
|
self.image = self.animes.2[selected.unwrap()].clone();
|
||||||
|
self.change_image();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
KeyCode::Up => match ep_select {
|
||||||
|
true => {
|
||||||
|
self.messages.previous();
|
||||||
|
}
|
||||||
|
false => {
|
||||||
|
self.messages.previous();
|
||||||
|
let selected = self.messages.state.selected();
|
||||||
|
self.image = self.animes.2[selected.unwrap()].clone();
|
||||||
|
self.change_image();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
KeyCode::Char('k') => match ep_select {
|
||||||
|
true => {
|
||||||
|
self.messages.previous();
|
||||||
|
}
|
||||||
|
false => {
|
||||||
|
self.messages.previous();
|
||||||
|
let selected = self.messages.state.selected();
|
||||||
|
self.image = self.animes.2[selected.unwrap()].clone();
|
||||||
|
self.change_image();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
//if KeyCode::Enter => {
|
||||||
|
KeyCode::Enter => {
|
||||||
|
if ep_select == false {
|
||||||
|
self.progress = 0;
|
||||||
|
let selected = self.messages.state.selected();
|
||||||
|
self.title = self.messages.items[selected.unwrap()].clone();
|
||||||
|
self.anime_id = self.animes.0[selected.unwrap()]
|
||||||
|
.clone()
|
||||||
|
.parse::<i32>()
|
||||||
|
.unwrap();
|
||||||
|
self.episodes = get_episodes(
|
||||||
|
&self.animes.0[selected.unwrap()].parse::<i32>().unwrap(),
|
||||||
|
&self.provider,
|
||||||
|
);
|
||||||
|
self.messages.items.clear();
|
||||||
|
if self.token == "local" || self.anime_id == 0 {
|
||||||
|
self.progress = get_an_progress(&self.title) as i32;
|
||||||
|
self.messages.state.select(Some(self.progress as usize));
|
||||||
|
} else {
|
||||||
|
self.progress =
|
||||||
|
get_user_anime_progress(self.anime_id, self.token.as_str());
|
||||||
|
self.messages.state.select(Some(self.progress as usize));
|
||||||
|
}
|
||||||
|
if self.episodes.0.len() == 1 {
|
||||||
|
let link =
|
||||||
|
get_episode_link(&self.episodes.1[0], &self.provider);
|
||||||
|
if !self.cast.0 {
|
||||||
|
open_video((
|
||||||
|
link.0,
|
||||||
|
format!("{} Episode 1", &self.title),
|
||||||
|
link.1,
|
||||||
|
));
|
||||||
|
} else {
|
||||||
|
open_cast(
|
||||||
|
(link.1, format!("{} Episode 1", &self.title)),
|
||||||
|
&self.cast.1,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
let selected = self.messages.state.selected();
|
||||||
|
let image_url = self.animes.2[selected.unwrap()].clone();
|
||||||
|
if self.token == "local" || self.anime_id == 0 {
|
||||||
|
write_an_progress(
|
||||||
|
(&self.title, &self.anime_id.to_string(), &image_url),
|
||||||
|
&1,
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
update_anime_progress(
|
||||||
|
self.anime_id,
|
||||||
|
1,
|
||||||
|
self.token.as_str(),
|
||||||
|
);
|
||||||
|
write_an_progress(
|
||||||
|
(&self.title, &self.anime_id.to_string(), &image_url),
|
||||||
|
&1,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
for ep in 1..self.episodes.1.len() + 1 {
|
||||||
|
self.messages.push(format!(
|
||||||
|
"Episode {}: {}",
|
||||||
|
ep,
|
||||||
|
self.episodes.0[ep - 1]
|
||||||
|
));
|
||||||
|
}
|
||||||
|
ep_select = true;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
let selected = self.messages.state.selected();
|
||||||
|
self.ep = self
|
||||||
|
.messages
|
||||||
|
.iter()
|
||||||
|
.nth(selected.unwrap())
|
||||||
|
.unwrap()
|
||||||
|
.replace("Episode ", "")
|
||||||
|
.split(":")
|
||||||
|
.collect::<Vec<&str>>()[0]
|
||||||
|
.parse::<u64>()
|
||||||
|
.unwrap();
|
||||||
|
let link = get_episode_link(
|
||||||
|
&self.episodes.1[self.ep as usize - 1],
|
||||||
|
&self.provider,
|
||||||
|
);
|
||||||
|
if !self.cast.0 {
|
||||||
|
open_video((
|
||||||
|
link.0,
|
||||||
|
format!("{} Episode {}", &self.title, self.ep),
|
||||||
|
link.1,
|
||||||
|
));
|
||||||
|
} else {
|
||||||
|
open_cast(
|
||||||
|
(link.0, format!("{} Episode {}", &self.title, self.ep)),
|
||||||
|
&self.cast.1,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
let image_url = &self.image;
|
||||||
|
if self.ep > self.progress as u64 {
|
||||||
|
if self.token == "local" || self.anime_id == 0 {
|
||||||
|
write_an_progress(
|
||||||
|
(&self.title, &self.anime_id.to_string(), &image_url),
|
||||||
|
&self.ep,
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
update_anime_progress(
|
||||||
|
self.anime_id,
|
||||||
|
self.ep as usize,
|
||||||
|
self.token.as_str(),
|
||||||
|
);
|
||||||
|
write_an_progress(
|
||||||
|
(&self.title, &self.anime_id.to_string(), &image_url),
|
||||||
|
&self.ep,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
self.progress = self.ep as i32;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_ => {}
|
||||||
|
},
|
||||||
|
InputMode::Editing => match key.code {
|
||||||
|
KeyCode::Enter => {
|
||||||
|
//push self.input into self.messages with '
|
||||||
|
self.animes = search_anime(self.input.drain(..).collect());
|
||||||
|
self.messages.items.clear();
|
||||||
|
for anime in &self.animes.1 {
|
||||||
|
self.messages.push(anime.to_string());
|
||||||
|
}
|
||||||
|
ep_select = false;
|
||||||
|
self.input_mode = InputMode::Normal;
|
||||||
|
}
|
||||||
|
KeyCode::Char(c) => {
|
||||||
|
self.input.push(c);
|
||||||
|
}
|
||||||
|
KeyCode::Backspace => {
|
||||||
|
self.input.pop();
|
||||||
|
}
|
||||||
|
KeyCode::Esc => {
|
||||||
|
self.input_mode = InputMode::Normal;
|
||||||
|
}
|
||||||
|
_ => {}
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn ui<B: Backend>(&mut self, f: &mut Frame<B>) {
|
||||||
|
let chunks = Layout::default()
|
||||||
|
.direction(Direction::Vertical)
|
||||||
|
.margin(1)
|
||||||
|
.constraints(
|
||||||
|
[
|
||||||
|
Constraint::Min(1),
|
||||||
|
Constraint::Length(1),
|
||||||
|
Constraint::Length(3),
|
||||||
|
]
|
||||||
|
.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 self.input_mode {
|
||||||
|
InputMode::Normal => (
|
||||||
|
vec![
|
||||||
|
Span::raw("Press "),
|
||||||
|
Span::styled("q", Style::default().add_modifier(Modifier::BOLD)),
|
||||||
|
Span::raw(" to exit, "),
|
||||||
|
Span::styled("i", Style::default().add_modifier(Modifier::BOLD)),
|
||||||
|
Span::raw(" to search."),
|
||||||
|
],
|
||||||
|
Style::default().add_modifier(Modifier::RAPID_BLINK),
|
||||||
|
),
|
||||||
|
InputMode::Editing => (
|
||||||
|
vec![
|
||||||
|
Span::raw("Press "),
|
||||||
|
Span::styled("Esc", Style::default().add_modifier(Modifier::BOLD)),
|
||||||
|
Span::raw(" to stop editing, "),
|
||||||
|
Span::styled("Enter", Style::default().add_modifier(Modifier::BOLD)),
|
||||||
|
Span::raw(" to select."),
|
||||||
|
],
|
||||||
|
Style::default(),
|
||||||
|
),
|
||||||
|
};
|
||||||
|
|
||||||
|
let messages: Vec<ListItem> = self
|
||||||
|
.messages
|
||||||
|
.iter()
|
||||||
|
.enumerate()
|
||||||
|
.map(|(i, m)| {
|
||||||
|
let content = vec![Spans::from(Span::raw(format!("{}: {}", i, m)))];
|
||||||
|
ListItem::new(content)
|
||||||
|
})
|
||||||
|
.collect();
|
||||||
|
let messages = List::new(messages)
|
||||||
|
.block(
|
||||||
|
Block::default()
|
||||||
|
.borders(Borders::ALL)
|
||||||
|
.title("list")
|
||||||
|
.border_type(BorderType::Rounded),
|
||||||
|
)
|
||||||
|
.style(Style::default().fg(Color::White))
|
||||||
|
.highlight_style(
|
||||||
|
Style::default()
|
||||||
|
.bg(Color::Rgb(183, 142, 241))
|
||||||
|
.add_modifier(Modifier::BOLD),
|
||||||
|
)
|
||||||
|
.highlight_symbol(">>");
|
||||||
|
f.render_stateful_widget(messages, top_chunks[0], &mut self.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);
|
||||||
|
let help_message = Paragraph::new(text);
|
||||||
|
f.render_widget(help_message, chunks[1]);
|
||||||
|
|
||||||
|
let input = Paragraph::new(self.input.as_ref())
|
||||||
|
.style(match self.input_mode {
|
||||||
|
InputMode::Normal => Style::default(),
|
||||||
|
InputMode::Editing => Style::default().fg(Color::Rgb(183, 142, 241)),
|
||||||
|
})
|
||||||
|
.block(Block::default().borders(Borders::all()).title("Input"));
|
||||||
|
f.render_widget(input, chunks[2]);
|
||||||
|
match self.input_mode {
|
||||||
|
InputMode::Normal =>
|
||||||
|
// Hide the cursor. `Frame` does this by default, so we don't need to do anything here
|
||||||
|
{}
|
||||||
|
|
||||||
|
InputMode::Editing => {
|
||||||
|
// Make the cursor visible and ask tui-rs to put it at the specified coordinates after rendering
|
||||||
|
f.set_cursor(
|
||||||
|
// Put cursor past the end of the input text
|
||||||
|
chunks[2].x + self.input.width() as u16 + 1,
|
||||||
|
// Move one line down, from the border to the input line
|
||||||
|
chunks[2].y + 1,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
8
src/ui/app/app.rs
Normal file
8
src/ui/app/app.rs
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
use std::io;
|
||||||
|
use tui::{backend::Backend, Frame, Terminal};
|
||||||
|
|
||||||
|
pub trait KamiApp {
|
||||||
|
fn new() -> Self;
|
||||||
|
fn run<B: Backend>(&mut self, terminal: &mut Terminal<B>) -> io::Result<()>;
|
||||||
|
fn ui<B: Backend>(&mut self, f: &mut Frame<B>);
|
||||||
|
}
|
||||||
307
src/ui/app/ln.rs
Normal file
307
src/ui/app/ln.rs
Normal file
@@ -0,0 +1,307 @@
|
|||||||
|
use crate::ui::{app::app::KamiApp, input::InputMode, list::StatefulList};
|
||||||
|
|
||||||
|
use crate::ln::open_text::{open_bat, open_glow};
|
||||||
|
use crate::ln::scraper::*;
|
||||||
|
use crate::ln::tracker::*;
|
||||||
|
use crossterm::event::{self, Event, KeyCode};
|
||||||
|
use std::fs::File;
|
||||||
|
use std::io;
|
||||||
|
use std::io::Write;
|
||||||
|
use tui::{
|
||||||
|
backend::Backend,
|
||||||
|
layout::{Constraint, Direction, Layout},
|
||||||
|
style::{Color, Modifier, Style},
|
||||||
|
text::{Span, Spans, Text},
|
||||||
|
widgets::{Block, BorderType, Borders, List, ListItem, Paragraph},
|
||||||
|
Frame, Terminal,
|
||||||
|
};
|
||||||
|
|
||||||
|
use unicode_width::UnicodeWidthStr;
|
||||||
|
|
||||||
|
pub struct App {
|
||||||
|
input: String, // Input box's value
|
||||||
|
input_mode: InputMode,
|
||||||
|
messages: StatefulList<String>, // History of recorded messages
|
||||||
|
ln_titles: Vec<String>,
|
||||||
|
ln_links: Vec<String>,
|
||||||
|
title: String,
|
||||||
|
ln_id: String,
|
||||||
|
ln_chapters: Vec<String>,
|
||||||
|
ln_chapters_links: Vec<String>,
|
||||||
|
last_page: String,
|
||||||
|
current_page: String,
|
||||||
|
pub current_page_number: u32,
|
||||||
|
pub reader: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'a> KamiApp for App {
|
||||||
|
fn new() -> Self {
|
||||||
|
App {
|
||||||
|
input: String::new(),
|
||||||
|
input_mode: InputMode::Normal,
|
||||||
|
messages: StatefulList::with_items(Vec::new()),
|
||||||
|
ln_titles: Vec::new(),
|
||||||
|
ln_links: Vec::new(),
|
||||||
|
title: String::new(),
|
||||||
|
ln_id: String::new(),
|
||||||
|
ln_chapters: Vec::new(),
|
||||||
|
ln_chapters_links: Vec::new(),
|
||||||
|
last_page: String::new(),
|
||||||
|
current_page: String::new(),
|
||||||
|
current_page_number: 0,
|
||||||
|
reader: "bat".to_string(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn run<B: Backend>(&mut self, terminal: &mut Terminal<B>) -> io::Result<()> {
|
||||||
|
let mut chapter_select = false;
|
||||||
|
|
||||||
|
loop {
|
||||||
|
terminal.draw(|f| self.ui(f))?;
|
||||||
|
if let Event::Key(key) = event::read()? {
|
||||||
|
match self.input_mode {
|
||||||
|
InputMode::Normal => match key.code {
|
||||||
|
KeyCode::Char('i') => {
|
||||||
|
self.input_mode = InputMode::Editing;
|
||||||
|
}
|
||||||
|
KeyCode::Char('q') => {
|
||||||
|
terminal.clear()?;
|
||||||
|
return Ok(());
|
||||||
|
}
|
||||||
|
KeyCode::Left => self.messages.unselect(),
|
||||||
|
KeyCode::Char('g') => self.messages.begin(),
|
||||||
|
KeyCode::Char('G') => self.messages.end(),
|
||||||
|
KeyCode::Down => self.messages.next(),
|
||||||
|
KeyCode::Char('j') => self.messages.next(),
|
||||||
|
KeyCode::Up => self.messages.previous(),
|
||||||
|
KeyCode::Char('k') => self.messages.previous(),
|
||||||
|
|
||||||
|
KeyCode::Char('h') => {
|
||||||
|
if self.current_page_number > 0 {
|
||||||
|
self.current_page_number -= 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
self.current_page =
|
||||||
|
get_ln_next_page(&self.ln_id, &self.current_page_number);
|
||||||
|
self.ln_chapters = get_ln_chapters(&self.current_page);
|
||||||
|
self.ln_chapters_links = get_ln_chapters_urls(&self.current_page);
|
||||||
|
self.messages.items.clear();
|
||||||
|
for chapter in self.ln_chapters.iter() {
|
||||||
|
self.messages.push(chapter.to_string());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
KeyCode::Char('l') => {
|
||||||
|
if self.current_page_number < self.last_page.parse::<u32>().unwrap() {
|
||||||
|
self.current_page_number += 1;
|
||||||
|
}
|
||||||
|
self.current_page =
|
||||||
|
get_ln_next_page(&self.ln_id, &self.current_page_number);
|
||||||
|
self.ln_chapters = get_ln_chapters(&self.current_page);
|
||||||
|
self.ln_chapters_links = get_ln_chapters_urls(&self.current_page);
|
||||||
|
self.messages.items.clear();
|
||||||
|
for chapter in self.ln_chapters.iter() {
|
||||||
|
self.messages.push(chapter.to_string());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//if KeyCode::Enter => {
|
||||||
|
KeyCode::Enter => {
|
||||||
|
if chapter_select == false {
|
||||||
|
let selected = self.messages.state.selected();
|
||||||
|
self.title = self
|
||||||
|
.messages
|
||||||
|
.iter()
|
||||||
|
.nth(selected.unwrap())
|
||||||
|
.unwrap()
|
||||||
|
.to_string();
|
||||||
|
if self.current_page_number == 1 {
|
||||||
|
let progress = get_ln_progress(&self.title);
|
||||||
|
self.current_page_number = progress.0;
|
||||||
|
self.messages.state.select(Some(progress.1));
|
||||||
|
}
|
||||||
|
let link = self.ln_links[selected.unwrap()].to_string();
|
||||||
|
let html = get_html(&link);
|
||||||
|
self.ln_id = get_ln_id(&html).to_string();
|
||||||
|
self.last_page = get_ln_last_page(&html);
|
||||||
|
self.current_page = get_ln_next_page(
|
||||||
|
&self.ln_id.to_string(),
|
||||||
|
&self.current_page_number,
|
||||||
|
);
|
||||||
|
self.ln_chapters = get_ln_chapters(&self.current_page);
|
||||||
|
self.ln_chapters_links = get_ln_chapters_urls(&self.current_page);
|
||||||
|
self.messages.items.clear();
|
||||||
|
for chapter in self.ln_chapters.iter() {
|
||||||
|
self.messages.push(chapter.to_string());
|
||||||
|
}
|
||||||
|
chapter_select = true;
|
||||||
|
} else {
|
||||||
|
let selected = self.messages.state.selected();
|
||||||
|
let chapter_url =
|
||||||
|
self.ln_chapters_links[selected.unwrap()].to_string();
|
||||||
|
let full_text = get_full_text(&chapter_url);
|
||||||
|
if cfg!(target_os = "windows") {
|
||||||
|
use dirs::home_dir;
|
||||||
|
let mut home = format!("{:?}", home_dir()).replace("\\\\", "/");
|
||||||
|
home.drain(0..6);
|
||||||
|
home.drain(home.len() - 2..home.len());
|
||||||
|
let mut file =
|
||||||
|
File::create(format!("{}/AppData/Roaming/log_e", home))
|
||||||
|
.expect("Unable to create file");
|
||||||
|
file.write_all(full_text.as_bytes())
|
||||||
|
.expect("Unable to write to file");
|
||||||
|
file.sync_all().expect("Unable to sync file");
|
||||||
|
} else {
|
||||||
|
let mut file =
|
||||||
|
File::create("/tmp/log_e").expect("Unable to create file");
|
||||||
|
file.write_all(full_text.as_bytes())
|
||||||
|
.expect("Unable to write to file");
|
||||||
|
file.sync_all().expect("Unable to sync file");
|
||||||
|
};
|
||||||
|
terminal.clear()?;
|
||||||
|
let _ = match &*self.reader {
|
||||||
|
"bat" => open_bat(),
|
||||||
|
"glow" => open_glow(),
|
||||||
|
&_ => todo!(),
|
||||||
|
};
|
||||||
|
write_ln_progress(
|
||||||
|
&self.title,
|
||||||
|
&self.current_page_number,
|
||||||
|
&self.messages.state.selected().unwrap(),
|
||||||
|
);
|
||||||
|
terminal.clear()?;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_ => {}
|
||||||
|
},
|
||||||
|
InputMode::Editing => match key.code {
|
||||||
|
KeyCode::Enter => {
|
||||||
|
//push self.input into self.messages with '1
|
||||||
|
let search: String = self.input.drain(..).collect();
|
||||||
|
let search = search.replace(" ", "+");
|
||||||
|
let url = "https://readlightnovels.net/?s=".to_string();
|
||||||
|
let url = format!("{}{}", url, search.trim()).trim().to_string();
|
||||||
|
let html = get_html(&url);
|
||||||
|
let ln_list = get_ln_list(html.as_str());
|
||||||
|
self.ln_titles = get_ln_titles(&ln_list);
|
||||||
|
self.ln_links = get_ln_urls(&ln_list);
|
||||||
|
self.messages.items.clear();
|
||||||
|
//remove index 0 of self.ln_titles and self.ln_links
|
||||||
|
self.ln_titles.remove(0);
|
||||||
|
self.ln_links.remove(0);
|
||||||
|
for ln in &self.ln_titles {
|
||||||
|
self.messages.push(ln.to_string());
|
||||||
|
}
|
||||||
|
chapter_select = false;
|
||||||
|
self.input_mode = InputMode::Normal;
|
||||||
|
}
|
||||||
|
KeyCode::Char(c) => {
|
||||||
|
self.input.push(c);
|
||||||
|
}
|
||||||
|
KeyCode::Backspace => {
|
||||||
|
self.input.pop();
|
||||||
|
}
|
||||||
|
KeyCode::Esc => {
|
||||||
|
self.input_mode = InputMode::Normal;
|
||||||
|
}
|
||||||
|
_ => {}
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn ui<B: Backend>(&mut self, f: &mut Frame<B>) {
|
||||||
|
let chunks = Layout::default()
|
||||||
|
.direction(Direction::Vertical)
|
||||||
|
.margin(1)
|
||||||
|
.constraints(
|
||||||
|
[
|
||||||
|
Constraint::Min(1),
|
||||||
|
Constraint::Length(1),
|
||||||
|
Constraint::Length(3),
|
||||||
|
]
|
||||||
|
.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 (msg, style) = match self.input_mode {
|
||||||
|
InputMode::Normal => (
|
||||||
|
vec![
|
||||||
|
Span::raw("Press "),
|
||||||
|
Span::styled("q", Style::default().add_modifier(Modifier::BOLD)),
|
||||||
|
Span::raw(" to exit, "),
|
||||||
|
Span::styled("i", Style::default().add_modifier(Modifier::BOLD)),
|
||||||
|
Span::raw(" to search, "),
|
||||||
|
Span::styled("h", Style::default().add_modifier(Modifier::BOLD)),
|
||||||
|
Span::raw(" to go to the previous page, "),
|
||||||
|
Span::styled("l", Style::default().add_modifier(Modifier::BOLD)),
|
||||||
|
Span::raw(" to go to the next page."),
|
||||||
|
],
|
||||||
|
Style::default().add_modifier(Modifier::RAPID_BLINK),
|
||||||
|
),
|
||||||
|
InputMode::Editing => (
|
||||||
|
vec![
|
||||||
|
Span::raw("Press "),
|
||||||
|
Span::styled("Esc", Style::default().add_modifier(Modifier::BOLD)),
|
||||||
|
Span::raw(" to stop editing, "),
|
||||||
|
Span::styled("Enter", Style::default().add_modifier(Modifier::BOLD)),
|
||||||
|
Span::raw(" to select."),
|
||||||
|
],
|
||||||
|
Style::default(),
|
||||||
|
),
|
||||||
|
};
|
||||||
|
|
||||||
|
let messages: Vec<ListItem> = self
|
||||||
|
.messages
|
||||||
|
.iter()
|
||||||
|
.enumerate()
|
||||||
|
.map(|(i, m)| {
|
||||||
|
let content = vec![Spans::from(Span::raw(format!("{}: {}", i, m)))];
|
||||||
|
ListItem::new(content)
|
||||||
|
})
|
||||||
|
.collect();
|
||||||
|
let messages = List::new(messages)
|
||||||
|
.block(Block::default().borders(Borders::ALL).title("list"))
|
||||||
|
.style(Style::default().fg(Color::White))
|
||||||
|
.highlight_style(
|
||||||
|
Style::default()
|
||||||
|
.bg(Color::Rgb(183, 142, 241))
|
||||||
|
.add_modifier(Modifier::BOLD),
|
||||||
|
)
|
||||||
|
.highlight_symbol(">>");
|
||||||
|
f.render_stateful_widget(messages, chunks[0], &mut self.messages.state);
|
||||||
|
|
||||||
|
let mut text = Text::from(Spans::from(msg));
|
||||||
|
text.patch_style(style);
|
||||||
|
let help_message = Paragraph::new(text);
|
||||||
|
f.render_widget(help_message, chunks[1]);
|
||||||
|
|
||||||
|
let input = Paragraph::new(self.input.as_ref())
|
||||||
|
.style(match self.input_mode {
|
||||||
|
InputMode::Normal => Style::default(),
|
||||||
|
InputMode::Editing => Style::default().fg(Color::Rgb(183, 142, 241)),
|
||||||
|
})
|
||||||
|
.block(Block::default().borders(Borders::all()).title("Input"));
|
||||||
|
f.render_widget(input, chunks[2]);
|
||||||
|
match self.input_mode {
|
||||||
|
InputMode::Normal =>
|
||||||
|
// Hide the cursor. `Frame` does this by default, so we don't need to do anything here
|
||||||
|
{}
|
||||||
|
|
||||||
|
InputMode::Editing => {
|
||||||
|
// Make the cursor visible and ask tui-rs to put it at the specified coordinates after rendering
|
||||||
|
f.set_cursor(
|
||||||
|
// Put cursor past the end of the input text
|
||||||
|
chunks[2].x + self.input.width() as u16 + 1,
|
||||||
|
// Move one line down, from the border to the input line
|
||||||
|
chunks[2].y + 1,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
3
src/ui/app/mod.rs
Normal file
3
src/ui/app/mod.rs
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
pub mod anime;
|
||||||
|
pub mod app;
|
||||||
|
pub mod ln;
|
||||||
4
src/ui/input.rs
Normal file
4
src/ui/input.rs
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
pub enum InputMode {
|
||||||
|
Normal,
|
||||||
|
Editing,
|
||||||
|
}
|
||||||
61
src/ui/list.rs
Normal file
61
src/ui/list.rs
Normal file
@@ -0,0 +1,61 @@
|
|||||||
|
use tui::widgets::ListState;
|
||||||
|
|
||||||
|
pub struct StatefulList<T> {
|
||||||
|
pub state: ListState,
|
||||||
|
pub items: Vec<T>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<T> StatefulList<T> {
|
||||||
|
pub fn with_items(items: Vec<T>) -> StatefulList<T> {
|
||||||
|
StatefulList {
|
||||||
|
state: ListState::default(),
|
||||||
|
items,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn begin(&mut self) {
|
||||||
|
self.state.select(Some(0))
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn end(&mut self) {
|
||||||
|
self.state.select(Some(self.items.len() - 1))
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn next(&mut self) {
|
||||||
|
let i = match self.state.selected() {
|
||||||
|
Some(i) => {
|
||||||
|
if i == self.items.len() - 1 {
|
||||||
|
0
|
||||||
|
} else {
|
||||||
|
i + 1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
None => 0,
|
||||||
|
};
|
||||||
|
self.state.select(Some(i));
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn previous(&mut self) {
|
||||||
|
let i = match self.state.selected() {
|
||||||
|
Some(i) => {
|
||||||
|
if i == 0 {
|
||||||
|
self.items.len() - 1
|
||||||
|
} else {
|
||||||
|
i - 1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
None => 0,
|
||||||
|
};
|
||||||
|
self.state.select(Some(i));
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn unselect(&mut self) {
|
||||||
|
self.state.select(None);
|
||||||
|
}
|
||||||
|
pub fn push(&mut self, item: T) {
|
||||||
|
self.items.push(item);
|
||||||
|
}
|
||||||
|
pub fn iter(&self) -> impl Iterator<Item = &T> {
|
||||||
|
self.items.iter()
|
||||||
|
}
|
||||||
|
}
|
||||||
3
src/ui/mod.rs
Normal file
3
src/ui/mod.rs
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
pub mod app;
|
||||||
|
pub mod input;
|
||||||
|
pub mod list;
|
||||||
Reference in New Issue
Block a user