Commit db597a03bc
Unsigned
Layout: unified · split
Cargo.lock +467 −369
| @@ -9,10 +9,22 @@ source = "registry+https://github.com/rust-lang/crates.io-index" | |||
| 9 | checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" | 9 | checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" |
| 10 | 10 | ||
| 11 | [[package]] | 11 | [[package]] |
| 12 | name = "adler32" | 12 | name = "aho-corasick" |
| 13 | version = "1.2.0" | 13 | version = "0.5.3" |
| 14 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 15 | checksum = "ca972c2ea5f742bfce5687b9aef75506a764f61d37f8f649047846a9686ddb66" | ||
| 16 | dependencies = [ | ||
| 17 | "memchr 0.1.11", | ||
| 18 | ] | ||
| 19 | |||
| 20 | [[package]] | ||
| 21 | name = "android_system_properties" | ||
| 22 | version = "0.1.5" | ||
| 14 | source = "registry+https://github.com/rust-lang/crates.io-index" | 23 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| 15 | checksum = "aae1277d39aeec15cb388266ecc24b11c80469deae6067e17a1a7aa9e5c1f234" | 24 | checksum = "819e7219dbd41043ac279b19830f2efc897156490d7fd6ea916720117ee66311" |
| 25 | dependencies = [ | ||
| 26 | "libc", | ||
| 27 | ] | ||
| 16 | 28 | ||
| 17 | [[package]] | 29 | [[package]] |
| 18 | name = "ansi_colours" | 30 | name = "ansi_colours" |
| @@ -49,15 +61,15 @@ checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" | |||
| 49 | 61 | ||
| 50 | [[package]] | 62 | [[package]] |
| 51 | name = "bumpalo" | 63 | name = "bumpalo" |
| 52 | version = "3.9.1" | 64 | version = "3.11.0" |
| 53 | source = "registry+https://github.com/rust-lang/crates.io-index" | 65 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| 54 | checksum = "a4a45a46ab1f2412e53d3a0ade76ffad2025804294569aae387231a0cd6e0899" | 66 | checksum = "c1ad822118d20d2c234f427000d5acc36eabe1e29a348c89b63dd60b13f28e5d" |
| 55 | 67 | ||
| 56 | [[package]] | 68 | [[package]] |
| 57 | name = "bytemuck" | 69 | name = "bytemuck" |
| 58 | version = "1.9.1" | 70 | version = "1.12.1" |
| 59 | source = "registry+https://github.com/rust-lang/crates.io-index" | 71 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| 60 | checksum = "cdead85bdec19c194affaeeb670c0e41fe23de31459efd1c174d049269cf02cc" | 72 | checksum = "2f5715e491b5a1598fc2bef5a606847b5dc1d48ea625bd3c02c00de8285591da" |
| 61 | 73 | ||
| 62 | [[package]] | 74 | [[package]] |
| 63 | name = "byteorder" | 75 | name = "byteorder" |
| @@ -67,9 +79,9 @@ checksum = "14c189c53d098945499cdfa7ecc63567cf3886b3332b312a5b4585d8d3a6a610" | |||
| 67 | 79 | ||
| 68 | [[package]] | 80 | [[package]] |
| 69 | name = "bytes" | 81 | name = "bytes" |
| 70 | version = "1.1.0" | 82 | version = "1.2.1" |
| 71 | source = "registry+https://github.com/rust-lang/crates.io-index" | 83 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| 72 | checksum = "c4872d67bab6358e59559027aa3b9157c53d9358c51423c17554809a8858e0f8" | 84 | checksum = "ec8a7b6a70fde80372154c65702f00a0f56f3e1c36abbc6c440484be248856db" |
| 73 | 85 | ||
| 74 | [[package]] | 86 | [[package]] |
| 75 | name = "cassowary" | 87 | name = "cassowary" |
| @@ -91,15 +103,14 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" | |||
| 91 | 103 | ||
| 92 | [[package]] | 104 | [[package]] |
| 93 | name = "chrono" | 105 | name = "chrono" |
| 94 | version = "0.4.19" | 106 | version = "0.4.22" |
| 95 | source = "registry+https://github.com/rust-lang/crates.io-index" | 107 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| 96 | checksum = "670ad68c9088c2a963aaa298cb369688cf3f9465ce5e2d4ca10e6e0098a1ce73" | 108 | checksum = "bfd4d1b31faaa3a89d7934dbded3111da0d2ef28e3ebccdb4f0179f5929d1ef1" |
| 97 | dependencies = [ | 109 | dependencies = [ |
| 98 | "libc", | 110 | "iana-time-zone", |
| 99 | "num-integer", | 111 | "num-integer", |
| 100 | "num-traits", | 112 | "num-traits", |
| 101 | "time", | 113 | "winapi 0.3.9", |
| 102 | "winapi", | ||
| 103 | ] | 114 | ] |
| 104 | 115 | ||
| 105 | [[package]] | 116 | [[package]] |
| @@ -110,15 +121,15 @@ checksum = "3d7b894f5411737b7867f4827955924d7c254fc9f4d91a6aad6b097804b1018b" | |||
| 110 | 121 | ||
| 111 | [[package]] | 122 | [[package]] |
| 112 | name = "console" | 123 | name = "console" |
| 113 | version = "0.15.0" | 124 | version = "0.15.1" |
| 114 | source = "registry+https://github.com/rust-lang/crates.io-index" | 125 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| 115 | checksum = "a28b32d32ca44b70c3e4acd7db1babf555fa026e385fb95f18028f88848b3c31" | 126 | checksum = "89eab4d20ce20cea182308bca13088fecea9c05f6776cf287205d41a0ed3c847" |
| 116 | dependencies = [ | 127 | dependencies = [ |
| 117 | "encode_unicode", | 128 | "encode_unicode", |
| 118 | "libc", | 129 | "libc", |
| 119 | "once_cell", | 130 | "once_cell", |
| 120 | "terminal_size", | 131 | "terminal_size", |
| 121 | "winapi", | 132 | "winapi 0.3.9", |
| 122 | ] | 133 | ] |
| 123 | 134 | ||
| 124 | [[package]] | 135 | [[package]] |
| @@ -148,9 +159,9 @@ dependencies = [ | |||
| 148 | 159 | ||
| 149 | [[package]] | 160 | [[package]] |
| 150 | name = "crossbeam-channel" | 161 | name = "crossbeam-channel" |
| 151 | version = "0.5.4" | 162 | version = "0.5.6" |
| 152 | source = "registry+https://github.com/rust-lang/crates.io-index" | 163 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| 153 | checksum = "5aaa7bd5fb665c6864b5f963dd9097905c54125909c7aa94c9e18507cdbe6c53" | 164 | checksum = "c2dd04ddaf88237dc3b8d8f9a3c1004b506b54b3313403944054d23c0870c521" |
| 154 | dependencies = [ | 165 | dependencies = [ |
| 155 | "cfg-if", | 166 | "cfg-if", |
| 156 | "crossbeam-utils", | 167 | "crossbeam-utils", |
| @@ -158,9 +169,9 @@ dependencies = [ | |||
| 158 | 169 | ||
| 159 | [[package]] | 170 | [[package]] |
| 160 | name = "crossbeam-deque" | 171 | name = "crossbeam-deque" |
| 161 | version = "0.8.1" | 172 | version = "0.8.2" |
| 162 | source = "registry+https://github.com/rust-lang/crates.io-index" | 173 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| 163 | checksum = "6455c0ca19f0d2fbf751b908d5c55c1f5cbc65e03c4225427254b46890bdde1e" | 174 | checksum = "715e8152b692bba2d374b53d4875445368fdf21a94751410af607a5ac677d1fc" |
| 164 | dependencies = [ | 175 | dependencies = [ |
| 165 | "cfg-if", | 176 | "cfg-if", |
| 166 | "crossbeam-epoch", | 177 | "crossbeam-epoch", |
| @@ -169,26 +180,26 @@ dependencies = [ | |||
| 169 | 180 | ||
| 170 | [[package]] | 181 | [[package]] |
| 171 | name = "crossbeam-epoch" | 182 | name = "crossbeam-epoch" |
| 172 | version = "0.9.8" | 183 | version = "0.9.10" |
| 173 | source = "registry+https://github.com/rust-lang/crates.io-index" | 184 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| 174 | checksum = "1145cf131a2c6ba0615079ab6a638f7e1973ac9c2634fcbeaaad6114246efe8c" | 185 | checksum = "045ebe27666471bb549370b4b0b3e51b07f56325befa4284db65fc89c02511b1" |
| 175 | dependencies = [ | 186 | dependencies = [ |
| 176 | "autocfg", | 187 | "autocfg", |
| 177 | "cfg-if", | 188 | "cfg-if", |
| 178 | "crossbeam-utils", | 189 | "crossbeam-utils", |
| 179 | "lazy_static", | ||
| 180 | "memoffset", | 190 | "memoffset", |
| 191 | "once_cell", | ||
| 181 | "scopeguard", | 192 | "scopeguard", |
| 182 | ] | 193 | ] |
| 183 | 194 | ||
| 184 | [[package]] | 195 | [[package]] |
| 185 | name = "crossbeam-utils" | 196 | name = "crossbeam-utils" |
| 186 | version = "0.8.8" | 197 | version = "0.8.11" |
| 187 | source = "registry+https://github.com/rust-lang/crates.io-index" | 198 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| 188 | checksum = "0bf124c720b7686e3c2663cf54062ab0f68a88af2fb6a030e87e30bf721fcb38" | 199 | checksum = "51887d4adc7b564537b15adcfb307936f8075dfcd5f00dde9a9f1d29383682bc" |
| 189 | dependencies = [ | 200 | dependencies = [ |
| 190 | "cfg-if", | 201 | "cfg-if", |
| 191 | "lazy_static", | 202 | "once_cell", |
| 192 | ] | 203 | ] |
| 193 | 204 | ||
| 194 | [[package]] | 205 | [[package]] |
| @@ -204,7 +215,24 @@ dependencies = [ | |||
| 204 | "parking_lot", | 215 | "parking_lot", |
| 205 | "signal-hook", | 216 | "signal-hook", |
| 206 | "signal-hook-mio", | 217 | "signal-hook-mio", |
| 207 | "winapi", | 218 | "winapi 0.3.9", |
| 219 | ] | ||
| 220 | |||
| 221 | [[package]] | ||
| 222 | name = "crossterm" | ||
| 223 | version = "0.25.0" | ||
| 224 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 225 | checksum = "e64e6c0fbe2c17357405f7c758c1ef960fce08bdfb2c03d88d2a18d7e09c4b67" | ||
| 226 | dependencies = [ | ||
| 227 | "bitflags", | ||
| 228 | "crossterm_winapi", | ||
| 229 | "libc", | ||
| 230 | "mio", | ||
| 231 | "parking_lot", | ||
| 232 | "serde", | ||
| 233 | "signal-hook", | ||
| 234 | "signal-hook-mio", | ||
| 235 | "winapi 0.3.9", | ||
| 208 | ] | 236 | ] |
| 209 | 237 | ||
| 210 | [[package]] | 238 | [[package]] |
| @@ -213,23 +241,20 @@ version = "0.9.0" | |||
| 213 | source = "registry+https://github.com/rust-lang/crates.io-index" | 241 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| 214 | checksum = "2ae1b35a484aa10e07fe0638d02301c5ad24de82d310ccbd2f3693da5f09bf1c" | 242 | checksum = "2ae1b35a484aa10e07fe0638d02301c5ad24de82d310ccbd2f3693da5f09bf1c" |
| 215 | dependencies = [ | 243 | dependencies = [ |
| 216 | "winapi", | 244 | "winapi 0.3.9", |
| 217 | ] | 245 | ] |
| 218 | 246 | ||
| 219 | [[package]] | 247 | [[package]] |
| 220 | name = "deflate" | 248 | name = "dyn-clone" |
| 221 | version = "1.0.0" | 249 | version = "1.0.9" |
| 222 | source = "registry+https://github.com/rust-lang/crates.io-index" | 250 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| 223 | checksum = "c86f7e25f518f4b81808a2cf1c50996a61f5c2eb394b2393bd87f2a4780a432f" | 251 | checksum = "4f94fa09c2aeea5b8839e414b7b841bf429fd25b9c522116ac97ee87856d88b2" |
| 224 | dependencies = [ | ||
| 225 | "adler32", | ||
| 226 | ] | ||
| 227 | 252 | ||
| 228 | [[package]] | 253 | [[package]] |
| 229 | name = "either" | 254 | name = "either" |
| 230 | version = "1.6.1" | 255 | version = "1.8.0" |
| 231 | source = "registry+https://github.com/rust-lang/crates.io-index" | 256 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| 232 | checksum = "e78d4f1cc4ae33bbfc157ed5d5a5ef3bc29227303d595861deb238fcec4e9457" | 257 | checksum = "90e5c1c8368803113bf0c9584fc495a58b86dc8a29edbf8fe877d21d9507e797" |
| 233 | 258 | ||
| 234 | [[package]] | 259 | [[package]] |
| 235 | name = "encode_unicode" | 260 | name = "encode_unicode" |
| @@ -248,46 +273,43 @@ dependencies = [ | |||
| 248 | 273 | ||
| 249 | [[package]] | 274 | [[package]] |
| 250 | name = "exr" | 275 | name = "exr" |
| 251 | version = "1.4.2" | 276 | version = "1.5.0" |
| 252 | source = "registry+https://github.com/rust-lang/crates.io-index" | 277 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| 253 | checksum = "14cc0e06fb5f67e5d6beadf3a382fec9baca1aa751c6d5368fdeee7e5932c215" | 278 | checksum = "78c26a90d9dd411a3d119d6f55752fb4c134ca243250c32fb9cab7b2561638d2" |
| 254 | dependencies = [ | 279 | dependencies = [ |
| 255 | "bit_field", | 280 | "bit_field", |
| 256 | "deflate", | ||
| 257 | "flume", | 281 | "flume", |
| 258 | "half", | 282 | "half", |
| 259 | "inflate", | ||
| 260 | "lebe", | 283 | "lebe", |
| 284 | "miniz_oxide", | ||
| 261 | "smallvec", | 285 | "smallvec", |
| 262 | "threadpool", | 286 | "threadpool", |
| 263 | ] | 287 | ] |
| 264 | 288 | ||
| 265 | [[package]] | 289 | [[package]] |
| 266 | name = "fastrand" | 290 | name = "fastrand" |
| 267 | version = "1.7.0" | 291 | version = "1.8.0" |
| 268 | source = "registry+https://github.com/rust-lang/crates.io-index" | 292 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| 269 | checksum = "c3fcf0cee53519c866c09b5de1f6c56ff9d647101f81c1964fa632e148896cdf" | 293 | checksum = "a7a407cfaa3385c4ae6b23e84623d48c2798d06e3e6a1878f7f59f17b3f86499" |
| 270 | dependencies = [ | 294 | dependencies = [ |
| 271 | "instant", | 295 | "instant", |
| 272 | ] | 296 | ] |
| 273 | 297 | ||
| 274 | [[package]] | 298 | [[package]] |
| 275 | name = "flate2" | 299 | name = "flate2" |
| 276 | version = "1.0.23" | 300 | version = "1.0.24" |
| 277 | source = "registry+https://github.com/rust-lang/crates.io-index" | 301 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| 278 | checksum = "b39522e96686d38f4bc984b9198e3a0613264abaebaff2c5c918bfa6b6da09af" | 302 | checksum = "f82b0f4c27ad9f8bfd1f3208d882da2b09c301bc1c828fd3a00d0216d2fbbff6" |
| 279 | dependencies = [ | 303 | dependencies = [ |
| 280 | "cfg-if", | ||
| 281 | "crc32fast", | 304 | "crc32fast", |
| 282 | "libc", | ||
| 283 | "miniz_oxide", | 305 | "miniz_oxide", |
| 284 | ] | 306 | ] |
| 285 | 307 | ||
| 286 | [[package]] | 308 | [[package]] |
| 287 | name = "flume" | 309 | name = "flume" |
| 288 | version = "0.10.12" | 310 | version = "0.10.14" |
| 289 | source = "registry+https://github.com/rust-lang/crates.io-index" | 311 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| 290 | checksum = "843c03199d0c0ca54bc1ea90ac0d507274c28abcc4f691ae8b4eaa375087c76a" | 312 | checksum = "1657b4441c3403d9f7b3409e47575237dac27b1b5726df654a6ecbf92f0f7577" |
| 291 | dependencies = [ | 313 | dependencies = [ |
| 292 | "futures-core", | 314 | "futures-core", |
| 293 | "futures-sink", | 315 | "futures-sink", |
| @@ -319,19 +341,18 @@ checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b" | |||
| 319 | 341 | ||
| 320 | [[package]] | 342 | [[package]] |
| 321 | name = "form_urlencoded" | 343 | name = "form_urlencoded" |
| 322 | version = "1.0.1" | 344 | version = "1.1.0" |
| 323 | source = "registry+https://github.com/rust-lang/crates.io-index" | 345 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| 324 | checksum = "5fc25a87fa4fd2094bffb06925852034d90a17f0d1e05197d4956d3555752191" | 346 | checksum = "a9c384f161156f5260c24a097c56119f9be8c798586aecc13afbcbe7b7e26bf8" |
| 325 | dependencies = [ | 347 | dependencies = [ |
| 326 | "matches", | ||
| 327 | "percent-encoding", | 348 | "percent-encoding", |
| 328 | ] | 349 | ] |
| 329 | 350 | ||
| 330 | [[package]] | 351 | [[package]] |
| 331 | name = "futures" | 352 | name = "futures" |
| 332 | version = "0.3.21" | 353 | version = "0.3.24" |
| 333 | source = "registry+https://github.com/rust-lang/crates.io-index" | 354 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| 334 | checksum = "f73fe65f54d1e12b726f517d3e2135ca3125a437b6d998caf1962961f7172d9e" | 355 | checksum = "7f21eda599937fba36daeb58a22e8f5cee2d14c4a17b5b7739c7c8e5e3b8230c" |
| 335 | dependencies = [ | 356 | dependencies = [ |
| 336 | "futures-channel", | 357 | "futures-channel", |
| 337 | "futures-core", | 358 | "futures-core", |
| @@ -344,9 +365,9 @@ dependencies = [ | |||
| 344 | 365 | ||
| 345 | [[package]] | 366 | [[package]] |
| 346 | name = "futures-channel" | 367 | name = "futures-channel" |
| 347 | version = "0.3.21" | 368 | version = "0.3.24" |
| 348 | source = "registry+https://github.com/rust-lang/crates.io-index" | 369 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| 349 | checksum = "c3083ce4b914124575708913bca19bfe887522d6e2e6d0952943f5eac4a74010" | 370 | checksum = "30bdd20c28fadd505d0fd6712cdfcb0d4b5648baf45faef7f852afb2399bb050" |
| 350 | dependencies = [ | 371 | dependencies = [ |
| 351 | "futures-core", | 372 | "futures-core", |
| 352 | "futures-sink", | 373 | "futures-sink", |
| @@ -354,15 +375,15 @@ dependencies = [ | |||
| 354 | 375 | ||
| 355 | [[package]] | 376 | [[package]] |
| 356 | name = "futures-core" | 377 | name = "futures-core" |
| 357 | version = "0.3.21" | 378 | version = "0.3.24" |
| 358 | source = "registry+https://github.com/rust-lang/crates.io-index" | 379 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| 359 | checksum = "0c09fd04b7e4073ac7156a9539b57a484a8ea920f79c7c675d05d289ab6110d3" | 380 | checksum = "4e5aa3de05362c3fb88de6531e6296e85cde7739cccad4b9dfeeb7f6ebce56bf" |
| 360 | 381 | ||
| 361 | [[package]] | 382 | [[package]] |
| 362 | name = "futures-executor" | 383 | name = "futures-executor" |
| 363 | version = "0.3.21" | 384 | version = "0.3.24" |
| 364 | source = "registry+https://github.com/rust-lang/crates.io-index" | 385 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| 365 | checksum = "9420b90cfa29e327d0429f19be13e7ddb68fa1cccb09d65e5706b8c7a749b8a6" | 386 | checksum = "9ff63c23854bee61b6e9cd331d523909f238fc7636290b96826e9cfa5faa00ab" |
| 366 | dependencies = [ | 387 | dependencies = [ |
| 367 | "futures-core", | 388 | "futures-core", |
| 368 | "futures-task", | 389 | "futures-task", |
| @@ -371,15 +392,15 @@ dependencies = [ | |||
| 371 | 392 | ||
| 372 | [[package]] | 393 | [[package]] |
| 373 | name = "futures-io" | 394 | name = "futures-io" |
| 374 | version = "0.3.21" | 395 | version = "0.3.24" |
| 375 | source = "registry+https://github.com/rust-lang/crates.io-index" | 396 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| 376 | checksum = "fc4045962a5a5e935ee2fdedaa4e08284547402885ab326734432bed5d12966b" | 397 | checksum = "bbf4d2a7a308fd4578637c0b17c7e1c7ba127b8f6ba00b29f717e9655d85eb68" |
| 377 | 398 | ||
| 378 | [[package]] | 399 | [[package]] |
| 379 | name = "futures-macro" | 400 | name = "futures-macro" |
| 380 | version = "0.3.21" | 401 | version = "0.3.24" |
| 381 | source = "registry+https://github.com/rust-lang/crates.io-index" | 402 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| 382 | checksum = "33c1e13800337f4d4d7a316bf45a567dbcb6ffe087f16424852d97e97a91f512" | 403 | checksum = "42cd15d1c7456c04dbdf7e88bcd69760d74f3a798d6444e16974b505b0e62f17" |
| 383 | dependencies = [ | 404 | dependencies = [ |
| 384 | "proc-macro2", | 405 | "proc-macro2", |
| 385 | "quote", | 406 | "quote", |
| @@ -388,21 +409,21 @@ dependencies = [ | |||
| 388 | 409 | ||
| 389 | [[package]] | 410 | [[package]] |
| 390 | name = "futures-sink" | 411 | name = "futures-sink" |
| 391 | version = "0.3.21" | 412 | version = "0.3.24" |
| 392 | source = "registry+https://github.com/rust-lang/crates.io-index" | 413 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| 393 | checksum = "21163e139fa306126e6eedaf49ecdb4588f939600f0b1e770f4205ee4b7fa868" | 414 | checksum = "21b20ba5a92e727ba30e72834706623d94ac93a725410b6a6b6fbc1b07f7ba56" |
| 394 | 415 | ||
| 395 | [[package]] | 416 | [[package]] |
| 396 | name = "futures-task" | 417 | name = "futures-task" |
| 397 | version = "0.3.21" | 418 | version = "0.3.24" |
| 398 | source = "registry+https://github.com/rust-lang/crates.io-index" | 419 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| 399 | checksum = "57c66a976bf5909d801bbef33416c41372779507e7a6b3a5e25e4749c58f776a" | 420 | checksum = "a6508c467c73851293f390476d4491cf4d227dbabcd4170f3bb6044959b294f1" |
| 400 | 421 | ||
| 401 | [[package]] | 422 | [[package]] |
| 402 | name = "futures-util" | 423 | name = "futures-util" |
| 403 | version = "0.3.21" | 424 | version = "0.3.24" |
| 404 | source = "registry+https://github.com/rust-lang/crates.io-index" | 425 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| 405 | checksum = "d8b7abd5d659d9b90c8cba917f6ec750a74e2dc23902ef9cd4cc8c8b22e6036a" | 426 | checksum = "44fb6cb1be61cc1d2e43b262516aafcf63b241cffdb1d3fa115f91d9c7b09c90" |
| 406 | dependencies = [ | 427 | dependencies = [ |
| 407 | "futures-channel", | 428 | "futures-channel", |
| 408 | "futures-core", | 429 | "futures-core", |
| @@ -410,7 +431,7 @@ dependencies = [ | |||
| 410 | "futures-macro", | 431 | "futures-macro", |
| 411 | "futures-sink", | 432 | "futures-sink", |
| 412 | "futures-task", | 433 | "futures-task", |
| 413 | "memchr", | 434 | "memchr 2.5.0", |
| 414 | "pin-project-lite", | 435 | "pin-project-lite", |
| 415 | "pin-utils", | 436 | "pin-utils", |
| 416 | "slab", | 437 | "slab", |
| @@ -418,22 +439,22 @@ dependencies = [ | |||
| 418 | 439 | ||
| 419 | [[package]] | 440 | [[package]] |
| 420 | name = "getrandom" | 441 | name = "getrandom" |
| 421 | version = "0.2.6" | 442 | version = "0.2.7" |
| 422 | source = "registry+https://github.com/rust-lang/crates.io-index" | 443 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| 423 | checksum = "9be70c98951c83b8d2f8f60d7065fa6d5146873094452a1008da8c2f1e4205ad" | 444 | checksum = "4eb1a864a501629691edf6c15a593b7a51eebaa1e8468e9ddc623de7c9b58ec6" |
| 424 | dependencies = [ | 445 | dependencies = [ |
| 425 | "cfg-if", | 446 | "cfg-if", |
| 426 | "js-sys", | 447 | "js-sys", |
| 427 | "libc", | 448 | "libc", |
| 428 | "wasi 0.10.2+wasi-snapshot-preview1", | 449 | "wasi", |
| 429 | "wasm-bindgen", | 450 | "wasm-bindgen", |
| 430 | ] | 451 | ] |
| 431 | 452 | ||
| 432 | [[package]] | 453 | [[package]] |
| 433 | name = "gif" | 454 | name = "gif" |
| 434 | version = "0.11.3" | 455 | version = "0.11.4" |
| 435 | source = "registry+https://github.com/rust-lang/crates.io-index" | 456 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| 436 | checksum = "c3a7187e78088aead22ceedeee99779455b23fc231fe13ec443f99bb71694e5b" | 457 | checksum = "3edd93c6756b4dfaf2709eafcc345ba2636565295c198a9cfbf75fa5e3e00b06" |
| 437 | dependencies = [ | 458 | dependencies = [ |
| 438 | "color_quant", | 459 | "color_quant", |
| 439 | "weezl", | 460 | "weezl", |
| @@ -441,9 +462,9 @@ dependencies = [ | |||
| 441 | 462 | ||
| 442 | [[package]] | 463 | [[package]] |
| 443 | name = "h2" | 464 | name = "h2" |
| 444 | version = "0.3.13" | 465 | version = "0.3.14" |
| 445 | source = "registry+https://github.com/rust-lang/crates.io-index" | 466 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| 446 | checksum = "37a82c6d637fc9515a4694bbf1cb2457b79d81ce52b3108bdeea58b07dd34a57" | 467 | checksum = "5ca32592cf21ac7ccab1825cd87f6c9b3d9022c44d086172ed0966bec8af30be" |
| 447 | dependencies = [ | 468 | dependencies = [ |
| 448 | "bytes", | 469 | "bytes", |
| 449 | "fnv", | 470 | "fnv", |
| @@ -466,9 +487,9 @@ checksum = "eabb4a44450da02c90444cf74558da904edde8fb4e9035a9a6a4e15445af0bd7" | |||
| 466 | 487 | ||
| 467 | [[package]] | 488 | [[package]] |
| 468 | name = "hashbrown" | 489 | name = "hashbrown" |
| 469 | version = "0.11.2" | 490 | version = "0.12.3" |
| 470 | source = "registry+https://github.com/rust-lang/crates.io-index" | 491 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| 471 | checksum = "ab5ef0d4909ef3724cc8cce6ccc8572c5c817592e9285f5464f8e86f8bd3726e" | 492 | checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888" |
| 472 | 493 | ||
| 473 | [[package]] | 494 | [[package]] |
| 474 | name = "hermit-abi" | 495 | name = "hermit-abi" |
| @@ -485,20 +506,14 @@ version = "0.5.3" | |||
| 485 | source = "registry+https://github.com/rust-lang/crates.io-index" | 506 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| 486 | checksum = "2456aef2e6b6a9784192ae780c0f15bc57df0e918585282325e8c8ac27737654" | 507 | checksum = "2456aef2e6b6a9784192ae780c0f15bc57df0e918585282325e8c8ac27737654" |
| 487 | dependencies = [ | 508 | dependencies = [ |
| 488 | "winapi", | 509 | "winapi 0.3.9", |
| 489 | ] | 510 | ] |
| 490 | 511 | ||
| 491 | [[package]] | ||
| 492 | name = "hrtime" | ||
| 493 | version = "0.2.0" | ||
| 494 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 495 | checksum = "2a80870ee775a6b862265eb04a8d61d1b1ef8e4c423154a52ba6a1e3ff24836c" | ||
| 496 | |||
| 497 | [[package]] | 512 | [[package]] |
| 498 | name = "http" | 513 | name = "http" |
| 499 | version = "0.2.6" | 514 | version = "0.2.8" |
| 500 | source = "registry+https://github.com/rust-lang/crates.io-index" | 515 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| 501 | checksum = "31f4c6746584866f0feabcc69893c5b51beef3831656a968ed7ae254cdc4fd03" | 516 | checksum = "75f43d41e26995c17e71ee126451dd3941010b0514a81a9d11f3b341debc2399" |
| 502 | dependencies = [ | 517 | dependencies = [ |
| 503 | "bytes", | 518 | "bytes", |
| 504 | "fnv", | 519 | "fnv", |
| @@ -507,9 +522,9 @@ dependencies = [ | |||
| 507 | 522 | ||
| 508 | [[package]] | 523 | [[package]] |
| 509 | name = "http-body" | 524 | name = "http-body" |
| 510 | version = "0.4.4" | 525 | version = "0.4.5" |
| 511 | source = "registry+https://github.com/rust-lang/crates.io-index" | 526 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| 512 | checksum = "1ff4f84919677303da5f147645dbea6b1881f368d03ac84e1dc09031ebd7b2c6" | 527 | checksum = "d5f38f16d184e36f2408a55281cd658ecbd3ca05cce6d6510a176eca393e26d1" |
| 513 | dependencies = [ | 528 | dependencies = [ |
| 514 | "bytes", | 529 | "bytes", |
| 515 | "http", | 530 | "http", |
| @@ -518,9 +533,9 @@ dependencies = [ | |||
| 518 | 533 | ||
| 519 | [[package]] | 534 | [[package]] |
| 520 | name = "httparse" | 535 | name = "httparse" |
| 521 | version = "1.7.0" | 536 | version = "1.8.0" |
| 522 | source = "registry+https://github.com/rust-lang/crates.io-index" | 537 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| 523 | checksum = "6330e8a36bd8c859f3fa6d9382911fbb7147ec39807f63b923933a247240b9ba" | 538 | checksum = "d897f394bad6a705d5f4104762e116a75639e470d80901eed05a860a95cb1904" |
| 524 | 539 | ||
| 525 | [[package]] | 540 | [[package]] |
| 526 | name = "httpdate" | 541 | name = "httpdate" |
| @@ -530,9 +545,9 @@ checksum = "c4a1e36c821dbe04574f602848a19f742f4fb3c98d40449f11bcad18d6b17421" | |||
| 530 | 545 | ||
| 531 | [[package]] | 546 | [[package]] |
| 532 | name = "hyper" | 547 | name = "hyper" |
| 533 | version = "0.14.18" | 548 | version = "0.14.20" |
| 534 | source = "registry+https://github.com/rust-lang/crates.io-index" | 549 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| 535 | checksum = "b26ae0a80afebe130861d90abf98e3814a4f28a4c6ffeb5ab8ebb2be311e0ef2" | 550 | checksum = "02c929dc5c39e335a03c405292728118860721b10190d98c2a0f0efd5baafbac" |
| 536 | dependencies = [ | 551 | dependencies = [ |
| 537 | "bytes", | 552 | "bytes", |
| 538 | "futures-channel", | 553 | "futures-channel", |
| @@ -565,22 +580,35 @@ dependencies = [ | |||
| 565 | "tokio-native-tls", | 580 | "tokio-native-tls", |
| 566 | ] | 581 | ] |
| 567 | 582 | ||
| 583 | [[package]] | ||
| 584 | name = "iana-time-zone" | ||
| 585 | version = "0.1.47" | ||
| 586 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 587 | checksum = "4c495f162af0bf17656d0014a0eded5f3cd2f365fdd204548c2869db89359dc7" | ||
| 588 | dependencies = [ | ||
| 589 | "android_system_properties", | ||
| 590 | "core-foundation-sys", | ||
| 591 | "js-sys", | ||
| 592 | "once_cell", | ||
| 593 | "wasm-bindgen", | ||
| 594 | "winapi 0.3.9", | ||
| 595 | ] | ||
| 596 | |||
| 568 | [[package]] | 597 | [[package]] |
| 569 | name = "idna" | 598 | name = "idna" |
| 570 | version = "0.2.3" | 599 | version = "0.3.0" |
| 571 | source = "registry+https://github.com/rust-lang/crates.io-index" | 600 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| 572 | checksum = "418a0a6fab821475f634efe3ccc45c013f742efe03d853e8d3355d5cb850ecf8" | 601 | checksum = "e14ddfc70884202db2244c223200c204c2bda1bc6e0998d11b5e024d657209e6" |
| 573 | dependencies = [ | 602 | dependencies = [ |
| 574 | "matches", | ||
| 575 | "unicode-bidi", | 603 | "unicode-bidi", |
| 576 | "unicode-normalization", | 604 | "unicode-normalization", |
| 577 | ] | 605 | ] |
| 578 | 606 | ||
| 579 | [[package]] | 607 | [[package]] |
| 580 | name = "image" | 608 | name = "image" |
| 581 | version = "0.24.2" | 609 | version = "0.24.3" |
| 582 | source = "registry+https://github.com/rust-lang/crates.io-index" | 610 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| 583 | checksum = "28edd9d7bc256be2502e325ac0628bde30b7001b9b52e0abe31a1a9dc2701212" | 611 | checksum = "7e30ca2ecf7666107ff827a8e481de6a132a9b687ed3bb20bb1c144a36c00964" |
| 584 | dependencies = [ | 612 | dependencies = [ |
| 585 | "bytemuck", | 613 | "bytemuck", |
| 586 | "byteorder", | 614 | "byteorder", |
| @@ -588,7 +616,6 @@ dependencies = [ | |||
| 588 | "exr", | 616 | "exr", |
| 589 | "gif", | 617 | "gif", |
| 590 | "jpeg-decoder", | 618 | "jpeg-decoder", |
| 591 | "num-iter", | ||
| 592 | "num-rational", | 619 | "num-rational", |
| 593 | "num-traits", | 620 | "num-traits", |
| 594 | "png", | 621 | "png", |
| @@ -598,23 +625,14 @@ dependencies = [ | |||
| 598 | 625 | ||
| 599 | [[package]] | 626 | [[package]] |
| 600 | name = "indexmap" | 627 | name = "indexmap" |
| 601 | version = "1.8.1" | 628 | version = "1.9.1" |
| 602 | source = "registry+https://github.com/rust-lang/crates.io-index" | 629 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| 603 | checksum = "0f647032dfaa1f8b6dc29bd3edb7bbef4861b8b8007ebb118d6db284fd59f6ee" | 630 | checksum = "10a35a97730320ffe8e2d410b5d3b69279b98d2c14bdb8b70ea89ecf7888d41e" |
| 604 | dependencies = [ | 631 | dependencies = [ |
| 605 | "autocfg", | 632 | "autocfg", |
| 606 | "hashbrown", | 633 | "hashbrown", |
| 607 | ] | 634 | ] |
| 608 | 635 | ||
| 609 | [[package]] | ||
| 610 | name = "inflate" | ||
| 611 | version = "0.4.5" | ||
| 612 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 613 | checksum = "1cdb29978cc5797bd8dcc8e5bf7de604891df2a8dc576973d71a281e916db2ff" | ||
| 614 | dependencies = [ | ||
| 615 | "adler32", | ||
| 616 | ] | ||
| 617 | |||
| 618 | [[package]] | 636 | [[package]] |
| 619 | name = "instant" | 637 | name = "instant" |
| 620 | version = "0.1.12" | 638 | version = "0.1.12" |
| @@ -626,9 +644,9 @@ dependencies = [ | |||
| 626 | 644 | ||
| 627 | [[package]] | 645 | [[package]] |
| 628 | name = "invidious" | 646 | name = "invidious" |
| 629 | version = "0.2.1" | 647 | version = "0.3.2" |
| 630 | source = "registry+https://github.com/rust-lang/crates.io-index" | 648 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| 631 | checksum = "b6d4c6a7a9048464b7265d607d7d94469143ae51bc76338a103f7d088c0e5da7" | 649 | checksum = "c0768e9ab3b6d2f3ce235e6c85167d3e78cde11fb08c0811c5f320c6f5a4834e" |
| 632 | dependencies = [ | 650 | dependencies = [ |
| 633 | "reqwest", | 651 | "reqwest", |
| 634 | "serde", | 652 | "serde", |
| @@ -643,28 +661,44 @@ checksum = "879d54834c8c76457ef4293a689b2a8c59b076067ad77b15efafbb05f92a592b" | |||
| 643 | 661 | ||
| 644 | [[package]] | 662 | [[package]] |
| 645 | name = "itoa" | 663 | name = "itoa" |
| 646 | version = "1.0.1" | 664 | version = "1.0.3" |
| 647 | source = "registry+https://github.com/rust-lang/crates.io-index" | 665 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| 648 | checksum = "1aab8fc367588b89dcee83ab0fd66b72b50b72fa1904d7095045ace2b0c81c35" | 666 | checksum = "6c8af84674fe1f223a982c933a0ee1086ac4d4052aa0fb8060c12c6ad838e754" |
| 649 | 667 | ||
| 650 | [[package]] | 668 | [[package]] |
| 651 | name = "jpeg-decoder" | 669 | name = "jpeg-decoder" |
| 652 | version = "0.2.5" | 670 | version = "0.2.6" |
| 653 | source = "registry+https://github.com/rust-lang/crates.io-index" | 671 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| 654 | checksum = "be7ef4b99870f0c9f2fc2f20dbef72707e2bcca675bb9196734cf433e999b0c5" | 672 | checksum = "9478aa10f73e7528198d75109c8be5cd7d15fb530238040148d5f9a22d4c5b3b" |
| 655 | dependencies = [ | 673 | dependencies = [ |
| 656 | "rayon", | 674 | "rayon", |
| 657 | ] | 675 | ] |
| 658 | 676 | ||
| 659 | [[package]] | 677 | [[package]] |
| 660 | name = "js-sys" | 678 | name = "js-sys" |
| 661 | version = "0.3.57" | 679 | version = "0.3.59" |
| 662 | source = "registry+https://github.com/rust-lang/crates.io-index" | 680 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| 663 | checksum = "671a26f820db17c2a2750743f1dd03bafd15b98c9f30c7c2628c024c05d73397" | 681 | checksum = "258451ab10b34f8af53416d1fdab72c22e805f0c92a1136d59470ec0b11138b2" |
| 664 | dependencies = [ | 682 | dependencies = [ |
| 665 | "wasm-bindgen", | 683 | "wasm-bindgen", |
| 666 | ] | 684 | ] |
| 667 | 685 | ||
| 686 | [[package]] | ||
| 687 | name = "kernel32-sys" | ||
| 688 | version = "0.2.2" | ||
| 689 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 690 | checksum = "7507624b29483431c0ba2d82aece8ca6cdba9382bff4ddd0f7490560c056098d" | ||
| 691 | dependencies = [ | ||
| 692 | "winapi 0.2.8", | ||
| 693 | "winapi-build", | ||
| 694 | ] | ||
| 695 | |||
| 696 | [[package]] | ||
| 697 | name = "lazy_static" | ||
| 698 | version = "0.2.11" | ||
| 699 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 700 | checksum = "76f033c7ad61445c5b347c7382dd1237847eb1bce590fe50365dcb33d546be73" | ||
| 701 | |||
| 668 | [[package]] | 702 | [[package]] |
| 669 | name = "lazy_static" | 703 | name = "lazy_static" |
| 670 | version = "1.4.0" | 704 | version = "1.4.0" |
| @@ -673,27 +707,21 @@ checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" | |||
| 673 | 707 | ||
| 674 | [[package]] | 708 | [[package]] |
| 675 | name = "lebe" | 709 | name = "lebe" |
| 676 | version = "0.5.1" | 710 | version = "0.5.2" |
| 677 | source = "registry+https://github.com/rust-lang/crates.io-index" | 711 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| 678 | checksum = "7efd1d698db0759e6ef11a7cd44407407399a910c774dd804c64c032da7826ff" | 712 | checksum = "03087c2bad5e1034e8cace5926dec053fb3790248370865f5117a7d0213354c8" |
| 679 | 713 | ||
| 680 | [[package]] | 714 | [[package]] |
| 681 | name = "libc" | 715 | name = "libc" |
| 682 | version = "0.2.124" | 716 | version = "0.2.132" |
| 683 | source = "registry+https://github.com/rust-lang/crates.io-index" | 717 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| 684 | checksum = "21a41fed9d98f27ab1c6d161da622a4fa35e8a54a8adc24bbf3ddd0ef70b0e50" | 718 | checksum = "8371e4e5341c3a96db127eb2465ac681ced4c433e01dd0e938adbef26ba93ba5" |
| 685 | |||
| 686 | [[package]] | ||
| 687 | name = "linked-hash-map" | ||
| 688 | version = "0.5.4" | ||
| 689 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 690 | checksum = "7fb9b38af92608140b86b693604b9ffcc5824240a484d1ecd4795bacb2fe88f3" | ||
| 691 | 719 | ||
| 692 | [[package]] | 720 | [[package]] |
| 693 | name = "lock_api" | 721 | name = "lock_api" |
| 694 | version = "0.4.7" | 722 | version = "0.4.8" |
| 695 | source = "registry+https://github.com/rust-lang/crates.io-index" | 723 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| 696 | checksum = "327fa5b6a6940e4699ec49a9beae1ea4845c6bab9314e4f84ac68742139d8c53" | 724 | checksum = "9f80bf5aacaf25cbfc8210d1cfb718f2bf3b11c4c54e5afe36c236853a8ec390" |
| 697 | dependencies = [ | 725 | dependencies = [ |
| 698 | "autocfg", | 726 | "autocfg", |
| 699 | "scopeguard", | 727 | "scopeguard", |
| @@ -701,24 +729,33 @@ dependencies = [ | |||
| 701 | 729 | ||
| 702 | [[package]] | 730 | [[package]] |
| 703 | name = "log" | 731 | name = "log" |
| 704 | version = "0.4.16" | 732 | version = "0.4.17" |
| 705 | source = "registry+https://github.com/rust-lang/crates.io-index" | 733 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| 706 | checksum = "6389c490849ff5bc16be905ae24bc913a9c8892e19b2341dbc175e14c341c2b8" | 734 | checksum = "abb12e687cfb44aa40f41fc3978ef76448f9b6038cad6aef4259d3c095a2382e" |
| 707 | dependencies = [ | 735 | dependencies = [ |
| 708 | "cfg-if", | 736 | "cfg-if", |
| 709 | ] | 737 | ] |
| 710 | 738 | ||
| 711 | [[package]] | 739 | [[package]] |
| 712 | name = "matches" | 740 | name = "make-cmd" |
| 713 | version = "0.1.9" | 741 | version = "0.1.0" |
| 742 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 743 | checksum = "a8ca8afbe8af1785e09636acb5a41e08a765f5f0340568716c18a8700ba3c0d3" | ||
| 744 | |||
| 745 | [[package]] | ||
| 746 | name = "memchr" | ||
| 747 | version = "0.1.11" | ||
| 714 | source = "registry+https://github.com/rust-lang/crates.io-index" | 748 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| 715 | checksum = "a3e378b66a060d48947b590737b30a1be76706c8dd7b8ba0f2fe3989c68a853f" | 749 | checksum = "d8b629fb514376c675b98c1421e80b151d3817ac42d7c667717d282761418d20" |
| 750 | dependencies = [ | ||
| 751 | "libc", | ||
| 752 | ] | ||
| 716 | 753 | ||
| 717 | [[package]] | 754 | [[package]] |
| 718 | name = "memchr" | 755 | name = "memchr" |
| 719 | version = "2.4.1" | 756 | version = "2.5.0" |
| 720 | source = "registry+https://github.com/rust-lang/crates.io-index" | 757 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| 721 | checksum = "308cc39be01b73d0d18f82a0e7b2a3df85245f84af96fdddc5d202d27e47b86a" | 758 | checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d" |
| 722 | 759 | ||
| 723 | [[package]] | 760 | [[package]] |
| 724 | name = "memoffset" | 761 | name = "memoffset" |
| @@ -737,34 +774,23 @@ checksum = "2a60c7ce501c71e03a9c9c0d35b861413ae925bd979cc7a4e30d060069aaac8d" | |||
| 737 | 774 | ||
| 738 | [[package]] | 775 | [[package]] |
| 739 | name = "miniz_oxide" | 776 | name = "miniz_oxide" |
| 740 | version = "0.5.1" | 777 | version = "0.5.4" |
| 741 | source = "registry+https://github.com/rust-lang/crates.io-index" | 778 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| 742 | checksum = "d2b29bd4bc3f33391105ebee3589c19197c4271e3e5a9ec9bfe8127eeff8f082" | 779 | checksum = "96590ba8f175222643a85693f33d26e9c8a015f599c216509b1a6894af675d34" |
| 743 | dependencies = [ | 780 | dependencies = [ |
| 744 | "adler", | 781 | "adler", |
| 745 | ] | 782 | ] |
| 746 | 783 | ||
| 747 | [[package]] | 784 | [[package]] |
| 748 | name = "mio" | 785 | name = "mio" |
| 749 | version = "0.8.2" | 786 | version = "0.8.4" |
| 750 | source = "registry+https://github.com/rust-lang/crates.io-index" | 787 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| 751 | checksum = "52da4364ffb0e4fe33a9841a98a3f3014fb964045ce4f7a45a398243c8d6b0c9" | 788 | checksum = "57ee1c23c7c63b0c9250c339ffdc69255f110b298b901b9f6c82547b7b87caaf" |
| 752 | dependencies = [ | 789 | dependencies = [ |
| 753 | "libc", | 790 | "libc", |
| 754 | "log", | 791 | "log", |
| 755 | "miow", | 792 | "wasi", |
| 756 | "ntapi", | 793 | "windows-sys", |
| 757 | "wasi 0.11.0+wasi-snapshot-preview1", | ||
| 758 | "winapi", | ||
| 759 | ] | ||
| 760 | |||
| 761 | [[package]] | ||
| 762 | name = "miow" | ||
| 763 | version = "0.3.7" | ||
| 764 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 765 | checksum = "b9f1c5b025cda876f66ef43a113f91ebc9f4ccef34843000e0adf6ebbab84e21" | ||
| 766 | dependencies = [ | ||
| 767 | "winapi", | ||
| 768 | ] | 794 | ] |
| 769 | 795 | ||
| 770 | [[package]] | 796 | [[package]] |
| @@ -782,7 +808,7 @@ version = "0.2.10" | |||
| 782 | source = "registry+https://github.com/rust-lang/crates.io-index" | 808 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| 783 | checksum = "fd7e2f3618557f980e0b17e8856252eee3c97fa12c54dff0ca290fb6266ca4a9" | 809 | checksum = "fd7e2f3618557f980e0b17e8856252eee3c97fa12c54dff0ca290fb6266ca4a9" |
| 784 | dependencies = [ | 810 | dependencies = [ |
| 785 | "lazy_static", | 811 | "lazy_static 1.4.0", |
| 786 | "libc", | 812 | "libc", |
| 787 | "log", | 813 | "log", |
| 788 | "openssl", | 814 | "openssl", |
| @@ -794,15 +820,6 @@ dependencies = [ | |||
| 794 | "tempfile", | 820 | "tempfile", |
| 795 | ] | 821 | ] |
| 796 | 822 | ||
| 797 | [[package]] | ||
| 798 | name = "ntapi" | ||
| 799 | version = "0.3.7" | ||
| 800 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 801 | checksum = "c28774a7fd2fbb4f0babd8237ce554b73af68021b5f695a3cebd6c59bac0980f" | ||
| 802 | dependencies = [ | ||
| 803 | "winapi", | ||
| 804 | ] | ||
| 805 | |||
| 806 | [[package]] | 823 | [[package]] |
| 807 | name = "num-integer" | 824 | name = "num-integer" |
| 808 | version = "0.1.45" | 825 | version = "0.1.45" |
| @@ -813,22 +830,11 @@ dependencies = [ | |||
| 813 | "num-traits", | 830 | "num-traits", |
| 814 | ] | 831 | ] |
| 815 | 832 | ||
| 816 | [[package]] | ||
| 817 | name = "num-iter" | ||
| 818 | version = "0.1.43" | ||
| 819 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 820 | checksum = "7d03e6c028c5dc5cac6e2dec0efda81fc887605bb3d884578bb6d6bf7514e252" | ||
| 821 | dependencies = [ | ||
| 822 | "autocfg", | ||
| 823 | "num-integer", | ||
| 824 | "num-traits", | ||
| 825 | ] | ||
| 826 | |||
| 827 | [[package]] | 833 | [[package]] |
| 828 | name = "num-rational" | 834 | name = "num-rational" |
| 829 | version = "0.4.0" | 835 | version = "0.4.1" |
| 830 | source = "registry+https://github.com/rust-lang/crates.io-index" | 836 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| 831 | checksum = "d41702bd167c2df5520b384281bc111a4b5efcf7fbc4c9c222c815b07e0a6a6a" | 837 | checksum = "0638a1c9d0a3c0914158145bc76cff373a75a627e6ecbfb71cbe6f453a5a19b0" |
| 832 | dependencies = [ | 838 | dependencies = [ |
| 833 | "autocfg", | 839 | "autocfg", |
| 834 | "num-integer", | 840 | "num-integer", |
| @@ -856,24 +862,36 @@ dependencies = [ | |||
| 856 | 862 | ||
| 857 | [[package]] | 863 | [[package]] |
| 858 | name = "once_cell" | 864 | name = "once_cell" |
| 859 | version = "1.10.0" | 865 | version = "1.14.0" |
| 860 | source = "registry+https://github.com/rust-lang/crates.io-index" | 866 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| 861 | checksum = "87f3e037eac156d1775da914196f0f37741a274155e34a0b7e427c35d2a2ecb9" | 867 | checksum = "2f7254b99e31cad77da24b08ebf628882739a608578bb1bcdfc1f9c21260d7c0" |
| 862 | 868 | ||
| 863 | [[package]] | 869 | [[package]] |
| 864 | name = "openssl" | 870 | name = "openssl" |
| 865 | version = "0.10.38" | 871 | version = "0.10.41" |
| 866 | source = "registry+https://github.com/rust-lang/crates.io-index" | 872 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| 867 | checksum = "0c7ae222234c30df141154f159066c5093ff73b63204dcda7121eb082fc56a95" | 873 | checksum = "618febf65336490dfcf20b73f885f5651a0c89c64c2d4a8c3662585a70bf5bd0" |
| 868 | dependencies = [ | 874 | dependencies = [ |
| 869 | "bitflags", | 875 | "bitflags", |
| 870 | "cfg-if", | 876 | "cfg-if", |
| 871 | "foreign-types", | 877 | "foreign-types", |
| 872 | "libc", | 878 | "libc", |
| 873 | "once_cell", | 879 | "once_cell", |
| 880 | "openssl-macros", | ||
| 874 | "openssl-sys", | 881 | "openssl-sys", |
| 875 | ] | 882 | ] |
| 876 | 883 | ||
| 884 | [[package]] | ||
| 885 | name = "openssl-macros" | ||
| 886 | version = "0.1.0" | ||
| 887 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 888 | checksum = "b501e44f11665960c7e7fcf062c7d96a14ade4aa98116c004b2e37b5be7d736c" | ||
| 889 | dependencies = [ | ||
| 890 | "proc-macro2", | ||
| 891 | "quote", | ||
| 892 | "syn", | ||
| 893 | ] | ||
| 894 | |||
| 877 | [[package]] | 895 | [[package]] |
| 878 | name = "openssl-probe" | 896 | name = "openssl-probe" |
| 879 | version = "0.1.5" | 897 | version = "0.1.5" |
| @@ -882,9 +900,9 @@ checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf" | |||
| 882 | 900 | ||
| 883 | [[package]] | 901 | [[package]] |
| 884 | name = "openssl-sys" | 902 | name = "openssl-sys" |
| 885 | version = "0.9.72" | 903 | version = "0.9.75" |
| 886 | source = "registry+https://github.com/rust-lang/crates.io-index" | 904 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| 887 | checksum = "7e46109c383602735fa0a2e48dd2b7c892b048e1bf69e5c3b1d804b7d9c203cb" | 905 | checksum = "e5f9bd0c2710541a3cda73d6f9ac4f1b240de4ae261065d309dbe73d9dceb42f" |
| 888 | dependencies = [ | 906 | dependencies = [ |
| 889 | "autocfg", | 907 | "autocfg", |
| 890 | "cc", | 908 | "cc", |
| @@ -895,9 +913,9 @@ dependencies = [ | |||
| 895 | 913 | ||
| 896 | [[package]] | 914 | [[package]] |
| 897 | name = "parking_lot" | 915 | name = "parking_lot" |
| 898 | version = "0.12.0" | 916 | version = "0.12.1" |
| 899 | source = "registry+https://github.com/rust-lang/crates.io-index" | 917 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| 900 | checksum = "87f5ec2493a61ac0506c0f4199f99070cbe83857b0337006a30f3e6719b8ef58" | 918 | checksum = "3742b2c103b9f06bc9fff0a37ff4912935851bee6d36f3c02bcc755bcfec228f" |
| 901 | dependencies = [ | 919 | dependencies = [ |
| 902 | "lock_api", | 920 | "lock_api", |
| 903 | "parking_lot_core", | 921 | "parking_lot_core", |
| @@ -905,9 +923,9 @@ dependencies = [ | |||
| 905 | 923 | ||
| 906 | [[package]] | 924 | [[package]] |
| 907 | name = "parking_lot_core" | 925 | name = "parking_lot_core" |
| 908 | version = "0.9.2" | 926 | version = "0.9.3" |
| 909 | source = "registry+https://github.com/rust-lang/crates.io-index" | 927 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| 910 | checksum = "995f667a6c822200b0433ac218e05582f0e2efa1b922a3fd2fbaadc5f87bab37" | 928 | checksum = "09a279cbf25cb0757810394fbc1e359949b59e348145c643a939a525692e6929" |
| 911 | dependencies = [ | 929 | dependencies = [ |
| 912 | "cfg-if", | 930 | "cfg-if", |
| 913 | "libc", | 931 | "libc", |
| @@ -918,24 +936,24 @@ dependencies = [ | |||
| 918 | 936 | ||
| 919 | [[package]] | 937 | [[package]] |
| 920 | name = "percent-encoding" | 938 | name = "percent-encoding" |
| 921 | version = "2.1.0" | 939 | version = "2.2.0" |
| 922 | source = "registry+https://github.com/rust-lang/crates.io-index" | 940 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| 923 | checksum = "d4fd5641d01c8f18a23da7b6fe29298ff4b55afcccdf78973b24cf3175fee32e" | 941 | checksum = "478c572c3d73181ff3c2539045f6eb99e5491218eae919370993b890cdbdd98e" |
| 924 | 942 | ||
| 925 | [[package]] | 943 | [[package]] |
| 926 | name = "pin-project" | 944 | name = "pin-project" |
| 927 | version = "1.0.10" | 945 | version = "1.0.12" |
| 928 | source = "registry+https://github.com/rust-lang/crates.io-index" | 946 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| 929 | checksum = "58ad3879ad3baf4e44784bc6a718a8698867bb991f8ce24d1bcbe2cfb4c3a75e" | 947 | checksum = "ad29a609b6bcd67fee905812e544992d216af9d755757c05ed2d0e15a74c6ecc" |
| 930 | dependencies = [ | 948 | dependencies = [ |
| 931 | "pin-project-internal", | 949 | "pin-project-internal", |
| 932 | ] | 950 | ] |
| 933 | 951 | ||
| 934 | [[package]] | 952 | [[package]] |
| 935 | name = "pin-project-internal" | 953 | name = "pin-project-internal" |
| 936 | version = "1.0.10" | 954 | version = "1.0.12" |
| 937 | source = "registry+https://github.com/rust-lang/crates.io-index" | 955 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| 938 | checksum = "744b6f092ba29c3650faf274db506afd39944f48420f6c86b17cfe0ee1cb36bb" | 956 | checksum = "069bdb1e05adc7a8990dce9cc75370895fbe4e3d58b9b73bf1aee56359344a55" |
| 939 | dependencies = [ | 957 | dependencies = [ |
| 940 | "proc-macro2", | 958 | "proc-macro2", |
| 941 | "quote", | 959 | "quote", |
| @@ -944,9 +962,9 @@ dependencies = [ | |||
| 944 | 962 | ||
| 945 | [[package]] | 963 | [[package]] |
| 946 | name = "pin-project-lite" | 964 | name = "pin-project-lite" |
| 947 | version = "0.2.8" | 965 | version = "0.2.9" |
| 948 | source = "registry+https://github.com/rust-lang/crates.io-index" | 966 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| 949 | checksum = "e280fbe77cc62c91527259e9442153f4688736748d24660126286329742b4c6c" | 967 | checksum = "e0a7ae3ac2f1173085d398531c705756c94a4c56843785df85a60c1a0afac116" |
| 950 | 968 | ||
| 951 | [[package]] | 969 | [[package]] |
| 952 | name = "pin-utils" | 970 | name = "pin-utils" |
| @@ -962,39 +980,39 @@ checksum = "1df8c4ec4b0627e53bdf214615ad287367e482558cf84b109250b37464dc03ae" | |||
| 962 | 980 | ||
| 963 | [[package]] | 981 | [[package]] |
| 964 | name = "png" | 982 | name = "png" |
| 965 | version = "0.17.5" | 983 | version = "0.17.6" |
| 966 | source = "registry+https://github.com/rust-lang/crates.io-index" | 984 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| 967 | checksum = "dc38c0ad57efb786dd57b9864e5b18bae478c00c824dc55a38bbc9da95dde3ba" | 985 | checksum = "8f0e7f4c94ec26ff209cee506314212639d6c91b80afb82984819fafce9df01c" |
| 968 | dependencies = [ | 986 | dependencies = [ |
| 969 | "bitflags", | 987 | "bitflags", |
| 970 | "crc32fast", | 988 | "crc32fast", |
| 971 | "deflate", | 989 | "flate2", |
| 972 | "miniz_oxide", | 990 | "miniz_oxide", |
| 973 | ] | 991 | ] |
| 974 | 992 | ||
| 975 | [[package]] | 993 | [[package]] |
| 976 | name = "proc-macro2" | 994 | name = "proc-macro2" |
| 977 | version = "1.0.37" | 995 | version = "1.0.43" |
| 978 | source = "registry+https://github.com/rust-lang/crates.io-index" | 996 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| 979 | checksum = "ec757218438d5fda206afc041538b2f6d889286160d649a86a24d37e1235afd1" | 997 | checksum = "0a2ca2c61bc9f3d74d2886294ab7b9853abd9c1ad903a3ac7815c58989bb7bab" |
| 980 | dependencies = [ | 998 | dependencies = [ |
| 981 | "unicode-xid", | 999 | "unicode-ident", |
| 982 | ] | 1000 | ] |
| 983 | 1001 | ||
| 984 | [[package]] | 1002 | [[package]] |
| 985 | name = "quote" | 1003 | name = "quote" |
| 986 | version = "1.0.18" | 1004 | version = "1.0.21" |
| 987 | source = "registry+https://github.com/rust-lang/crates.io-index" | 1005 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| 988 | checksum = "a1feb54ed693b93a84e14094943b84b7c4eae204c512b7ccb95ab0c66d278ad1" | 1006 | checksum = "bbe448f377a7d6961e30f5955f9b8d106c3f5e449d493ee1b125c1d43c2b5179" |
| 989 | dependencies = [ | 1007 | dependencies = [ |
| 990 | "proc-macro2", | 1008 | "proc-macro2", |
| 991 | ] | 1009 | ] |
| 992 | 1010 | ||
| 993 | [[package]] | 1011 | [[package]] |
| 994 | name = "rayon" | 1012 | name = "rayon" |
| 995 | version = "1.5.2" | 1013 | version = "1.5.3" |
| 996 | source = "registry+https://github.com/rust-lang/crates.io-index" | 1014 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| 997 | checksum = "fd249e82c21598a9a426a4e00dd7adc1d640b22445ec8545feef801d1a74c221" | 1015 | checksum = "bd99e5772ead8baa5215278c9b15bf92087709e9c1b2d1f97cdb5a183c933a7d" |
| 998 | dependencies = [ | 1016 | dependencies = [ |
| 999 | "autocfg", | 1017 | "autocfg", |
| 1000 | "crossbeam-deque", | 1018 | "crossbeam-deque", |
| @@ -1004,9 +1022,9 @@ dependencies = [ | |||
| 1004 | 1022 | ||
| 1005 | [[package]] | 1023 | [[package]] |
| 1006 | name = "rayon-core" | 1024 | name = "rayon-core" |
| 1007 | version = "1.9.2" | 1025 | version = "1.9.3" |
| 1008 | source = "registry+https://github.com/rust-lang/crates.io-index" | 1026 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| 1009 | checksum = "9f51245e1e62e1f1629cbfec37b5793bbabcaeb90f30e94d2ba03564687353e4" | 1027 | checksum = "258bcdb5ac6dad48491bb2992db6b7cf74878b0384908af124823d118c99683f" |
| 1010 | dependencies = [ | 1028 | dependencies = [ |
| 1011 | "crossbeam-channel", | 1029 | "crossbeam-channel", |
| 1012 | "crossbeam-deque", | 1030 | "crossbeam-deque", |
| @@ -1016,27 +1034,46 @@ dependencies = [ | |||
| 1016 | 1034 | ||
| 1017 | [[package]] | 1035 | [[package]] |
| 1018 | name = "redox_syscall" | 1036 | name = "redox_syscall" |
| 1019 | version = "0.2.13" | 1037 | version = "0.2.16" |
| 1020 | source = "registry+https://github.com/rust-lang/crates.io-index" | 1038 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| 1021 | checksum = "62f25bc4c7e55e0b0b7a1d43fb893f4fa1361d0abe38b9ce4f323c2adfe6ef42" | 1039 | checksum = "fb5a58c1855b4b6819d59012155603f0b22ad30cad752600aadfcb695265519a" |
| 1022 | dependencies = [ | 1040 | dependencies = [ |
| 1023 | "bitflags", | 1041 | "bitflags", |
| 1024 | ] | 1042 | ] |
| 1025 | 1043 | ||
| 1044 | [[package]] | ||
| 1045 | name = "regex" | ||
| 1046 | version = "0.1.80" | ||
| 1047 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 1048 | checksum = "4fd4ace6a8cf7860714a2c2280d6c1f7e6a413486c13298bbc86fd3da019402f" | ||
| 1049 | dependencies = [ | ||
| 1050 | "aho-corasick", | ||
| 1051 | "memchr 0.1.11", | ||
| 1052 | "regex-syntax", | ||
| 1053 | "thread_local", | ||
| 1054 | "utf8-ranges", | ||
| 1055 | ] | ||
| 1056 | |||
| 1057 | [[package]] | ||
| 1058 | name = "regex-syntax" | ||
| 1059 | version = "0.3.9" | ||
| 1060 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 1061 | checksum = "f9ec002c35e86791825ed294b50008eea9ddfc8def4420124fbc6b08db834957" | ||
| 1062 | |||
| 1026 | [[package]] | 1063 | [[package]] |
| 1027 | name = "remove_dir_all" | 1064 | name = "remove_dir_all" |
| 1028 | version = "0.5.3" | 1065 | version = "0.5.3" |
| 1029 | source = "registry+https://github.com/rust-lang/crates.io-index" | 1066 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| 1030 | checksum = "3acd125665422973a33ac9d3dd2df85edad0f4ae9b00dafb1a05e43a9f5ef8e7" | 1067 | checksum = "3acd125665422973a33ac9d3dd2df85edad0f4ae9b00dafb1a05e43a9f5ef8e7" |
| 1031 | dependencies = [ | 1068 | dependencies = [ |
| 1032 | "winapi", | 1069 | "winapi 0.3.9", |
| 1033 | ] | 1070 | ] |
| 1034 | 1071 | ||
| 1035 | [[package]] | 1072 | [[package]] |
| 1036 | name = "reqwest" | 1073 | name = "reqwest" |
| 1037 | version = "0.11.10" | 1074 | version = "0.11.11" |
| 1038 | source = "registry+https://github.com/rust-lang/crates.io-index" | 1075 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| 1039 | checksum = "46a1f7aa4f35e5e8b4160449f51afc758f0ce6454315a9fa7d0d113e958c41eb" | 1076 | checksum = "b75aa69a3f06bbcc66ede33af2af253c6f7a86b1ca0033f60c580a27074fbf92" |
| 1040 | dependencies = [ | 1077 | dependencies = [ |
| 1041 | "base64", | 1078 | "base64", |
| 1042 | "bytes", | 1079 | "bytes", |
| @@ -1050,7 +1087,7 @@ dependencies = [ | |||
| 1050 | "hyper-tls", | 1087 | "hyper-tls", |
| 1051 | "ipnet", | 1088 | "ipnet", |
| 1052 | "js-sys", | 1089 | "js-sys", |
| 1053 | "lazy_static", | 1090 | "lazy_static 1.4.0", |
| 1054 | "log", | 1091 | "log", |
| 1055 | "mime", | 1092 | "mime", |
| 1056 | "native-tls", | 1093 | "native-tls", |
| @@ -1061,6 +1098,7 @@ dependencies = [ | |||
| 1061 | "serde_urlencoded", | 1098 | "serde_urlencoded", |
| 1062 | "tokio", | 1099 | "tokio", |
| 1063 | "tokio-native-tls", | 1100 | "tokio-native-tls", |
| 1101 | "tower-service", | ||
| 1064 | "url", | 1102 | "url", |
| 1065 | "wasm-bindgen", | 1103 | "wasm-bindgen", |
| 1066 | "wasm-bindgen-futures", | 1104 | "wasm-bindgen-futures", |
| @@ -1070,27 +1108,27 @@ dependencies = [ | |||
| 1070 | 1108 | ||
| 1071 | [[package]] | 1109 | [[package]] |
| 1072 | name = "rgb" | 1110 | name = "rgb" |
| 1073 | version = "0.8.32" | 1111 | version = "0.8.33" |
| 1074 | source = "registry+https://github.com/rust-lang/crates.io-index" | 1112 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| 1075 | checksum = "e74fdc210d8f24a7dbfedc13b04ba5764f5232754ccebfdf5fff1bad791ccbc6" | 1113 | checksum = "c3b221de559e4a29df3b957eec92bc0de6bc8eaf6ca9cfed43e5e1d67ff65a34" |
| 1076 | dependencies = [ | 1114 | dependencies = [ |
| 1077 | "bytemuck", | 1115 | "bytemuck", |
| 1078 | ] | 1116 | ] |
| 1079 | 1117 | ||
| 1080 | [[package]] | 1118 | [[package]] |
| 1081 | name = "ryu" | 1119 | name = "ryu" |
| 1082 | version = "1.0.9" | 1120 | version = "1.0.11" |
| 1083 | source = "registry+https://github.com/rust-lang/crates.io-index" | 1121 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| 1084 | checksum = "73b4b750c782965c211b42f022f59af1fbceabdd026623714f104152f1ec149f" | 1122 | checksum = "4501abdff3ae82a1c1b477a17252eb69cee9e66eb915c1abaa4f44d873df9f09" |
| 1085 | 1123 | ||
| 1086 | [[package]] | 1124 | [[package]] |
| 1087 | name = "schannel" | 1125 | name = "schannel" |
| 1088 | version = "0.1.19" | 1126 | version = "0.1.20" |
| 1089 | source = "registry+https://github.com/rust-lang/crates.io-index" | 1127 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| 1090 | checksum = "8f05ba609c234e60bee0d547fe94a4c7e9da733d1c962cf6e59efa4cd9c8bc75" | 1128 | checksum = "88d6731146462ea25d9244b2ed5fd1d716d25c52e4d54aa4fb0f3c4e9854dbe2" |
| 1091 | dependencies = [ | 1129 | dependencies = [ |
| 1092 | "lazy_static", | 1130 | "lazy_static 1.4.0", |
| 1093 | "winapi", | 1131 | "windows-sys", |
| 1094 | ] | 1132 | ] |
| 1095 | 1133 | ||
| 1096 | [[package]] | 1134 | [[package]] |
| @@ -1107,9 +1145,9 @@ checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd" | |||
| 1107 | 1145 | ||
| 1108 | [[package]] | 1146 | [[package]] |
| 1109 | name = "security-framework" | 1147 | name = "security-framework" |
| 1110 | version = "2.6.1" | 1148 | version = "2.7.0" |
| 1111 | source = "registry+https://github.com/rust-lang/crates.io-index" | 1149 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| 1112 | checksum = "2dc14f172faf8a0194a3aded622712b0de276821addc574fa54fc0a1167e10dc" | 1150 | checksum = "2bc1bb97804af6631813c55739f771071e0f2ed33ee20b68c86ec505d906356c" |
| 1113 | dependencies = [ | 1151 | dependencies = [ |
| 1114 | "bitflags", | 1152 | "bitflags", |
| 1115 | "core-foundation", | 1153 | "core-foundation", |
| @@ -1128,20 +1166,30 @@ dependencies = [ | |||
| 1128 | "libc", | 1166 | "libc", |
| 1129 | ] | 1167 | ] |
| 1130 | 1168 | ||
| 1169 | [[package]] | ||
| 1170 | name = "semver-parser" | ||
| 1171 | version = "0.6.2" | ||
| 1172 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 1173 | checksum = "d8fff3c9c5a54636ab95acd8c1349926e04cb1eb8cd70b5adced8a1d1f703a67" | ||
| 1174 | dependencies = [ | ||
| 1175 | "lazy_static 0.2.11", | ||
| 1176 | "regex", | ||
| 1177 | ] | ||
| 1178 | |||
| 1131 | [[package]] | 1179 | [[package]] |
| 1132 | name = "serde" | 1180 | name = "serde" |
| 1133 | version = "1.0.136" | 1181 | version = "1.0.144" |
| 1134 | source = "registry+https://github.com/rust-lang/crates.io-index" | 1182 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| 1135 | checksum = "ce31e24b01e1e524df96f1c2fdd054405f8d7376249a5110886fb4b658484789" | 1183 | checksum = "0f747710de3dcd43b88c9168773254e809d8ddbdf9653b84e2554ab219f17860" |
| 1136 | dependencies = [ | 1184 | dependencies = [ |
| 1137 | "serde_derive", | 1185 | "serde_derive", |
| 1138 | ] | 1186 | ] |
| 1139 | 1187 | ||
| 1140 | [[package]] | 1188 | [[package]] |
| 1141 | name = "serde_derive" | 1189 | name = "serde_derive" |
| 1142 | version = "1.0.136" | 1190 | version = "1.0.144" |
| 1143 | source = "registry+https://github.com/rust-lang/crates.io-index" | 1191 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| 1144 | checksum = "08597e7152fcd306f41838ed3e37be9eaeed2b61c42e2117266a554fab4662f9" | 1192 | checksum = "94ed3a816fb1d101812f83e789f888322c34e291f894f19590dc310963e87a00" |
| 1145 | dependencies = [ | 1193 | dependencies = [ |
| 1146 | "proc-macro2", | 1194 | "proc-macro2", |
| 1147 | "quote", | 1195 | "quote", |
| @@ -1150,9 +1198,9 @@ dependencies = [ | |||
| 1150 | 1198 | ||
| 1151 | [[package]] | 1199 | [[package]] |
| 1152 | name = "serde_json" | 1200 | name = "serde_json" |
| 1153 | version = "1.0.79" | 1201 | version = "1.0.85" |
| 1154 | source = "registry+https://github.com/rust-lang/crates.io-index" | 1202 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| 1155 | checksum = "8e8d9fa5c3b304765ce1fd9c4c8a3de2c8db365a5b91be52f186efc675681d95" | 1203 | checksum = "e55a28e3aaef9d5ce0506d0a14dbba8054ddc7e499ef522dd8b26859ec9d4a44" |
| 1156 | dependencies = [ | 1204 | dependencies = [ |
| 1157 | "itoa", | 1205 | "itoa", |
| 1158 | "ryu", | 1206 | "ryu", |
| @@ -1173,21 +1221,22 @@ dependencies = [ | |||
| 1173 | 1221 | ||
| 1174 | [[package]] | 1222 | [[package]] |
| 1175 | name = "serde_yaml" | 1223 | name = "serde_yaml" |
| 1176 | version = "0.8.24" | 1224 | version = "0.9.11" |
| 1177 | source = "registry+https://github.com/rust-lang/crates.io-index" | 1225 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| 1178 | checksum = "707d15895415db6628332b737c838b88c598522e4dc70647e59b72312924aebc" | 1226 | checksum = "89f31df3f50926cdf2855da5fd8812295c34752cb20438dae42a67f79e021ac3" |
| 1179 | dependencies = [ | 1227 | dependencies = [ |
| 1180 | "indexmap", | 1228 | "indexmap", |
| 1229 | "itoa", | ||
| 1181 | "ryu", | 1230 | "ryu", |
| 1182 | "serde", | 1231 | "serde", |
| 1183 | "yaml-rust", | 1232 | "unsafe-libyaml", |
| 1184 | ] | 1233 | ] |
| 1185 | 1234 | ||
| 1186 | [[package]] | 1235 | [[package]] |
| 1187 | name = "signal-hook" | 1236 | name = "signal-hook" |
| 1188 | version = "0.3.13" | 1237 | version = "0.3.14" |
| 1189 | source = "registry+https://github.com/rust-lang/crates.io-index" | 1238 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| 1190 | checksum = "647c97df271007dcea485bb74ffdb57f2e683f1306c854f468a0c244badabf2d" | 1239 | checksum = "a253b5e89e2698464fc26b545c9edceb338e18a89effeeecfea192c3025be29d" |
| 1191 | dependencies = [ | 1240 | dependencies = [ |
| 1192 | "libc", | 1241 | "libc", |
| 1193 | "signal-hook-registry", | 1242 | "signal-hook-registry", |
| @@ -1213,46 +1262,69 @@ dependencies = [ | |||
| 1213 | "libc", | 1262 | "libc", |
| 1214 | ] | 1263 | ] |
| 1215 | 1264 | ||
| 1265 | [[package]] | ||
| 1266 | name = "sixel" | ||
| 1267 | version = "0.3.2" | ||
| 1268 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 1269 | checksum = "51e4bcd2d65122138405b83d3f7777df6b04b0dd5222c85972ed1fb0119aeaaa" | ||
| 1270 | dependencies = [ | ||
| 1271 | "lazy_static 0.2.11", | ||
| 1272 | "semver-parser", | ||
| 1273 | "sixel-sys", | ||
| 1274 | ] | ||
| 1275 | |||
| 1276 | [[package]] | ||
| 1277 | name = "sixel-sys" | ||
| 1278 | version = "0.3.1" | ||
| 1279 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 1280 | checksum = "fb46e0cd5569bf910390844174a5a99d52dd40681fff92228d221d9f8bf87dea" | ||
| 1281 | dependencies = [ | ||
| 1282 | "make-cmd", | ||
| 1283 | ] | ||
| 1284 | |||
| 1216 | [[package]] | 1285 | [[package]] |
| 1217 | name = "slab" | 1286 | name = "slab" |
| 1218 | version = "0.4.6" | 1287 | version = "0.4.7" |
| 1219 | source = "registry+https://github.com/rust-lang/crates.io-index" | 1288 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| 1220 | checksum = "eb703cfe953bccee95685111adeedb76fabe4e97549a58d16f03ea7b9367bb32" | 1289 | checksum = "4614a76b2a8be0058caa9dbbaf66d988527d86d003c11a94fbd335d7661edcef" |
| 1290 | dependencies = [ | ||
| 1291 | "autocfg", | ||
| 1292 | ] | ||
| 1221 | 1293 | ||
| 1222 | [[package]] | 1294 | [[package]] |
| 1223 | name = "smallvec" | 1295 | name = "smallvec" |
| 1224 | version = "1.8.0" | 1296 | version = "1.9.0" |
| 1225 | source = "registry+https://github.com/rust-lang/crates.io-index" | 1297 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| 1226 | checksum = "f2dd574626839106c320a323308629dcb1acfc96e32a8cba364ddc61ac23ee83" | 1298 | checksum = "2fd0db749597d91ff862fd1d55ea87f7855a744a8425a64695b6fca237d1dad1" |
| 1227 | 1299 | ||
| 1228 | [[package]] | 1300 | [[package]] |
| 1229 | name = "socket2" | 1301 | name = "socket2" |
| 1230 | version = "0.4.4" | 1302 | version = "0.4.7" |
| 1231 | source = "registry+https://github.com/rust-lang/crates.io-index" | 1303 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| 1232 | checksum = "66d72b759436ae32898a2af0a14218dbf55efde3feeb170eb623637db85ee1e0" | 1304 | checksum = "02e2d2db9033d13a1567121ddd7a095ee144db4e1ca1b1bda3419bc0da294ebd" |
| 1233 | dependencies = [ | 1305 | dependencies = [ |
| 1234 | "libc", | 1306 | "libc", |
| 1235 | "winapi", | 1307 | "winapi 0.3.9", |
| 1236 | ] | 1308 | ] |
| 1237 | 1309 | ||
| 1238 | [[package]] | 1310 | [[package]] |
| 1239 | name = "spin" | 1311 | name = "spin" |
| 1240 | version = "0.9.3" | 1312 | version = "0.9.4" |
| 1241 | source = "registry+https://github.com/rust-lang/crates.io-index" | 1313 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| 1242 | checksum = "c530c2b0d0bf8b69304b39fe2001993e267461948b890cd037d8ad4293fa1a0d" | 1314 | checksum = "7f6002a767bff9e83f8eeecf883ecb8011875a21ae8da43bffb817a57e78cc09" |
| 1243 | dependencies = [ | 1315 | dependencies = [ |
| 1244 | "lock_api", | 1316 | "lock_api", |
| 1245 | ] | 1317 | ] |
| 1246 | 1318 | ||
| 1247 | [[package]] | 1319 | [[package]] |
| 1248 | name = "syn" | 1320 | name = "syn" |
| 1249 | version = "1.0.91" | 1321 | version = "1.0.99" |
| 1250 | source = "registry+https://github.com/rust-lang/crates.io-index" | 1322 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| 1251 | checksum = "b683b2b825c8eef438b77c36a06dc262294da3d5a5813fac20da149241dcd44d" | 1323 | checksum = "58dbef6ec655055e20b86b15a8cc6d439cca19b667537ac6a1369572d151ab13" |
| 1252 | dependencies = [ | 1324 | dependencies = [ |
| 1253 | "proc-macro2", | 1325 | "proc-macro2", |
| 1254 | "quote", | 1326 | "quote", |
| 1255 | "unicode-xid", | 1327 | "unicode-ident", |
| 1256 | ] | 1328 | ] |
| 1257 | 1329 | ||
| 1258 | [[package]] | 1330 | [[package]] |
| @@ -1266,7 +1338,7 @@ dependencies = [ | |||
| 1266 | "libc", | 1338 | "libc", |
| 1267 | "redox_syscall", | 1339 | "redox_syscall", |
| 1268 | "remove_dir_all", | 1340 | "remove_dir_all", |
| 1269 | "winapi", | 1341 | "winapi 0.3.9", |
| 1270 | ] | 1342 | ] |
| 1271 | 1343 | ||
| 1272 | [[package]] | 1344 | [[package]] |
| @@ -1285,14 +1357,27 @@ source = "registry+https://github.com/rust-lang/crates.io-index" | |||
| 1285 | checksum = "633c1a546cee861a1a6d0dc69ebeca693bf4296661ba7852b9d21d159e0506df" | 1357 | checksum = "633c1a546cee861a1a6d0dc69ebeca693bf4296661ba7852b9d21d159e0506df" |
| 1286 | dependencies = [ | 1358 | dependencies = [ |
| 1287 | "libc", | 1359 | "libc", |
| 1288 | "winapi", | 1360 | "winapi 0.3.9", |
| 1361 | ] | ||
| 1362 | |||
| 1363 | [[package]] | ||
| 1364 | name = "thread-id" | ||
| 1365 | version = "2.0.0" | ||
| 1366 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 1367 | checksum = "a9539db560102d1cef46b8b78ce737ff0bb64e7e18d35b2a5688f7d097d0ff03" | ||
| 1368 | dependencies = [ | ||
| 1369 | "kernel32-sys", | ||
| 1370 | "libc", | ||
| 1289 | ] | 1371 | ] |
| 1290 | 1372 | ||
| 1291 | [[package]] | 1373 | [[package]] |
| 1292 | name = "thousands" | 1374 | name = "thread_local" |
| 1293 | version = "0.2.0" | 1375 | version = "0.2.7" |
| 1294 | source = "registry+https://github.com/rust-lang/crates.io-index" | 1376 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| 1295 | checksum = "3bf63baf9f5039dadc247375c29eb13706706cfde997d0330d05aa63a77d8820" | 1377 | checksum = "8576dbbfcaef9641452d5cf0df9b0e7eeab7694956dd33bb61515fb8f18cfdd5" |
| 1378 | dependencies = [ | ||
| 1379 | "thread-id", | ||
| 1380 | ] | ||
| 1296 | 1381 | ||
| 1297 | [[package]] | 1382 | [[package]] |
| 1298 | name = "threadpool" | 1383 | name = "threadpool" |
| @@ -1305,30 +1390,20 @@ dependencies = [ | |||
| 1305 | 1390 | ||
| 1306 | [[package]] | 1391 | [[package]] |
| 1307 | name = "tiff" | 1392 | name = "tiff" |
| 1308 | version = "0.7.2" | 1393 | version = "0.7.3" |
| 1309 | source = "registry+https://github.com/rust-lang/crates.io-index" | 1394 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| 1310 | checksum = "7cfada0986f446a770eca461e8c6566cb879682f7d687c8348aa0c857bd52286" | 1395 | checksum = "7259662e32d1e219321eb309d5f9d898b779769d81b76e762c07c8e5d38fcb65" |
| 1311 | dependencies = [ | 1396 | dependencies = [ |
| 1312 | "flate2", | 1397 | "flate2", |
| 1313 | "jpeg-decoder", | 1398 | "jpeg-decoder", |
| 1314 | "weezl", | 1399 | "weezl", |
| 1315 | ] | 1400 | ] |
| 1316 | 1401 | ||
| 1317 | [[package]] | ||
| 1318 | name = "time" | ||
| 1319 | version = "0.1.43" | ||
| 1320 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 1321 | checksum = "ca8a50ef2360fbd1eeb0ecd46795a87a19024eb4b53c5dc916ca1fd95fe62438" | ||
| 1322 | dependencies = [ | ||
| 1323 | "libc", | ||
| 1324 | "winapi", | ||
| 1325 | ] | ||
| 1326 | |||
| 1327 | [[package]] | 1402 | [[package]] |
| 1328 | name = "tinyvec" | 1403 | name = "tinyvec" |
| 1329 | version = "1.5.1" | 1404 | version = "1.6.0" |
| 1330 | source = "registry+https://github.com/rust-lang/crates.io-index" | 1405 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| 1331 | checksum = "2c1c1d5a42b6245520c249549ec267180beaffcc0615401ac8e31853d4b6d8d2" | 1406 | checksum = "87cc5ceb3875bb20c2890005a4e226a4651264a5c75edb2421b52861a0a0cb50" |
| 1332 | dependencies = [ | 1407 | dependencies = [ |
| 1333 | "tinyvec_macros", | 1408 | "tinyvec_macros", |
| 1334 | ] | 1409 | ] |
| @@ -1341,33 +1416,20 @@ checksum = "cda74da7e1a664f795bb1f8a87ec406fb89a02522cf6e50620d016add6dbbf5c" | |||
| 1341 | 1416 | ||
| 1342 | [[package]] | 1417 | [[package]] |
| 1343 | name = "tokio" | 1418 | name = "tokio" |
| 1344 | version = "1.18.1" | 1419 | version = "1.21.0" |
| 1345 | source = "registry+https://github.com/rust-lang/crates.io-index" | 1420 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| 1346 | checksum = "dce653fb475565de9f6fb0614b28bca8df2c430c0cf84bcd9c843f15de5414cc" | 1421 | checksum = "89797afd69d206ccd11fb0ea560a44bbb87731d020670e79416d442919257d42" |
| 1347 | dependencies = [ | 1422 | dependencies = [ |
| 1423 | "autocfg", | ||
| 1348 | "bytes", | 1424 | "bytes", |
| 1349 | "libc", | 1425 | "libc", |
| 1350 | "memchr", | 1426 | "memchr 2.5.0", |
| 1351 | "mio", | 1427 | "mio", |
| 1352 | "num_cpus", | 1428 | "num_cpus", |
| 1353 | "once_cell", | 1429 | "once_cell", |
| 1354 | "parking_lot", | ||
| 1355 | "pin-project-lite", | 1430 | "pin-project-lite", |
| 1356 | "signal-hook-registry", | ||
| 1357 | "socket2", | 1431 | "socket2", |
| 1358 | "tokio-macros", | 1432 | "winapi 0.3.9", |
| 1359 | "winapi", | ||
| 1360 | ] | ||
| 1361 | |||
| 1362 | [[package]] | ||
| 1363 | name = "tokio-macros" | ||
| 1364 | version = "1.7.0" | ||
| 1365 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 1366 | checksum = "b557f72f448c511a979e2564e55d74e6c4432fc96ff4f6241bc6bded342643b7" | ||
| 1367 | dependencies = [ | ||
| 1368 | "proc-macro2", | ||
| 1369 | "quote", | ||
| 1370 | "syn", | ||
| 1371 | ] | 1433 | ] |
| 1372 | 1434 | ||
| 1373 | [[package]] | 1435 | [[package]] |
| @@ -1382,9 +1444,9 @@ dependencies = [ | |||
| 1382 | 1444 | ||
| 1383 | [[package]] | 1445 | [[package]] |
| 1384 | name = "tokio-util" | 1446 | name = "tokio-util" |
| 1385 | version = "0.7.1" | 1447 | version = "0.7.4" |
| 1386 | source = "registry+https://github.com/rust-lang/crates.io-index" | 1448 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| 1387 | checksum = "0edfdeb067411dba2044da6d1cb2df793dd35add7888d73c16e3381ded401764" | 1449 | checksum = "0bb2e075f03b3d66d8d8785356224ba688d2906a371015e225beeb65ca92c740" |
| 1388 | dependencies = [ | 1450 | dependencies = [ |
| 1389 | "bytes", | 1451 | "bytes", |
| 1390 | "futures-core", | 1452 | "futures-core", |
| @@ -1396,41 +1458,35 @@ dependencies = [ | |||
| 1396 | 1458 | ||
| 1397 | [[package]] | 1459 | [[package]] |
| 1398 | name = "tower-service" | 1460 | name = "tower-service" |
| 1399 | version = "0.3.1" | 1461 | version = "0.3.2" |
| 1400 | source = "registry+https://github.com/rust-lang/crates.io-index" | 1462 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| 1401 | checksum = "360dfd1d6d30e05fda32ace2c8c70e9c0a9da713275777f5a4dbb8a1893930c6" | 1463 | checksum = "b6bc1c9ce2b5135ac7f93c72918fc37feb872bdc6a5533a8b85eb4b86bfdae52" |
| 1402 | 1464 | ||
| 1403 | [[package]] | 1465 | [[package]] |
| 1404 | name = "tracing" | 1466 | name = "tracing" |
| 1405 | version = "0.1.34" | 1467 | version = "0.1.36" |
| 1406 | source = "registry+https://github.com/rust-lang/crates.io-index" | 1468 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| 1407 | checksum = "5d0ecdcb44a79f0fe9844f0c4f33a342cbcbb5117de8001e6ba0dc2351327d09" | 1469 | checksum = "2fce9567bd60a67d08a16488756721ba392f24f29006402881e43b19aac64307" |
| 1408 | dependencies = [ | 1470 | dependencies = [ |
| 1409 | "cfg-if", | 1471 | "cfg-if", |
| 1410 | "pin-project-lite", | 1472 | "pin-project-lite", |
| 1411 | "tracing-attributes", | ||
| 1412 | "tracing-core", | 1473 | "tracing-core", |
| 1413 | ] | 1474 | ] |
| 1414 | 1475 | ||
| 1415 | [[package]] | 1476 | [[package]] |
| 1416 | name = "tracing-attributes" | 1477 | name = "tracing-core" |
| 1417 | version = "0.1.20" | 1478 | version = "0.1.29" |
| 1418 | source = "registry+https://github.com/rust-lang/crates.io-index" | 1479 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| 1419 | checksum = "2e65ce065b4b5c53e73bb28912318cb8c9e9ad3921f1d669eb0e68b4c8143a2b" | 1480 | checksum = "5aeea4303076558a00714b823f9ad67d58a3bbda1df83d8827d21193156e22f7" |
| 1420 | dependencies = [ | 1481 | dependencies = [ |
| 1421 | "proc-macro2", | 1482 | "once_cell", |
| 1422 | "quote", | ||
| 1423 | "syn", | ||
| 1424 | ] | 1483 | ] |
| 1425 | 1484 | ||
| 1426 | [[package]] | 1485 | [[package]] |
| 1427 | name = "tracing-core" | 1486 | name = "traitobject" |
| 1428 | version = "0.1.26" | 1487 | version = "0.1.0" |
| 1429 | source = "registry+https://github.com/rust-lang/crates.io-index" | 1488 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| 1430 | checksum = "f54c8ca710e81886d498c2fd3331b56c93aa248d49de2222ad2742247c60072f" | 1489 | checksum = "efd1f82c56340fdf16f2a953d7bda4f8fdffba13d93b00844c25572110b26079" |
| 1431 | dependencies = [ | ||
| 1432 | "lazy_static", | ||
| 1433 | ] | ||
| 1434 | 1490 | ||
| 1435 | [[package]] | 1491 | [[package]] |
| 1436 | name = "try-lock" | 1492 | name = "try-lock" |
| @@ -1440,28 +1496,57 @@ checksum = "59547bce71d9c38b83d9c0e92b6066c4253371f15005def0c30d9657f50c7642" | |||
| 1440 | 1496 | ||
| 1441 | [[package]] | 1497 | [[package]] |
| 1442 | name = "tui" | 1498 | name = "tui" |
| 1443 | version = "0.18.0" | 1499 | version = "0.19.0" |
| 1444 | source = "registry+https://github.com/rust-lang/crates.io-index" | 1500 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| 1445 | checksum = "96fe69244ec2af261bced1d9046a6fee6c8c2a6b0228e59e5ba39bc8ba4ed729" | 1501 | checksum = "ccdd26cbd674007e649a272da4475fb666d3aa0ad0531da7136db6fab0e5bad1" |
| 1446 | dependencies = [ | 1502 | dependencies = [ |
| 1447 | "bitflags", | 1503 | "bitflags", |
| 1448 | "cassowary", | 1504 | "cassowary", |
| 1449 | "crossterm", | 1505 | "crossterm 0.25.0", |
| 1506 | "serde", | ||
| 1450 | "unicode-segmentation", | 1507 | "unicode-segmentation", |
| 1451 | "unicode-width", | 1508 | "unicode-width", |
| 1452 | ] | 1509 | ] |
| 1453 | 1510 | ||
| 1511 | [[package]] | ||
| 1512 | name = "tui-additions" | ||
| 1513 | version = "0.1.8" | ||
| 1514 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 1515 | checksum = "2978e90e761ab278f378e954c40e142191178844ca6d05458bcbc0faadd77eba" | ||
| 1516 | dependencies = [ | ||
| 1517 | "crossterm 0.25.0", | ||
| 1518 | "dyn-clone", | ||
| 1519 | "tui", | ||
| 1520 | "typemap", | ||
| 1521 | "unicode-segmentation", | ||
| 1522 | ] | ||
| 1523 | |||
| 1524 | [[package]] | ||
| 1525 | name = "typemap" | ||
| 1526 | version = "0.3.3" | ||
| 1527 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 1528 | checksum = "653be63c80a3296da5551e1bfd2cca35227e13cdd08c6668903ae2f4f77aa1f6" | ||
| 1529 | dependencies = [ | ||
| 1530 | "unsafe-any", | ||
| 1531 | ] | ||
| 1532 | |||
| 1454 | [[package]] | 1533 | [[package]] |
| 1455 | name = "unicode-bidi" | 1534 | name = "unicode-bidi" |
| 1456 | version = "0.3.7" | 1535 | version = "0.3.8" |
| 1536 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 1537 | checksum = "099b7128301d285f79ddd55b9a83d5e6b9e97c92e0ea0daebee7263e932de992" | ||
| 1538 | |||
| 1539 | [[package]] | ||
| 1540 | name = "unicode-ident" | ||
| 1541 | version = "1.0.3" | ||
| 1457 | source = "registry+https://github.com/rust-lang/crates.io-index" | 1542 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| 1458 | checksum = "1a01404663e3db436ed2746d9fefef640d868edae3cceb81c3b8d5732fda678f" | 1543 | checksum = "c4f5b37a154999a8f3f98cc23a628d850e154479cd94decf3414696e12e31aaf" |
| 1459 | 1544 | ||
| 1460 | [[package]] | 1545 | [[package]] |
| 1461 | name = "unicode-normalization" | 1546 | name = "unicode-normalization" |
| 1462 | version = "0.1.19" | 1547 | version = "0.1.21" |
| 1463 | source = "registry+https://github.com/rust-lang/crates.io-index" | 1548 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| 1464 | checksum = "d54590932941a9e9266f0832deed84ebe1bf2e4c9e4a3554d393d18f5e854bf9" | 1549 | checksum = "854cbdc4f7bc6ae19c820d44abdc3277ac3e1b2b93db20a636825d9322fb60e6" |
| 1465 | dependencies = [ | 1550 | dependencies = [ |
| 1466 | "tinyvec", | 1551 | "tinyvec", |
| 1467 | ] | 1552 | ] |
| @@ -1479,23 +1564,37 @@ source = "registry+https://github.com/rust-lang/crates.io-index" | |||
| 1479 | checksum = "3ed742d4ea2bd1176e236172c8429aaf54486e7ac098db29ffe6529e0ce50973" | 1564 | checksum = "3ed742d4ea2bd1176e236172c8429aaf54486e7ac098db29ffe6529e0ce50973" |
| 1480 | 1565 | ||
| 1481 | [[package]] | 1566 | [[package]] |
| 1482 | name = "unicode-xid" | 1567 | name = "unsafe-any" |
| 1568 | version = "0.4.2" | ||
| 1569 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 1570 | checksum = "f30360d7979f5e9c6e6cea48af192ea8fab4afb3cf72597154b8f08935bc9c7f" | ||
| 1571 | dependencies = [ | ||
| 1572 | "traitobject", | ||
| 1573 | ] | ||
| 1574 | |||
| 1575 | [[package]] | ||
| 1576 | name = "unsafe-libyaml" | ||
| 1483 | version = "0.2.2" | 1577 | version = "0.2.2" |
| 1484 | source = "registry+https://github.com/rust-lang/crates.io-index" | 1578 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| 1485 | checksum = "8ccb82d61f80a663efe1f787a51b16b5a51e3314d6ac365b08639f52387b33f3" | 1579 | checksum = "931179334a56395bcf64ba5e0ff56781381c1a5832178280c7d7f91d1679aeb0" |
| 1486 | 1580 | ||
| 1487 | [[package]] | 1581 | [[package]] |
| 1488 | name = "url" | 1582 | name = "url" |
| 1489 | version = "2.2.2" | 1583 | version = "2.3.1" |
| 1490 | source = "registry+https://github.com/rust-lang/crates.io-index" | 1584 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| 1491 | checksum = "a507c383b2d33b5fc35d1861e77e6b383d158b2da5e14fe51b83dfedf6fd578c" | 1585 | checksum = "0d68c799ae75762b8c3fe375feb6600ef5602c883c5d21eb51c09f22b83c4643" |
| 1492 | dependencies = [ | 1586 | dependencies = [ |
| 1493 | "form_urlencoded", | 1587 | "form_urlencoded", |
| 1494 | "idna", | 1588 | "idna", |
| 1495 | "matches", | ||
| 1496 | "percent-encoding", | 1589 | "percent-encoding", |
| 1497 | ] | 1590 | ] |
| 1498 | 1591 | ||
| 1592 | [[package]] | ||
| 1593 | name = "utf8-ranges" | ||
| 1594 | version = "0.1.3" | ||
| 1595 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 1596 | checksum = "a1ca13c08c41c9c3e04224ed9ff80461d97e121589ff27c753a16cb10830ae0f" | ||
| 1597 | |||
| 1499 | [[package]] | 1598 | [[package]] |
| 1500 | name = "vcpkg" | 1599 | name = "vcpkg" |
| 1501 | version = "0.2.15" | 1600 | version = "0.2.15" |
| @@ -1511,9 +1610,11 @@ dependencies = [ | |||
| 1511 | "ansi_colours", | 1610 | "ansi_colours", |
| 1512 | "base64", | 1611 | "base64", |
| 1513 | "console", | 1612 | "console", |
| 1514 | "crossterm", | 1613 | "crossterm 0.23.2", |
| 1515 | "image", | 1614 | "image", |
| 1516 | "lazy_static", | 1615 | "lazy_static 1.4.0", |
| 1616 | "sixel", | ||
| 1617 | "sixel-sys", | ||
| 1517 | "tempfile", | 1618 | "tempfile", |
| 1518 | "termcolor", | 1619 | "termcolor", |
| 1519 | ] | 1620 | ] |
| @@ -1528,12 +1629,6 @@ dependencies = [ | |||
| 1528 | "try-lock", | 1629 | "try-lock", |
| 1529 | ] | 1630 | ] |
| 1530 | 1631 | ||
| 1531 | [[package]] | ||
| 1532 | name = "wasi" | ||
| 1533 | version = "0.10.2+wasi-snapshot-preview1" | ||
| 1534 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 1535 | checksum = "fd6fbd9a79829dd1ad0cc20627bf1ed606756a7f77edff7b66b7064f9cb327c6" | ||
| 1536 | |||
| 1537 | [[package]] | 1632 | [[package]] |
| 1538 | name = "wasi" | 1633 | name = "wasi" |
| 1539 | version = "0.11.0+wasi-snapshot-preview1" | 1634 | version = "0.11.0+wasi-snapshot-preview1" |
| @@ -1542,9 +1637,9 @@ checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" | |||
| 1542 | 1637 | ||
| 1543 | [[package]] | 1638 | [[package]] |
| 1544 | name = "wasm-bindgen" | 1639 | name = "wasm-bindgen" |
| 1545 | version = "0.2.80" | 1640 | version = "0.2.82" |
| 1546 | source = "registry+https://github.com/rust-lang/crates.io-index" | 1641 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| 1547 | checksum = "27370197c907c55e3f1a9fbe26f44e937fe6451368324e009cba39e139dc08ad" | 1642 | checksum = "fc7652e3f6c4706c8d9cd54832c4a4ccb9b5336e2c3bd154d5cccfbf1c1f5f7d" |
| 1548 | dependencies = [ | 1643 | dependencies = [ |
| 1549 | "cfg-if", | 1644 | "cfg-if", |
| 1550 | "wasm-bindgen-macro", | 1645 | "wasm-bindgen-macro", |
| @@ -1552,13 +1647,13 @@ dependencies = [ | |||
| 1552 | 1647 | ||
| 1553 | [[package]] | 1648 | [[package]] |
| 1554 | name = "wasm-bindgen-backend" | 1649 | name = "wasm-bindgen-backend" |
| 1555 | version = "0.2.80" | 1650 | version = "0.2.82" |
| 1556 | source = "registry+https://github.com/rust-lang/crates.io-index" | 1651 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| 1557 | checksum = "53e04185bfa3a779273da532f5025e33398409573f348985af9a1cbf3774d3f4" | 1652 | checksum = "662cd44805586bd52971b9586b1df85cdbbd9112e4ef4d8f41559c334dc6ac3f" |
| 1558 | dependencies = [ | 1653 | dependencies = [ |
| 1559 | "bumpalo", | 1654 | "bumpalo", |
| 1560 | "lazy_static", | ||
| 1561 | "log", | 1655 | "log", |
| 1656 | "once_cell", | ||
| 1562 | "proc-macro2", | 1657 | "proc-macro2", |
| 1563 | "quote", | 1658 | "quote", |
| 1564 | "syn", | 1659 | "syn", |
| @@ -1567,9 +1662,9 @@ dependencies = [ | |||
| 1567 | 1662 | ||
| 1568 | [[package]] | 1663 | [[package]] |
| 1569 | name = "wasm-bindgen-futures" | 1664 | name = "wasm-bindgen-futures" |
| 1570 | version = "0.4.30" | 1665 | version = "0.4.32" |
| 1571 | source = "registry+https://github.com/rust-lang/crates.io-index" | 1666 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| 1572 | checksum = "6f741de44b75e14c35df886aff5f1eb73aa114fa5d4d00dcd37b5e01259bf3b2" | 1667 | checksum = "fa76fb221a1f8acddf5b54ace85912606980ad661ac7a503b4570ffd3a624dad" |
| 1573 | dependencies = [ | 1668 | dependencies = [ |
| 1574 | "cfg-if", | 1669 | "cfg-if", |
| 1575 | "js-sys", | 1670 | "js-sys", |
| @@ -1579,9 +1674,9 @@ dependencies = [ | |||
| 1579 | 1674 | ||
| 1580 | [[package]] | 1675 | [[package]] |
| 1581 | name = "wasm-bindgen-macro" | 1676 | name = "wasm-bindgen-macro" |
| 1582 | version = "0.2.80" | 1677 | version = "0.2.82" |
| 1583 | source = "registry+https://github.com/rust-lang/crates.io-index" | 1678 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| 1584 | checksum = "17cae7ff784d7e83a2fe7611cfe766ecf034111b49deb850a3dc7699c08251f5" | 1679 | checksum = "b260f13d3012071dfb1512849c033b1925038373aea48ced3012c09df952c602" |
| 1585 | dependencies = [ | 1680 | dependencies = [ |
| 1586 | "quote", | 1681 | "quote", |
| 1587 | "wasm-bindgen-macro-support", | 1682 | "wasm-bindgen-macro-support", |
| @@ -1589,9 +1684,9 @@ dependencies = [ | |||
| 1589 | 1684 | ||
| 1590 | [[package]] | 1685 | [[package]] |
| 1591 | name = "wasm-bindgen-macro-support" | 1686 | name = "wasm-bindgen-macro-support" |
| 1592 | version = "0.2.80" | 1687 | version = "0.2.82" |
| 1593 | source = "registry+https://github.com/rust-lang/crates.io-index" | 1688 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| 1594 | checksum = "99ec0dc7a4756fffc231aab1b9f2f578d23cd391390ab27f952ae0c9b3ece20b" | 1689 | checksum = "5be8e654bdd9b79216c2929ab90721aa82faf65c48cdf08bdc4e7f51357b80da" |
| 1595 | dependencies = [ | 1690 | dependencies = [ |
| 1596 | "proc-macro2", | 1691 | "proc-macro2", |
| 1597 | "quote", | 1692 | "quote", |
| @@ -1602,15 +1697,15 @@ dependencies = [ | |||
| 1602 | 1697 | ||
| 1603 | [[package]] | 1698 | [[package]] |
| 1604 | name = "wasm-bindgen-shared" | 1699 | name = "wasm-bindgen-shared" |
| 1605 | version = "0.2.80" | 1700 | version = "0.2.82" |
| 1606 | source = "registry+https://github.com/rust-lang/crates.io-index" | 1701 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| 1607 | checksum = "d554b7f530dee5964d9a9468d95c1f8b8acae4f282807e7d27d4b03099a46744" | 1702 | checksum = "6598dd0bd3c7d51095ff6531a5b23e02acdc81804e30d8f07afb77b7215a140a" |
| 1608 | 1703 | ||
| 1609 | [[package]] | 1704 | [[package]] |
| 1610 | name = "web-sys" | 1705 | name = "web-sys" |
| 1611 | version = "0.3.57" | 1706 | version = "0.3.59" |
| 1612 | source = "registry+https://github.com/rust-lang/crates.io-index" | 1707 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| 1613 | checksum = "7b17e741662c70c8bd24ac5c5b18de314a2c26c32bf8346ee1e6f53de919c283" | 1708 | checksum = "ed055ab27f941423197eb86b2035720b1a3ce40504df082cac2ecc6ed73335a1" |
| 1614 | dependencies = [ | 1709 | dependencies = [ |
| 1615 | "js-sys", | 1710 | "js-sys", |
| 1616 | "wasm-bindgen", | 1711 | "wasm-bindgen", |
| @@ -1618,9 +1713,15 @@ dependencies = [ | |||
| 1618 | 1713 | ||
| 1619 | [[package]] | 1714 | [[package]] |
| 1620 | name = "weezl" | 1715 | name = "weezl" |
| 1621 | version = "0.1.6" | 1716 | version = "0.1.7" |
| 1717 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 1718 | checksum = "9193164d4de03a926d909d3bc7c30543cecb35400c02114792c2cae20d5e2dbb" | ||
| 1719 | |||
| 1720 | [[package]] | ||
| 1721 | name = "winapi" | ||
| 1722 | version = "0.2.8" | ||
| 1622 | source = "registry+https://github.com/rust-lang/crates.io-index" | 1723 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| 1623 | checksum = "9c97e489d8f836838d497091de568cf16b117486d529ec5579233521065bd5e4" | 1724 | checksum = "167dc9d6949a9b857f3451275e911c3f44255842c1f7a76f33c55103a909087a" |
| 1624 | 1725 | ||
| 1625 | [[package]] | 1726 | [[package]] |
| 1626 | name = "winapi" | 1727 | name = "winapi" |
| @@ -1632,6 +1733,12 @@ dependencies = [ | |||
| 1632 | "winapi-x86_64-pc-windows-gnu", | 1733 | "winapi-x86_64-pc-windows-gnu", |
| 1633 | ] | 1734 | ] |
| 1634 | 1735 | ||
| 1736 | [[package]] | ||
| 1737 | name = "winapi-build" | ||
| 1738 | version = "0.1.1" | ||
| 1739 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 1740 | checksum = "2d315eee3b34aca4797b2da6b13ed88266e6d612562a0c46390af8299fc699bc" | ||
| 1741 | |||
| 1635 | [[package]] | 1742 | [[package]] |
| 1636 | name = "winapi-i686-pc-windows-gnu" | 1743 | name = "winapi-i686-pc-windows-gnu" |
| 1637 | version = "0.4.0" | 1744 | version = "0.4.0" |
| @@ -1644,7 +1751,7 @@ version = "0.1.5" | |||
| 1644 | source = "registry+https://github.com/rust-lang/crates.io-index" | 1751 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| 1645 | checksum = "70ec6ce85bb158151cae5e5c87f95a8e97d2c0c4b001223f33a334e3ce5de178" | 1752 | checksum = "70ec6ce85bb158151cae5e5c87f95a8e97d2c0c4b001223f33a334e3ce5de178" |
| 1646 | dependencies = [ | 1753 | dependencies = [ |
| 1647 | "winapi", | 1754 | "winapi 0.3.9", |
| 1648 | ] | 1755 | ] |
| 1649 | 1756 | ||
| 1650 | [[package]] | 1757 | [[package]] |
| @@ -1655,9 +1762,9 @@ checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" | |||
| 1655 | 1762 | ||
| 1656 | [[package]] | 1763 | [[package]] |
| 1657 | name = "windows-sys" | 1764 | name = "windows-sys" |
| 1658 | version = "0.34.0" | 1765 | version = "0.36.1" |
| 1659 | source = "registry+https://github.com/rust-lang/crates.io-index" | 1766 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| 1660 | checksum = "5acdd78cb4ba54c0045ac14f62d8f94a03d10047904ae2a40afa1e99d8f70825" | 1767 | checksum = "ea04155a16a59f9eab786fe12a4a450e75cdb175f9e0d80da1e17db09f55b8d2" |
| 1661 | dependencies = [ | 1768 | dependencies = [ |
| 1662 | "windows_aarch64_msvc", | 1769 | "windows_aarch64_msvc", |
| 1663 | "windows_i686_gnu", | 1770 | "windows_i686_gnu", |
| @@ -1668,33 +1775,33 @@ dependencies = [ | |||
| 1668 | 1775 | ||
| 1669 | [[package]] | 1776 | [[package]] |
| 1670 | name = "windows_aarch64_msvc" | 1777 | name = "windows_aarch64_msvc" |
| 1671 | version = "0.34.0" | 1778 | version = "0.36.1" |
| 1672 | source = "registry+https://github.com/rust-lang/crates.io-index" | 1779 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| 1673 | checksum = "17cffbe740121affb56fad0fc0e421804adf0ae00891205213b5cecd30db881d" | 1780 | checksum = "9bb8c3fd39ade2d67e9874ac4f3db21f0d710bee00fe7cab16949ec184eeaa47" |
| 1674 | 1781 | ||
| 1675 | [[package]] | 1782 | [[package]] |
| 1676 | name = "windows_i686_gnu" | 1783 | name = "windows_i686_gnu" |
| 1677 | version = "0.34.0" | 1784 | version = "0.36.1" |
| 1678 | source = "registry+https://github.com/rust-lang/crates.io-index" | 1785 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| 1679 | checksum = "2564fde759adb79129d9b4f54be42b32c89970c18ebf93124ca8870a498688ed" | 1786 | checksum = "180e6ccf01daf4c426b846dfc66db1fc518f074baa793aa7d9b9aaeffad6a3b6" |
| 1680 | 1787 | ||
| 1681 | [[package]] | 1788 | [[package]] |
| 1682 | name = "windows_i686_msvc" | 1789 | name = "windows_i686_msvc" |
| 1683 | version = "0.34.0" | 1790 | version = "0.36.1" |
| 1684 | source = "registry+https://github.com/rust-lang/crates.io-index" | 1791 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| 1685 | checksum = "9cd9d32ba70453522332c14d38814bceeb747d80b3958676007acadd7e166956" | 1792 | checksum = "e2e7917148b2812d1eeafaeb22a97e4813dfa60a3f8f78ebe204bcc88f12f024" |
| 1686 | 1793 | ||
| 1687 | [[package]] | 1794 | [[package]] |
| 1688 | name = "windows_x86_64_gnu" | 1795 | name = "windows_x86_64_gnu" |
| 1689 | version = "0.34.0" | 1796 | version = "0.36.1" |
| 1690 | source = "registry+https://github.com/rust-lang/crates.io-index" | 1797 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| 1691 | checksum = "cfce6deae227ee8d356d19effc141a509cc503dfd1f850622ec4b0f84428e1f4" | 1798 | checksum = "4dcd171b8776c41b97521e5da127a2d86ad280114807d0b2ab1e462bc764d9e1" |
| 1692 | 1799 | ||
| 1693 | [[package]] | 1800 | [[package]] |
| 1694 | name = "windows_x86_64_msvc" | 1801 | name = "windows_x86_64_msvc" |
| 1695 | version = "0.34.0" | 1802 | version = "0.36.1" |
| 1696 | source = "registry+https://github.com/rust-lang/crates.io-index" | 1803 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| 1697 | checksum = "d19538ccc21819d01deaf88d6a17eae6596a12e9aafdbb97916fb49896d89de9" | 1804 | checksum = "c811ca4a8c853ef420abd8592ba53ddbbac90410fab6903b3e79972a631f7680" |
| 1698 | 1805 | ||
| 1699 | [[package]] | 1806 | [[package]] |
| 1700 | name = "winreg" | 1807 | name = "winreg" |
| @@ -1702,34 +1809,25 @@ version = "0.10.1" | |||
| 1702 | source = "registry+https://github.com/rust-lang/crates.io-index" | 1809 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| 1703 | checksum = "80d0f4e272c85def139476380b12f9ac60926689dd2e01d4923222f40580869d" | 1810 | checksum = "80d0f4e272c85def139476380b12f9ac60926689dd2e01d4923222f40580869d" |
| 1704 | dependencies = [ | 1811 | dependencies = [ |
| 1705 | "winapi", | 1812 | "winapi 0.3.9", |
| 1706 | ] | ||
| 1707 | |||
| 1708 | [[package]] | ||
| 1709 | name = "yaml-rust" | ||
| 1710 | version = "0.4.5" | ||
| 1711 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 1712 | checksum = "56c1936c4cc7a1c9ab21a1ebb602eb942ba868cbd44a99cb7cdc5892335e1c85" | ||
| 1713 | dependencies = [ | ||
| 1714 | "linked-hash-map", | ||
| 1715 | ] | 1813 | ] |
| 1716 | 1814 | ||
| 1717 | [[package]] | 1815 | [[package]] |
| 1718 | name = "youtube-tui" | 1816 | name = "youtube-tui" |
| 1719 | version = "0.4.5" | 1817 | version = "0.5.0" |
| 1720 | dependencies = [ | 1818 | dependencies = [ |
| 1721 | "chrono", | 1819 | "chrono", |
| 1722 | "crossterm", | 1820 | "crossterm 0.25.0", |
| 1821 | "dyn-clone", | ||
| 1723 | "futures", | 1822 | "futures", |
| 1724 | "home", | 1823 | "home", |
| 1725 | "hrtime", | ||
| 1726 | "invidious", | 1824 | "invidious", |
| 1727 | "reqwest", | 1825 | "reqwest", |
| 1728 | "serde", | 1826 | "serde", |
| 1729 | "serde_json", | ||
| 1730 | "serde_yaml", | 1827 | "serde_yaml", |
| 1731 | "thousands", | ||
| 1732 | "tokio", | 1828 | "tokio", |
| 1733 | "tui", | 1829 | "tui", |
| 1830 | "tui-additions", | ||
| 1831 | "typemap", | ||
| 1734 | "viuer", | 1832 | "viuer", |
| 1735 | ] | 1833 | ] |
Cargo.toml +16 −17
| @@ -1,6 +1,6 @@ | |||
| 1 | [package] | 1 | [package] |
| 2 | name = "youtube-tui" | 2 | name = "youtube-tui" |
| 3 | version = "0.4.5" | 3 | version = "0.5.0" |
| 4 | edition = "2021" | 4 | edition = "2021" |
| 5 | authors = ["Siriusmart <siriusmart@tuta.io>"] | 5 | authors = ["Siriusmart <siriusmart@tuta.io>"] |
| 6 | description = "An aesthetically pleasing YouTube TUI written in Rust" | 6 | description = "An aesthetically pleasing YouTube TUI written in Rust" |
| @@ -13,20 +13,19 @@ repository = "https://github.com/Siriusmart/youtube-tui" | |||
| 13 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | 13 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html |
| 14 | 14 | ||
| 15 | [dependencies] | 15 | [dependencies] |
| 16 | tui = "0.18" | 16 | serde = {version = "1.0", features = ["derive"]} |
| 17 | crossterm = "0.23" | 17 | tui = {version = "0.19", features = ["serde"]} |
| 18 | invidious = "0.2" | 18 | crossterm = {version = "0.25", features = ["serde"]} |
| 19 | futures = "0.3" | 19 | viuer = {version = "0.6", features = ["sixel"]} |
| 20 | hrtime = "0.2" | ||
| 21 | home = "0.5" | 20 | home = "0.5" |
| 22 | reqwest = {version = "0.11", features = ["blocking"]} | 21 | chrono = {version = "0.4", default-features = false, features = ["clock"]} |
| 23 | tokio = { version = "1.18", features = ["full"] } | 22 | tui-additions = {version = "0.1", default-features = false, features = ["framework", "widgets"]} |
| 24 | viuer = "0.6" | 23 | typemap = "0.3" |
| 25 | thousands = "0.2" | 24 | invidious = {version = "0.3", default-features = false, features = ["reqwest"]} |
| 26 | chrono = "0.4" | 25 | serde_yaml = "0.9" |
| 27 | serde = "1" | 26 | dyn-clone = "1.0" |
| 28 | serde_yaml = "0.8" | 27 | tokio = "1.21" |
| 29 | serde_json = "1" | 28 | futures = "0.3" |
| 30 | 29 | reqwest = "0.11" | |
| 31 | [profile.dev.package."*"] | 30 | # serde_json = "1.0" |
| 32 | opt-level = 3 | 31 | # tui-additions = {path = "../../Rust/Packages/tui-additions", default-features = false, features = ["framework", "widgets"]} |
README.md +51 −30
| @@ -8,6 +8,46 @@ | |||
| 8 | 8 | ||
| 9 | An aesthetically pleasing YouTube TUI written in Rust. | 9 | An aesthetically pleasing YouTube TUI written in Rust. |
| 10 | 10 | ||
| 11 | > ## Warning | ||
| 12 | > | ||
| 13 | > The current code on GitHub is a rewritten-from-scratch version of the old code, it is not functional yet. Therefore if you would like to try the TUI out, please install it from `crates.io` (seen Installation). | ||
| 14 | > | ||
| 15 | > ### Changes | ||
| 16 | > | ||
| 17 | > #### Framework | ||
| 18 | > Now uses the TUI framework from `tui-additions` which I wrote specifically for this project. The main benefits of this are that all "items" are no longer related to each other, so changing one of them won't break the others. This modular framework also make fixing bugs in existing items and adding new ones much easier (which is the main reason that I decided to rewrite the entire thing from scratch). | ||
| 19 | > | ||
| 20 | > The main drawbacks of using a framework is there are limitations of what I can do (the old code does excatly what I wanted it to, but it's a hella mess), and the performance may take a hit (just slightly, TUIs written in Rust are still ***blazingly fast!!!***). | ||
| 21 | > | ||
| 22 | > #### Config files readability | ||
| 23 | > | ||
| 24 | > The old config files uses the YAML format, which is usually very easy to read, but when it comes to `tuples` and custom `struct` representation it actually look pure gibberish. | ||
| 25 | > | ||
| 26 | > The new config files are also in YAML, but I prevented tuples from appearing in them by removing stuff nobody is gonna change anyways and options that are gonna break the entire thing anyways, so that even a 6 year old Roblox player would have the ability to read and modify their config. | ||
| 27 | > | ||
| 28 | > No docs on the config until I finish the whole thing, so if you want to figure out stuff go read the code yourself it's not that bad now. | ||
| 29 | > | ||
| 30 | > #### Sixels! | ||
| 31 | > | ||
| 32 | > You can now display PNGs in terminal yay! Very slow and lots of delay, trying to get it work multithreaded so that it can still be usable but with no success. If anyone knows how to do that (or just make it faster) please help. | ||
| 33 | > | ||
| 34 | > #### Code readability | ||
| 35 | > | ||
| 36 | > The code is now more idiomatic and i put comments so yeah go read it and i will memorize the arch wiki | ||
| 37 | > | ||
| 38 | > ### Progress | ||
| 39 | > | ||
| 40 | > #### Done | ||
| 41 | > | ||
| 42 | > - Config files (mostly, more options will be added when I get to that part) | ||
| 43 | > - Home page with its basic items | ||
| 44 | > | ||
| 45 | > #### To do before release | ||
| 46 | > | ||
| 47 | > - Search filters | ||
| 48 | > - All pages (search, video/playlist/channel info) | ||
| 49 | > - Basically back to where it is before the rewrite | ||
| 50 | |||
| 11 | ## Overview | 51 | ## Overview |
| 12 | YouTube TUI is a text user interface that provides a clean TUI for browsing YouTube. It can perform YouTube query searches, view and inspect channels, and play the desired content as a regular video or audio-only stream for saving bandwidth. | 52 | YouTube TUI is a text user interface that provides a clean TUI for browsing YouTube. It can perform YouTube query searches, view and inspect channels, and play the desired content as a regular video or audio-only stream for saving bandwidth. |
| 13 | 53 | ||
| @@ -18,36 +58,8 @@ YouTube TUI is a text user interface that provides a clean TUI for browsing YouT | |||
| 18 | 58 | ||
| 19 | [YouTube TUI user manual](https://siriusmart.github.io/youtube-tui) | 59 | [YouTube TUI user manual](https://siriusmart.github.io/youtube-tui) |
| 20 | 60 | ||
| 21 | Changelog: | ||
| 22 | |||
| 23 | * AM | ||
| 24 | * REWRITING | ||
| 25 | * THE | ||
| 26 | * ENTRIE | ||
| 27 | * THING | ||
| 28 | * FROM | ||
| 29 | * SCRATCH | ||
| 30 | * THEN | ||
| 31 | * NOTICED | ||
| 32 | * A | ||
| 33 | * SINGLE | ||
| 34 | * TYPO | ||
| 35 | * IN | ||
| 36 | * THE | ||
| 37 | * OLD | ||
| 38 | * VERSION | ||
| 39 | * GRRRRR | ||
| 40 | |||
| 41 | So I fixed that one single typo and continued with stuff | ||
| 42 | |||
| 43 | ## Installation | 61 | ## Installation |
| 44 | 62 | ||
| 45 | ###Install from the AUR | ||
| 46 | |||
| 47 | ```bash | ||
| 48 | yay -S youtube-tui-git # Or any other AUR helper | ||
| 49 | ``` | ||
| 50 | |||
| 51 | ### Install from crates.io | 63 | ### Install from crates.io |
| 52 | 64 | ||
| 53 | ```bash | 65 | ```bash |
| @@ -60,8 +72,17 @@ git clone https://github.com/sirusmart/youtube-tui && cd youtube-tui && cargo bu | |||
| 60 | ``` | 72 | ``` |
| 61 | Once build, the compiled binary will be located at `./target/release/youtube-tui`. The program is not in your path yet, so you'll have to manually move to to a place from which you would be able to execute it. A common way to do so is to copy the binary executable to `/usr/local/bin/youtube-tui`. | 73 | Once build, the compiled binary will be located at `./target/release/youtube-tui`. The program is not in your path yet, so you'll have to manually move to to a place from which you would be able to execute it. A common way to do so is to copy the binary executable to `/usr/local/bin/youtube-tui`. |
| 62 | 74 | ||
| 63 | ### Dependencies | 75 | > ### Dependencies |
| 64 | This program does not require any dependencies, but it is strongly recommended that there are at least three things present in your system's path as executable commands: | 76 | > |
| 77 | > This program does not requires any dependencies, but it is suggested these three things on your system that can be launched via command: | ||
| 78 | > | ||
| 79 | > 1. A video player (Defaults to `mpv`) | ||
| 80 | > 2. A terminal emulator (Defaults to `konsole`) | ||
| 81 | > 3. A YouTube downloader (Defaults to `yt-dlp`, strongly suggest NOT to use `youtube-dl` because it is now very slow) | ||
| 82 | > | ||
| 83 | > None of these dependencies are required as you can change them in config (in `commands.yml`) | ||
| 84 | |||
| 85 | ## Usage | ||
| 65 | 86 | ||
| 66 | * A video player (Defaults to `MPV`) | 87 | * A video player (Defaults to `MPV`) |
| 67 | * A terminal emulator (Defaults to `konsole`) | 88 | * A terminal emulator (Defaults to `konsole`) |
src/app/app.rs deleted −452
| @@ -1,452 +0,0 @@ | |||
| 1 | use std::collections::LinkedList; | ||
| 2 | |||
| 3 | use crate::{ | ||
| 4 | structs::{AppHistory, Item, Page, SearchSettings, State, WatchHistory, MessageText}, | ||
| 5 | traits::ItemTrait, | ||
| 6 | }; | ||
| 7 | use crossterm::event::KeyEvent; | ||
| 8 | use invidious::blocking::Client; | ||
| 9 | use tui::{ | ||
| 10 | backend::Backend, | ||
| 11 | layout::{Constraint, Direction, Layout}, | ||
| 12 | style::{Color, Style}, | ||
| 13 | widgets::{Block, Paragraph, Wrap}, | ||
| 14 | Frame, | ||
| 15 | }; | ||
| 16 | |||
| 17 | use super::config::{Action, Config, LayoutConfig}; | ||
| 18 | |||
| 19 | #[derive(Clone)] | ||
| 20 | pub struct App { | ||
| 21 | pub config: Config, | ||
| 22 | pub page: Page, | ||
| 23 | pub state: State, // Item | ||
| 24 | pub selectable: Vec<Vec<(usize, usize)>>, | ||
| 25 | pub hover: Option<(usize, usize)>, // x, y | ||
| 26 | pub selected: Option<(usize, usize)>, | ||
| 27 | pub client: Client, | ||
| 28 | pub message: MessageText, | ||
| 29 | pub load: bool, | ||
| 30 | pub render: bool, | ||
| 31 | pub popup_focus: bool, | ||
| 32 | pub history: Vec<AppHistory>, | ||
| 33 | pub watch_history: WatchHistory, | ||
| 34 | pub search_settings: SearchSettings, | ||
| 35 | pub search_text: String, | ||
| 36 | pub search_index: usize, | ||
| 37 | pub page_no: usize, | ||
| 38 | pub term_clear: bool, | ||
| 39 | } | ||
| 40 | |||
| 41 | pub struct AppNoState { | ||
| 42 | pub config: Config, | ||
| 43 | pub page: Page, | ||
| 44 | pub selectable: Vec<Vec<(usize, usize)>>, | ||
| 45 | pub hover: Option<(usize, usize)>, // x, y | ||
| 46 | pub selected: Option<(usize, usize)>, | ||
| 47 | pub client: Client, | ||
| 48 | pub message: MessageText, | ||
| 49 | pub load: bool, | ||
| 50 | pub render: bool, | ||
| 51 | pub popup_focus: bool, | ||
| 52 | pub history: Vec<AppHistory>, | ||
| 53 | pub watch_history: WatchHistory, | ||
| 54 | pub search_settings: SearchSettings, | ||
| 55 | pub search_text: String, | ||
| 56 | pub search_index: usize, | ||
| 57 | pub page_no: usize, | ||
| 58 | pub term_clear: bool, | ||
| 59 | } | ||
| 60 | |||
| 61 | impl AppNoState { | ||
| 62 | pub fn split(app: App) -> (Self, State) { | ||
| 63 | let out = Self { | ||
| 64 | config: app.config, | ||
| 65 | page: app.page, | ||
| 66 | selectable: app.selectable, | ||
| 67 | hover: app.hover, | ||
| 68 | selected: app.selected, | ||
| 69 | client: app.client, | ||
| 70 | message: app.message, | ||
| 71 | load: app.load, | ||
| 72 | render: app.render, | ||
| 73 | popup_focus: app.popup_focus, | ||
| 74 | history: app.history, | ||
| 75 | watch_history: app.watch_history, | ||
| 76 | search_settings: app.search_settings, | ||
| 77 | search_text: app.search_text, | ||
| 78 | search_index: app.search_index, | ||
| 79 | page_no: app.page_no, | ||
| 80 | term_clear: app.term_clear, | ||
| 81 | }; | ||
| 82 | (out, app.state) | ||
| 83 | } | ||
| 84 | |||
| 85 | pub fn join(app: Self, state: State) -> App { | ||
| 86 | App { | ||
| 87 | config: app.config, | ||
| 88 | page: app.page, | ||
| 89 | selectable: app.selectable, | ||
| 90 | hover: app.hover, | ||
| 91 | selected: app.selected, | ||
| 92 | client: app.client, | ||
| 93 | message: app.message, | ||
| 94 | load: app.load, | ||
| 95 | render: app.render, | ||
| 96 | popup_focus: app.popup_focus, | ||
| 97 | history: app.history, | ||
| 98 | watch_history: app.watch_history, | ||
| 99 | search_settings: app.search_settings, | ||
| 100 | search_text: app.search_text, | ||
| 101 | search_index: app.search_index, | ||
| 102 | page_no: app.page_no, | ||
| 103 | state, | ||
| 104 | term_clear: app.term_clear, | ||
| 105 | } | ||
| 106 | } | ||
| 107 | } | ||
| 108 | |||
| 109 | impl Default for App { | ||
| 110 | fn default() -> Self { | ||
| 111 | let config = Config::load().unwrap(); | ||
| 112 | let state: State = config.layouts.main_menu.clone().into(); | ||
| 113 | let selectable = App::selectable(&state); | ||
| 114 | Self { | ||
| 115 | page: Page::default(), | ||
| 116 | state, | ||
| 117 | selectable, | ||
| 118 | client: Client::new(config.main.server_url.clone()), | ||
| 119 | selected: None, | ||
| 120 | hover: None, | ||
| 121 | message: MessageText::None, | ||
| 122 | load: true, | ||
| 123 | render: true, | ||
| 124 | popup_focus: false, | ||
| 125 | history: Vec::new(), | ||
| 126 | config, | ||
| 127 | watch_history: WatchHistory::load(), | ||
| 128 | search_settings: SearchSettings::default(), | ||
| 129 | search_text: String::new(), | ||
| 130 | search_index: 0, | ||
| 131 | page_no: 1, | ||
| 132 | term_clear: false, | ||
| 133 | } | ||
| 134 | } | ||
| 135 | } | ||
| 136 | |||
| 137 | impl App { | ||
| 138 | pub fn selectable(state: &State) -> Vec<Vec<(usize, usize)>> { | ||
| 139 | let mut selectable = Vec::new(); | ||
| 140 | |||
| 141 | for (y, row) in state.0.iter().enumerate() { | ||
| 142 | let mut row_vec = Vec::new(); | ||
| 143 | for (x, row_item) in row.items.iter().enumerate() { | ||
| 144 | if match &row_item.item { | ||
| 145 | Item::Global(item) => item.selectable(), | ||
| 146 | Item::MainMenu(item) => item.selectable(), | ||
| 147 | Item::ItemInfo(item) => item.selectable(), | ||
| 148 | Item::Search(item) => item.selectable(), | ||
| 149 | Item::Channel(item) => item.selectable(), | ||
| 150 | } { | ||
| 151 | row_vec.push((x, y)); | ||
| 152 | } | ||
| 153 | } | ||
| 154 | if row_vec.len() != 0 { | ||
| 155 | selectable.push(row_vec); | ||
| 156 | } | ||
| 157 | } | ||
| 158 | |||
| 159 | selectable | ||
| 160 | } | ||
| 161 | |||
| 162 | pub fn key_input(mut self, key: KeyEvent) -> App { | ||
| 163 | let action = self.config.keybindings.0.get(&key); | ||
| 164 | |||
| 165 | if let Some((x, y)) = self.selected { | ||
| 166 | if action != Some(&Action::Deselect) { | ||
| 167 | let mut item = self.state.0[y].items[x].item.clone(); | ||
| 168 | let updated; | ||
| 169 | (updated, self) = item.key_input(key, self); | ||
| 170 | if updated { | ||
| 171 | self.state.0[y].items[x].item = item; | ||
| 172 | } | ||
| 173 | |||
| 174 | return self; | ||
| 175 | } | ||
| 176 | } | ||
| 177 | |||
| 178 | let action = match action { | ||
| 179 | Some(action) => *action, | ||
| 180 | None => return self, | ||
| 181 | }; | ||
| 182 | |||
| 183 | match action { | ||
| 184 | Action::Refresh => { | ||
| 185 | self.state.reset(); | ||
| 186 | self.load = true; | ||
| 187 | self.render = true; | ||
| 188 | } | ||
| 189 | Action::Select => { | ||
| 190 | if self.hover.is_some() && self.selected.is_none() { | ||
| 191 | let (mut x, mut y) = self.hover.unwrap(); | ||
| 192 | (x, y) = self.selectable[y][x]; | ||
| 193 | |||
| 194 | let select; | ||
| 195 | (self, select) = self.state.0[y] | ||
| 196 | .items | ||
| 197 | .iter() | ||
| 198 | .nth(x) | ||
| 199 | .clone() | ||
| 200 | .unwrap() | ||
| 201 | .item | ||
| 202 | .clone() | ||
| 203 | .select(self); | ||
| 204 | if select { | ||
| 205 | self.selected = Some((x, y)); | ||
| 206 | } | ||
| 207 | |||
| 208 | self.render = true; | ||
| 209 | |||
| 210 | return self; | ||
| 211 | } | ||
| 212 | } | ||
| 213 | Action::Deselect => { | ||
| 214 | if self.selected.is_some() { | ||
| 215 | self.selected = None; | ||
| 216 | self.popup_focus = false; | ||
| 217 | self.render = true; | ||
| 218 | return self; | ||
| 219 | } | ||
| 220 | } | ||
| 221 | |||
| 222 | _ => {} | ||
| 223 | } | ||
| 224 | |||
| 225 | match &mut self.hover { | ||
| 226 | Some((x, y)) => match action { | ||
| 227 | Action::Up => { | ||
| 228 | if *y > 0 { | ||
| 229 | self.render = true; | ||
| 230 | let temp_y = *y - 1; | ||
| 231 | if *x > self.selectable[temp_y].len() { | ||
| 232 | let temp_x = self.selectable[temp_y].len(); | ||
| 233 | if temp_x > self.selectable[*y].len() - 1 { | ||
| 234 | *x = self.selectable[*y].len() - 1; | ||
| 235 | } | ||
| 236 | } | ||
| 237 | *y -= 1; | ||
| 238 | if *x > self.selectable[*y].len() - 1 { | ||
| 239 | *x = self.selectable[*y].len() - 1; | ||
| 240 | } | ||
| 241 | } | ||
| 242 | } | ||
| 243 | Action::Down => { | ||
| 244 | if *y < self.selectable.len() - 1 { | ||
| 245 | self.render = true; | ||
| 246 | *y += 1; | ||
| 247 | if *x > self.selectable[*y].len() - 1 { | ||
| 248 | *x = self.selectable[*y].len() - 1; | ||
| 249 | } | ||
| 250 | } | ||
| 251 | } | ||
| 252 | |||
| 253 | Action::Left => { | ||
| 254 | if *x > 0 { | ||
| 255 | self.render = true; | ||
| 256 | *x -= 1; | ||
| 257 | } | ||
| 258 | } | ||
| 259 | |||
| 260 | Action::Right => { | ||
| 261 | if *x < self.selectable[*y].len() - 1 { | ||
| 262 | self.render = true; | ||
| 263 | *x += 1; | ||
| 264 | } | ||
| 265 | } | ||
| 266 | |||
| 267 | _ => {} | ||
| 268 | }, | ||
| 269 | None => match action { | ||
| 270 | Action::Up => { | ||
| 271 | self.render = true; | ||
| 272 | self.hover = Some((0, 0)); | ||
| 273 | } | ||
| 274 | Action::Down => { | ||
| 275 | self.render = true; | ||
| 276 | self.hover = Some((0, self.selectable.len() - 1)); | ||
| 277 | } | ||
| 278 | Action::Left => { | ||
| 279 | self.render = true; | ||
| 280 | self.hover = Some((0, 0)); | ||
| 281 | } | ||
| 282 | Action::Right => { | ||
| 283 | self.render = true; | ||
| 284 | self.hover = Some((0, self.selectable.len() - 1)); | ||
| 285 | } | ||
| 286 | _ => {} | ||
| 287 | }, | ||
| 288 | } | ||
| 289 | |||
| 290 | self | ||
| 291 | } | ||
| 292 | |||
| 293 | pub fn render<B: Backend>(mut self, frame: &mut Frame<B>) -> Self { | ||
| 294 | let size = frame.size(); | ||
| 295 | let mut popups = Vec::new(); | ||
| 296 | |||
| 297 | let min = self.page.min(&self.config); | ||
| 298 | |||
| 299 | if size.width < min.0 || size.height < min.1 { | ||
| 300 | let paragraph = Paragraph::new(format!( | ||
| 301 | "Window too small. Minimum size for this page is {} x {}. Current size is {} x {}", | ||
| 302 | min.0, min.1, size.width, size.height | ||
| 303 | )) | ||
| 304 | .block(Block::default()) | ||
| 305 | .style(Style::default().fg(Color::Red)) | ||
| 306 | .wrap(Wrap { trim: true }); | ||
| 307 | frame.render_widget(paragraph, size); | ||
| 308 | return self; | ||
| 309 | } | ||
| 310 | |||
| 311 | let hover_selected = if let Some((x, y)) = self.hover { | ||
| 312 | Some(self.selectable[y][x]) | ||
| 313 | } else { | ||
| 314 | None | ||
| 315 | }; | ||
| 316 | |||
| 317 | let vertical_chunks = Layout::default() | ||
| 318 | .direction(Direction::Vertical) | ||
| 319 | .constraints( | ||
| 320 | self.state | ||
| 321 | .0 | ||
| 322 | .iter() | ||
| 323 | .map(|row| row.height) | ||
| 324 | .collect::<Vec<Constraint>>(), | ||
| 325 | ) | ||
| 326 | .split(size); | ||
| 327 | |||
| 328 | let (mut app, mut state) = AppNoState::split(self); | ||
| 329 | |||
| 330 | for (y, (row, row_chunk)) in state | ||
| 331 | .0 | ||
| 332 | .iter_mut() | ||
| 333 | .zip(vertical_chunks.clone().iter_mut()) | ||
| 334 | .enumerate() | ||
| 335 | { | ||
| 336 | let mut constraints = LinkedList::new(); | ||
| 337 | let mut length = match row.centered { | ||
| 338 | true => Some(0), | ||
| 339 | false => None, | ||
| 340 | }; | ||
| 341 | for item in row.items.iter() { | ||
| 342 | constraints.push_back(item.constraint); | ||
| 343 | if let Some(length_value) = length { | ||
| 344 | length = Some(match item.constraint { | ||
| 345 | Constraint::Length(l) | Constraint::Max(l) | Constraint::Min(l) => { | ||
| 346 | l + length_value | ||
| 347 | } | ||
| 348 | Constraint::Percentage(p) => length_value + size.width * p / 100, | ||
| 349 | _ => unreachable!(), | ||
| 350 | }) | ||
| 351 | } | ||
| 352 | } | ||
| 353 | |||
| 354 | if let Some(i) = length { | ||
| 355 | let extra_constraint = Constraint::Length((size.width - i) / 2); | ||
| 356 | constraints.push_front(extra_constraint); | ||
| 357 | } else { | ||
| 358 | constraints.push_front(Constraint::Length(0)); | ||
| 359 | } | ||
| 360 | |||
| 361 | constraints.push_back(Constraint::Length(0)); | ||
| 362 | |||
| 363 | let mut chunks = Layout::default() | ||
| 364 | .direction(Direction::Horizontal) | ||
| 365 | .constraints(constraints.into_iter().collect::<Vec<Constraint>>()) | ||
| 366 | .split(*row_chunk) | ||
| 367 | .into_iter(); | ||
| 368 | |||
| 369 | frame.render_widget(Block::default(), chunks.next().unwrap()); | ||
| 370 | |||
| 371 | let popup_focus = app.popup_focus; | ||
| 372 | for (x, (chunk, item)) in chunks | ||
| 373 | .zip(row.items.iter_mut().map(|i| &mut i.item)) | ||
| 374 | .enumerate() | ||
| 375 | { | ||
| 376 | let selected = app.selected == Some((x, y)); | ||
| 377 | |||
| 378 | let hover = hover_selected == Some((x, y)); | ||
| 379 | |||
| 380 | let hold = item.render_item(frame, chunk, app, selected, hover, popup_focus, false); | ||
| 381 | |||
| 382 | app = hold.1; | ||
| 383 | |||
| 384 | if hold.0 { | ||
| 385 | popups.push((item, selected, hover, chunk)); | ||
| 386 | } | ||
| 387 | } | ||
| 388 | } | ||
| 389 | |||
| 390 | for (item, selected, hover, chunk) in popups { | ||
| 391 | let hold = item.render_item(frame, chunk, app, selected, hover, true, true); | ||
| 392 | app = hold.1; | ||
| 393 | } | ||
| 394 | |||
| 395 | self = AppNoState::join(app, state); | ||
| 396 | self | ||
| 397 | } | ||
| 398 | |||
| 399 | pub fn pop(mut self) -> (App, bool) { | ||
| 400 | if self.history.len() == 0 { | ||
| 401 | self.message = MessageText::Text(String::from("This is the beginning of history")); | ||
| 402 | return (self, false); | ||
| 403 | } | ||
| 404 | |||
| 405 | let app_history = self.history.pop().unwrap(); | ||
| 406 | |||
| 407 | self = Self { | ||
| 408 | state: app_history.state, | ||
| 409 | selectable: app_history.selectable, | ||
| 410 | selected: app_history.selected, | ||
| 411 | hover: app_history.hover, | ||
| 412 | message: app_history.message, | ||
| 413 | page: app_history.page, | ||
| 414 | client: app_history.client, | ||
| 415 | load: app_history.load, | ||
| 416 | render: app_history.render, | ||
| 417 | history: self.history.clone(), | ||
| 418 | config: self.config, | ||
| 419 | watch_history: self.watch_history, | ||
| 420 | search_settings: self.search_settings, | ||
| 421 | popup_focus: app_history.popup_focus, | ||
| 422 | search_text: app_history.search_text, | ||
| 423 | search_index: app_history.search_index, | ||
| 424 | page_no: app_history.page_no, | ||
| 425 | term_clear: false, | ||
| 426 | }; | ||
| 427 | |||
| 428 | (self, true) | ||
| 429 | } | ||
| 430 | |||
| 431 | pub fn home(&mut self) { | ||
| 432 | *self = App::default(); | ||
| 433 | } | ||
| 434 | |||
| 435 | pub fn page_layout(&self) -> LayoutConfig { | ||
| 436 | match self.page { | ||
| 437 | Page::Search => self.config.layouts.search.clone(), | ||
| 438 | Page::MainMenu(_) => self.config.layouts.main_menu.clone(), | ||
| 439 | Page::ItemDisplay(_) => self.config.layouts.item_info.clone(), | ||
| 440 | Page::Channel(_, _) => self.config.layouts.channel.clone(), | ||
| 441 | } | ||
| 442 | } | ||
| 443 | |||
| 444 | pub fn page_default(&self) -> Option<(usize, usize)> { | ||
| 445 | match self.page { | ||
| 446 | Page::Search => self.config.layouts.search.def_selected, | ||
| 447 | Page::MainMenu(_) => self.config.layouts.main_menu.def_selected, | ||
| 448 | Page::ItemDisplay(_) => self.config.layouts.item_info.def_selected, | ||
| 449 | Page::Channel(_, _) => self.config.layouts.channel.def_selected, | ||
| 450 | } | ||
| 451 | } | ||
| 452 | } | ||
src/app/config/colors.rs deleted −1
| @@ -1 +0,0 @@ | |||
| 1 | // TODO | ||
src/app/config/commands.rs deleted −179
| @@ -1,179 +0,0 @@ | |||
| 1 | use serde::{Deserialize, Serialize}; | ||
| 2 | use std::{collections::HashMap, thread}; | ||
| 3 | |||
| 4 | use crate::traits::ConfigItem; | ||
| 5 | |||
| 6 | #[derive(Serialize, Deserialize, Clone)] | ||
| 7 | pub struct Command { | ||
| 8 | pub args: Vec<String>, | ||
| 9 | pub message: String, | ||
| 10 | } | ||
| 11 | |||
| 12 | #[derive(Serialize, Deserialize, Clone)] | ||
| 13 | pub struct CommandsConfig(pub HashMap<String, Command>); | ||
| 14 | |||
| 15 | impl Command { | ||
| 16 | pub fn as_vec(&self, variables: &HashMap<String, String>) -> Result<Vec<String>, String> { | ||
| 17 | let mut out = Vec::new(); | ||
| 18 | |||
| 19 | for arg in self.args.iter() { | ||
| 20 | out.push(match check_arg(arg) { | ||
| 21 | ArgType::Normal(s) => s, | ||
| 22 | ArgType::Variable(s) => match variables.get(s) { | ||
| 23 | Some(s) => s.to_string(), | ||
| 24 | None => return Err(s.to_string()), | ||
| 25 | }, | ||
| 26 | }) | ||
| 27 | } | ||
| 28 | |||
| 29 | Ok(out) | ||
| 30 | } | ||
| 31 | |||
| 32 | pub fn run_command(&self, variables: &HashMap<String, String>) -> Option<String> { | ||
| 33 | let mut args = match self.as_vec(variables) { | ||
| 34 | Ok(args) => args, | ||
| 35 | Err(s) => return Some(s), | ||
| 36 | } | ||
| 37 | .into_iter(); | ||
| 38 | thread::spawn(move || { | ||
| 39 | let mut command = std::process::Command::new(args.next().unwrap()); | ||
| 40 | for arg in args { | ||
| 41 | command.arg(arg); | ||
| 42 | } | ||
| 43 | |||
| 44 | let _ = command.output(); | ||
| 45 | }); | ||
| 46 | |||
| 47 | None | ||
| 48 | } | ||
| 49 | } | ||
| 50 | |||
| 51 | impl Default for CommandsConfig { | ||
| 52 | fn default() -> Self { | ||
| 53 | let mut out = Self::blank(); | ||
| 54 | |||
| 55 | out.insert( | ||
| 56 | "video_player", | ||
| 57 | vec!["mpv", "{embed_url}", "--no-terminal"], | ||
| 58 | "Launched mpv", | ||
| 59 | ); | ||
| 60 | out.insert( | ||
| 61 | "audio_player", | ||
| 62 | vec!["konsole", "-e", "mpv", "{embed_url}", "--no-video"], | ||
| 63 | "Opened mpv in new konsole window", | ||
| 64 | ); | ||
| 65 | out.insert( | ||
| 66 | "audio_playlist_shuffle", | ||
| 67 | vec![ | ||
| 68 | "konsole", | ||
| 69 | "-e", | ||
| 70 | "mpv", | ||
| 71 | "{embed_url}", | ||
| 72 | "--no-video", | ||
| 73 | "--shuffle", | ||
| 74 | ], | ||
| 75 | "Opened mpv in new konsole window", | ||
| 76 | ); | ||
| 77 | out.insert( | ||
| 78 | "audio_playlist_loop", | ||
| 79 | vec![ | ||
| 80 | "konsole", | ||
| 81 | "-e", | ||
| 82 | "mpv", | ||
| 83 | "{embed_url}", | ||
| 84 | "--no-video", | ||
| 85 | "--loop-playlist=inf", | ||
| 86 | ], | ||
| 87 | "Opened mpv in new konsole window", | ||
| 88 | ); | ||
| 89 | out.insert( | ||
| 90 | "audio_playlist_shuffle_loop", | ||
| 91 | vec![ | ||
| 92 | "konsole", | ||
| 93 | "-e", | ||
| 94 | "mpv", | ||
| 95 | "{embed_url}", | ||
| 96 | "--no-video", | ||
| 97 | "--loop-playlist=inf", | ||
| 98 | "--shuffle", | ||
| 99 | ], | ||
| 100 | "Opened mpv in new konsole window", | ||
| 101 | ); | ||
| 102 | out.insert( | ||
| 103 | "audio_loop", | ||
| 104 | vec![ | ||
| 105 | "konsole", | ||
| 106 | "-e", | ||
| 107 | "mpv", | ||
| 108 | "{embed_url}", | ||
| 109 | "--no-video", | ||
| 110 | "--loop", | ||
| 111 | ], | ||
| 112 | "Opened mpv in new konsole window", | ||
| 113 | ); | ||
| 114 | out.insert( | ||
| 115 | "video_downloader", | ||
| 116 | vec![ | ||
| 117 | "konsole", | ||
| 118 | "-e", | ||
| 119 | "yt-dlp", | ||
| 120 | "{embed_url}", | ||
| 121 | "-o", | ||
| 122 | "{download_location}", | ||
| 123 | ], | ||
| 124 | "Download has started", | ||
| 125 | ); | ||
| 126 | |||
| 127 | out.insert( | ||
| 128 | "audio_downloader", | ||
| 129 | vec![ | ||
| 130 | "konsole", | ||
| 131 | "-e", | ||
| 132 | "yt-dlp", | ||
| 133 | "{embed_url}", | ||
| 134 | "-o", | ||
| 135 | "{download_location}", | ||
| 136 | "-x", | ||
| 137 | ], | ||
| 138 | "Download has started", | ||
| 139 | ); | ||
| 140 | |||
| 141 | out | ||
| 142 | } | ||
| 143 | } | ||
| 144 | |||
| 145 | impl CommandsConfig { | ||
| 146 | fn blank() -> Self { | ||
| 147 | Self(HashMap::default()) | ||
| 148 | } | ||
| 149 | |||
| 150 | fn insert(&mut self, label: &str, command: Vec<&str>, msg: &str) { | ||
| 151 | self.0.insert( | ||
| 152 | label.to_string(), | ||
| 153 | Command { | ||
| 154 | args: command | ||
| 155 | .into_iter() | ||
| 156 | .map(|item| item.to_string()) | ||
| 157 | .collect::<Vec<_>>(), | ||
| 158 | message: msg.to_string(), | ||
| 159 | }, | ||
| 160 | ); | ||
| 161 | } | ||
| 162 | } | ||
| 163 | |||
| 164 | impl ConfigItem<'_> for CommandsConfig { | ||
| 165 | type Struct = CommandsConfig; | ||
| 166 | const FILE_NAME: &'static str = "commands.yml"; | ||
| 167 | } | ||
| 168 | enum ArgType<'a> { | ||
| 169 | Normal(String), | ||
| 170 | Variable(&'a str), | ||
| 171 | } | ||
| 172 | |||
| 173 | fn check_arg(s: &str) -> ArgType { | ||
| 174 | if s.starts_with('{') && s.ends_with('}') { | ||
| 175 | ArgType::Variable(&s[1..s.len() - 1]) | ||
| 176 | } else { | ||
| 177 | ArgType::Normal(s.to_string()) | ||
| 178 | } | ||
| 179 | } | ||
src/app/config/config.rs deleted −49
| @@ -1,49 +0,0 @@ | |||
| 1 | use std::error::Error; | ||
| 2 | |||
| 3 | use super::{ | ||
| 4 | commands::CommandsConfig, KeybindingsConfig, LayoutsConfigs, MainConfig, PageCommandsConfig, | ||
| 5 | }; | ||
| 6 | use crate::traits::ConfigItem; | ||
| 7 | |||
| 8 | #[derive(Clone)] | ||
| 9 | pub struct Config { | ||
| 10 | pub commands: CommandsConfig, | ||
| 11 | pub main: MainConfig, | ||
| 12 | pub page_commands: PageCommandsConfig, | ||
| 13 | pub keybindings: KeybindingsConfig, | ||
| 14 | pub layouts: LayoutsConfigs, | ||
| 15 | } | ||
| 16 | |||
| 17 | impl Default for Config { | ||
| 18 | fn default() -> Self { | ||
| 19 | Self { | ||
| 20 | commands: CommandsConfig::default(), | ||
| 21 | main: MainConfig::default(), | ||
| 22 | page_commands: PageCommandsConfig::default(), | ||
| 23 | keybindings: KeybindingsConfig::default(), | ||
| 24 | layouts: LayoutsConfigs::default(), | ||
| 25 | } | ||
| 26 | } | ||
| 27 | } | ||
| 28 | |||
| 29 | impl Config { | ||
| 30 | pub fn load() -> Result<Self, Box<dyn Error>> { | ||
| 31 | Ok(Self { | ||
| 32 | main: MainConfig::load()?, | ||
| 33 | commands: CommandsConfig::load()?, | ||
| 34 | page_commands: PageCommandsConfig::load()?, | ||
| 35 | keybindings: KeybindingsConfig::load()?.into(), | ||
| 36 | layouts: LayoutsConfigs::load()?, | ||
| 37 | }) | ||
| 38 | } | ||
| 39 | } | ||
| 40 | |||
| 41 | pub struct EnvVar { | ||
| 42 | pub url: Option<String>, | ||
| 43 | } | ||
| 44 | |||
| 45 | impl Default for EnvVar { | ||
| 46 | fn default() -> Self { | ||
| 47 | Self { url: None } | ||
| 48 | } | ||
| 49 | } | ||
src/app/config/keybindings.rs deleted −289
| @@ -1,289 +0,0 @@ | |||
| 1 | use std::collections::HashMap; | ||
| 2 | |||
| 3 | use crossterm::event::{KeyCode, KeyEvent, KeyModifiers}; | ||
| 4 | use serde::{Deserialize, Serialize}; | ||
| 5 | |||
| 6 | use crate::traits::ConfigItem; | ||
| 7 | |||
| 8 | #[derive(Serialize, Deserialize, Clone, Copy, PartialEq, Eq)] | ||
| 9 | pub enum Action { | ||
| 10 | Up, | ||
| 11 | Down, | ||
| 12 | Left, | ||
| 13 | Right, | ||
| 14 | Select, | ||
| 15 | Deselect, | ||
| 16 | FirstItem, | ||
| 17 | LastItem, | ||
| 18 | Home, | ||
| 19 | Exit, | ||
| 20 | Back, | ||
| 21 | ClearHistory, | ||
| 22 | Refresh, | ||
| 23 | } | ||
| 24 | |||
| 25 | #[derive(Serialize, Deserialize, Clone, PartialEq, Eq, Hash)] | ||
| 26 | pub enum KeyCodeTransitional { | ||
| 27 | Backspace, | ||
| 28 | Enter, | ||
| 29 | Left, | ||
| 30 | Right, | ||
| 31 | Up, | ||
| 32 | Down, | ||
| 33 | Home, | ||
| 34 | End, | ||
| 35 | PageUp, | ||
| 36 | PageDown, | ||
| 37 | Tab, | ||
| 38 | BackTab, | ||
| 39 | Delete, | ||
| 40 | Insert, | ||
| 41 | F(u8), | ||
| 42 | Char(char), | ||
| 43 | Null, | ||
| 44 | Esc, | ||
| 45 | } | ||
| 46 | |||
| 47 | impl Into<KeyCode> for KeyCodeTransitional { | ||
| 48 | fn into(self) -> KeyCode { | ||
| 49 | match self { | ||
| 50 | Self::Backspace => KeyCode::Backspace, | ||
| 51 | Self::Enter => KeyCode::Enter, | ||
| 52 | Self::Left => KeyCode::Left, | ||
| 53 | Self::Right => KeyCode::Right, | ||
| 54 | Self::Up => KeyCode::Up, | ||
| 55 | Self::Down => KeyCode::Down, | ||
| 56 | Self::Home => KeyCode::Home, | ||
| 57 | Self::End => KeyCode::End, | ||
| 58 | Self::PageUp => KeyCode::PageUp, | ||
| 59 | Self::PageDown => KeyCode::PageDown, | ||
| 60 | Self::Tab => KeyCode::Tab, | ||
| 61 | Self::BackTab => KeyCode::BackTab, | ||
| 62 | Self::Delete => KeyCode::Delete, | ||
| 63 | Self::Insert => KeyCode::Insert, | ||
| 64 | Self::F(n) => KeyCode::F(n), | ||
| 65 | Self::Char(c) => KeyCode::Char(c), | ||
| 66 | Self::Null => KeyCode::Null, | ||
| 67 | Self::Esc => KeyCode::Esc, | ||
| 68 | } | ||
| 69 | } | ||
| 70 | } | ||
| 71 | |||
| 72 | impl Into<KeybindingsConfig> for KeybindingsConfigTransitional { | ||
| 73 | fn into(self) -> KeybindingsConfig { | ||
| 74 | let mut out = HashMap::default(); | ||
| 75 | |||
| 76 | for ((modifiers, code), v) in self.0.into_iter() { | ||
| 77 | out.insert( | ||
| 78 | KeyEvent { | ||
| 79 | code: code.into(), | ||
| 80 | modifiers: modifiers.into(), | ||
| 81 | }, | ||
| 82 | v, | ||
| 83 | ); | ||
| 84 | } | ||
| 85 | |||
| 86 | KeybindingsConfig(out) | ||
| 87 | } | ||
| 88 | } | ||
| 89 | |||
| 90 | #[derive(Clone, Copy, Hash, PartialEq, Eq, Serialize, Deserialize)] | ||
| 91 | pub enum KeyModifierTransitional { | ||
| 92 | Shift, | ||
| 93 | Control, | ||
| 94 | Alt, | ||
| 95 | r#None, | ||
| 96 | } | ||
| 97 | |||
| 98 | impl Into<KeyModifiers> for KeyModifierTransitional { | ||
| 99 | fn into(self) -> KeyModifiers { | ||
| 100 | match self { | ||
| 101 | Self::Shift => KeyModifiers::SHIFT, | ||
| 102 | Self::Control => KeyModifiers::CONTROL, | ||
| 103 | Self::Alt => KeyModifiers::ALT, | ||
| 104 | Self::None => KeyModifiers::NONE, | ||
| 105 | } | ||
| 106 | } | ||
| 107 | } | ||
| 108 | |||
| 109 | impl Into<KeyModifiersTransitional> for KeyModifierTransitional { | ||
| 110 | fn into(self) -> KeyModifiersTransitional { | ||
| 111 | KeyModifiersTransitional(vec![self]) | ||
| 112 | } | ||
| 113 | } | ||
| 114 | |||
| 115 | #[derive(Clone, Hash, PartialEq, Eq, Serialize, Deserialize)] | ||
| 116 | pub struct KeyModifiersTransitional(Vec<KeyModifierTransitional>); | ||
| 117 | |||
| 118 | impl Into<KeyModifiers> for KeyModifiersTransitional { | ||
| 119 | fn into(self) -> KeyModifiers { | ||
| 120 | KeyModifiers::from_bits( | ||
| 121 | self.0 | ||
| 122 | .into_iter() | ||
| 123 | .map(|item| Into::<KeyModifiers>::into(item).bits()) | ||
| 124 | .sum(), | ||
| 125 | ) | ||
| 126 | .unwrap() | ||
| 127 | } | ||
| 128 | } | ||
| 129 | |||
| 130 | impl Default for KeyModifiersTransitional { | ||
| 131 | fn default() -> Self { | ||
| 132 | Self(vec![KeyModifierTransitional::None]) | ||
| 133 | } | ||
| 134 | } | ||
| 135 | |||
| 136 | #[derive(Serialize, Deserialize, Clone)] | ||
| 137 | pub struct KeybindingsConfigTransitional( | ||
| 138 | pub HashMap<(KeyModifiersTransitional, KeyCodeTransitional), Action>, | ||
| 139 | ); | ||
| 140 | |||
| 141 | impl Default for KeybindingsConfigTransitional { | ||
| 142 | fn default() -> Self { | ||
| 143 | let mut out = HashMap::default(); | ||
| 144 | |||
| 145 | out.insert( | ||
| 146 | (KeyModifiersTransitional::default(), KeyCodeTransitional::Up), | ||
| 147 | Action::Up, | ||
| 148 | ); | ||
| 149 | out.insert( | ||
| 150 | ( | ||
| 151 | KeyModifiersTransitional::default(), | ||
| 152 | KeyCodeTransitional::Down, | ||
| 153 | ), | ||
| 154 | Action::Down, | ||
| 155 | ); | ||
| 156 | out.insert( | ||
| 157 | ( | ||
| 158 | KeyModifiersTransitional::default(), | ||
| 159 | KeyCodeTransitional::Left, | ||
| 160 | ), | ||
| 161 | Action::Left, | ||
| 162 | ); | ||
| 163 | out.insert( | ||
| 164 | ( | ||
| 165 | KeyModifiersTransitional::default(), | ||
| 166 | KeyCodeTransitional::Right, | ||
| 167 | ), | ||
| 168 | Action::Right, | ||
| 169 | ); | ||
| 170 | |||
| 171 | out.insert( | ||
| 172 | ( | ||
| 173 | KeyModifiersTransitional::default(), | ||
| 174 | KeyCodeTransitional::Char('h'), | ||
| 175 | ), | ||
| 176 | Action::Left, | ||
| 177 | ); | ||
| 178 | out.insert( | ||
| 179 | ( | ||
| 180 | KeyModifiersTransitional::default(), | ||
| 181 | KeyCodeTransitional::Char('j'), | ||
| 182 | ), | ||
| 183 | Action::Down, | ||
| 184 | ); | ||
| 185 | out.insert( | ||
| 186 | ( | ||
| 187 | KeyModifiersTransitional::default(), | ||
| 188 | KeyCodeTransitional::Char('k'), | ||
| 189 | ), | ||
| 190 | Action::Up, | ||
| 191 | ); | ||
| 192 | out.insert( | ||
| 193 | ( | ||
| 194 | KeyModifiersTransitional::default(), | ||
| 195 | KeyCodeTransitional::Char('l'), | ||
| 196 | ), | ||
| 197 | Action::Right, | ||
| 198 | ); | ||
| 199 | |||
| 200 | out.insert( | ||
| 201 | ( | ||
| 202 | KeyModifiersTransitional::default(), | ||
| 203 | KeyCodeTransitional::PageUp, | ||
| 204 | ), | ||
| 205 | Action::FirstItem, | ||
| 206 | ); | ||
| 207 | out.insert( | ||
| 208 | ( | ||
| 209 | KeyModifiersTransitional::default(), | ||
| 210 | KeyCodeTransitional::PageDown, | ||
| 211 | ), | ||
| 212 | Action::LastItem, | ||
| 213 | ); | ||
| 214 | |||
| 215 | out.insert( | ||
| 216 | ( | ||
| 217 | KeyModifiersTransitional::default(), | ||
| 218 | KeyCodeTransitional::Enter, | ||
| 219 | ), | ||
| 220 | Action::Select, | ||
| 221 | ); | ||
| 222 | out.insert( | ||
| 223 | ( | ||
| 224 | KeyModifiersTransitional::default(), | ||
| 225 | KeyCodeTransitional::Esc, | ||
| 226 | ), | ||
| 227 | Action::Deselect, | ||
| 228 | ); | ||
| 229 | out.insert( | ||
| 230 | ( | ||
| 231 | KeyModifiersTransitional::default(), | ||
| 232 | KeyCodeTransitional::Char('q'), | ||
| 233 | ), | ||
| 234 | Action::Exit, | ||
| 235 | ); | ||
| 236 | |||
| 237 | out.insert( | ||
| 238 | ( | ||
| 239 | KeyModifiersTransitional::default(), | ||
| 240 | KeyCodeTransitional::Home, | ||
| 241 | ), | ||
| 242 | Action::Home, | ||
| 243 | ); | ||
| 244 | out.insert( | ||
| 245 | ( | ||
| 246 | KeyModifiersTransitional::default(), | ||
| 247 | KeyCodeTransitional::Backspace, | ||
| 248 | ), | ||
| 249 | Action::Back, | ||
| 250 | ); | ||
| 251 | out.insert( | ||
| 252 | ( | ||
| 253 | KeyModifierTransitional::Alt.into(), | ||
| 254 | KeyCodeTransitional::Left, | ||
| 255 | ), | ||
| 256 | Action::Back, | ||
| 257 | ); | ||
| 258 | out.insert( | ||
| 259 | ( | ||
| 260 | KeyModifiersTransitional::default(), | ||
| 261 | KeyCodeTransitional::End, | ||
| 262 | ), | ||
| 263 | Action::ClearHistory, | ||
| 264 | ); | ||
| 265 | out.insert( | ||
| 266 | ( | ||
| 267 | KeyModifierTransitional::Control.into(), | ||
| 268 | KeyCodeTransitional::Char('r'), | ||
| 269 | ), | ||
| 270 | Action::Refresh, | ||
| 271 | ); | ||
| 272 | |||
| 273 | Self(out) | ||
| 274 | } | ||
| 275 | } | ||
| 276 | |||
| 277 | impl Default for KeybindingsConfig { | ||
| 278 | fn default() -> Self { | ||
| 279 | KeybindingsConfigTransitional::default().into() | ||
| 280 | } | ||
| 281 | } | ||
| 282 | |||
| 283 | #[derive(Clone)] | ||
| 284 | pub struct KeybindingsConfig(pub HashMap<KeyEvent, Action>); | ||
| 285 | |||
| 286 | impl ConfigItem<'_> for KeybindingsConfig { | ||
| 287 | type Struct = KeybindingsConfigTransitional; | ||
| 288 | const FILE_NAME: &'static str = "keybindings.yml"; | ||
| 289 | } | ||
src/app/config/layouts.rs deleted −176
| @@ -1,176 +0,0 @@ | |||
| 1 | use crate::{ | ||
| 2 | app::pages::{ | ||
| 3 | channel::{Channel, ChannelDisplayItem, ChannelItem, ChannelPage}, | ||
| 4 | global::GlobalItem, | ||
| 5 | item_info::{ItemInfo, ItemInfoItem}, | ||
| 6 | main_menu::{MainMenu, MainMenuItem, MainMenuSelector}, | ||
| 7 | search::{Search, SearchItem}, | ||
| 8 | }, | ||
| 9 | structs::{Item, Row, RowItem, State}, | ||
| 10 | traits::{ConfigItem, PageTrait}, | ||
| 11 | widgets::text_list::TextList, | ||
| 12 | }; | ||
| 13 | use serde::{Deserialize, Serialize}; | ||
| 14 | use tui::layout::Constraint; | ||
| 15 | |||
| 16 | #[derive(Serialize, Deserialize, Clone)] | ||
| 17 | pub struct LayoutsConfigs { | ||
| 18 | #[serde(default = "MainMenu::default")] | ||
| 19 | pub main_menu: LayoutConfig, | ||
| 20 | #[serde(default = "Channel::default")] | ||
| 21 | pub channel: LayoutConfig, | ||
| 22 | #[serde(default = "ItemInfo::default")] | ||
| 23 | pub item_info: LayoutConfig, | ||
| 24 | #[serde(default = "Search::default")] | ||
| 25 | pub search: LayoutConfig, | ||
| 26 | } | ||
| 27 | |||
| 28 | impl Default for LayoutsConfigs { | ||
| 29 | fn default() -> Self { | ||
| 30 | Self { | ||
| 31 | main_menu: MainMenu::default(), | ||
| 32 | channel: Channel::default(), | ||
| 33 | item_info: ItemInfo::default(), | ||
| 34 | search: Search::default(), | ||
| 35 | } | ||
| 36 | } | ||
| 37 | } | ||
| 38 | |||
| 39 | #[derive(Serialize, Deserialize, Clone, Copy)] | ||
| 40 | pub enum ConstraintTransitional { | ||
| 41 | Percentage(u16), | ||
| 42 | Ratio(u32, u32), | ||
| 43 | Length(u16), | ||
| 44 | Max(u16), | ||
| 45 | Min(u16), | ||
| 46 | } | ||
| 47 | |||
| 48 | impl Into<Constraint> for ConstraintTransitional { | ||
| 49 | fn into(self) -> Constraint { | ||
| 50 | match self { | ||
| 51 | Self::Percentage(i) => Constraint::Percentage(i), | ||
| 52 | Self::Ratio(i1, i2) => Constraint::Ratio(i1, i2), | ||
| 53 | Self::Length(i) => Constraint::Length(i), | ||
| 54 | Self::Max(i) => Constraint::Max(i), | ||
| 55 | Self::Min(i) => Constraint::Min(i), | ||
| 56 | } | ||
| 57 | } | ||
| 58 | } | ||
| 59 | |||
| 60 | #[derive(Serialize, Deserialize, Clone)] | ||
| 61 | pub struct LayoutConfig { | ||
| 62 | pub layout: Vec<RowTransitional>, | ||
| 63 | pub min: (u16, u16), | ||
| 64 | pub message: String, | ||
| 65 | pub def_selected: Option<(usize, usize)>, | ||
| 66 | } | ||
| 67 | |||
| 68 | impl Into<State> for LayoutConfig { | ||
| 69 | fn into(self) -> State { | ||
| 70 | State(self.layout.into_iter().map(|item| item.into()).collect()) | ||
| 71 | } | ||
| 72 | } | ||
| 73 | |||
| 74 | #[derive(Serialize, Deserialize, Clone)] | ||
| 75 | pub struct RowTransitional { | ||
| 76 | pub items: Vec<RowItemTransitional>, | ||
| 77 | pub centered: bool, | ||
| 78 | pub height: ConstraintTransitional, | ||
| 79 | } | ||
| 80 | |||
| 81 | impl Into<Row> for RowTransitional { | ||
| 82 | fn into(self) -> Row { | ||
| 83 | Row { | ||
| 84 | items: self.items.into_iter().map(|item| item.into()).collect(), | ||
| 85 | centered: self.centered, | ||
| 86 | height: self.height.into(), | ||
| 87 | } | ||
| 88 | } | ||
| 89 | } | ||
| 90 | |||
| 91 | #[derive(Serialize, Deserialize, Clone)] | ||
| 92 | pub struct RowItemTransitional { | ||
| 93 | pub item: ItemTransitional, | ||
| 94 | pub constraint: ConstraintTransitional, | ||
| 95 | } | ||
| 96 | |||
| 97 | impl Into<RowItem> for RowItemTransitional { | ||
| 98 | fn into(self) -> RowItem { | ||
| 99 | RowItem { | ||
| 100 | item: self.item.into(), | ||
| 101 | constraint: self.constraint.into(), | ||
| 102 | } | ||
| 103 | } | ||
| 104 | } | ||
| 105 | |||
| 106 | #[derive(Serialize, Deserialize, Clone)] | ||
| 107 | pub enum ItemTransitional { | ||
| 108 | Global(GlobalItem), | ||
| 109 | MainMenu(MainMenuItemTransitional), | ||
| 110 | ItemInfo, | ||
| 111 | Search(SearchItemTransitional), | ||
| 112 | Channel(ChannelItemTransitional), | ||
| 113 | } | ||
| 114 | |||
| 115 | impl Into<Item> for ItemTransitional { | ||
| 116 | fn into(self) -> Item { | ||
| 117 | match self { | ||
| 118 | Self::Global(i) => Item::Global(i), | ||
| 119 | Self::MainMenu(i) => Item::MainMenu(i.into()), | ||
| 120 | Self::ItemInfo => Item::ItemInfo(ItemInfoItem::Unknown), | ||
| 121 | Self::Search(i) => Item::Search(i.into()), | ||
| 122 | Self::Channel(i) => Item::Channel(i.into()), | ||
| 123 | } | ||
| 124 | } | ||
| 125 | } | ||
| 126 | |||
| 127 | #[derive(Serialize, Deserialize, Clone, Copy)] | ||
| 128 | pub enum MainMenuItemTransitional { | ||
| 129 | SelectorTab(MainMenuSelector), | ||
| 130 | VideoList, | ||
| 131 | } | ||
| 132 | |||
| 133 | impl Into<MainMenuItem> for MainMenuItemTransitional { | ||
| 134 | fn into(self) -> MainMenuItem { | ||
| 135 | match self { | ||
| 136 | Self::SelectorTab(i) => MainMenuItem::SeletorTab(i), | ||
| 137 | Self::VideoList => MainMenuItem::VideoList(None), | ||
| 138 | } | ||
| 139 | } | ||
| 140 | } | ||
| 141 | |||
| 142 | #[derive(Serialize, Deserialize, Clone, Copy)] | ||
| 143 | pub enum ChannelItemTransitional { | ||
| 144 | InfoDisplay, | ||
| 145 | SelectItems(ChannelPage), | ||
| 146 | } | ||
| 147 | |||
| 148 | impl Into<ChannelItem> for ChannelItemTransitional { | ||
| 149 | fn into(self) -> ChannelItem { | ||
| 150 | match self { | ||
| 151 | Self::InfoDisplay => ChannelItem::InfoDisplay(ChannelDisplayItem::Unknown), | ||
| 152 | Self::SelectItems(i) => ChannelItem::SelectItems(i), | ||
| 153 | } | ||
| 154 | } | ||
| 155 | } | ||
| 156 | |||
| 157 | #[derive(Serialize, Deserialize, Clone, Copy)] | ||
| 158 | pub enum SearchItemTransitional { | ||
| 159 | Search, | ||
| 160 | } | ||
| 161 | |||
| 162 | impl Into<SearchItem> for SearchItemTransitional { | ||
| 163 | fn into(self) -> SearchItem { | ||
| 164 | match self { | ||
| 165 | Self::Search => SearchItem::Search { | ||
| 166 | results: None, | ||
| 167 | text_list: TextList::default(), | ||
| 168 | }, | ||
| 169 | } | ||
| 170 | } | ||
| 171 | } | ||
| 172 | |||
| 173 | impl ConfigItem<'_> for LayoutsConfigs { | ||
| 174 | type Struct = LayoutsConfigs; | ||
| 175 | const FILE_NAME: &'static str = "layouts.yml"; | ||
| 176 | } | ||
src/app/config/main.rs deleted −58
| @@ -1,58 +0,0 @@ | |||
| 1 | use std::collections::HashMap; | ||
| 2 | |||
| 3 | use crate::traits::ConfigItem; | ||
| 4 | use serde::{Deserialize, Serialize}; | ||
| 5 | |||
| 6 | fn max_watch_history_default() -> usize { | ||
| 7 | 50 | ||
| 8 | } | ||
| 9 | |||
| 10 | fn server_url_default() -> String { | ||
| 11 | String::from("https://invidious.flokinet.to") | ||
| 12 | } | ||
| 13 | |||
| 14 | fn env_default() -> HashMap<String, String> { | ||
| 15 | let mut out = HashMap::default(); | ||
| 16 | |||
| 17 | out.insert( | ||
| 18 | String::from("download_location"), | ||
| 19 | String::from("~/Downloads/%(title)s.%(ext)s"), | ||
| 20 | ); | ||
| 21 | |||
| 22 | out | ||
| 23 | } | ||
| 24 | |||
| 25 | fn display_thumbnails_default() -> bool { | ||
| 26 | true | ||
| 27 | } | ||
| 28 | |||
| 29 | #[derive(Clone, Serialize, Deserialize)] | ||
| 30 | pub struct MainConfig { | ||
| 31 | #[serde(default = "max_watch_history_default")] | ||
| 32 | pub max_watch_history: usize, | ||
| 33 | |||
| 34 | #[serde(default = "server_url_default")] | ||
| 35 | pub server_url: String, | ||
| 36 | |||
| 37 | #[serde(default = "display_thumbnails_default")] | ||
| 38 | pub display_thumbnails: bool, | ||
| 39 | |||
| 40 | #[serde(default = "env_default")] | ||
| 41 | pub env: HashMap<String, String>, | ||
| 42 | } | ||
| 43 | |||
| 44 | impl Default for MainConfig { | ||
| 45 | fn default() -> Self { | ||
| 46 | Self { | ||
| 47 | max_watch_history: max_watch_history_default(), | ||
| 48 | server_url: server_url_default(), | ||
| 49 | display_thumbnails: display_thumbnails_default(), | ||
| 50 | env: env_default(), | ||
| 51 | } | ||
| 52 | } | ||
| 53 | } | ||
| 54 | |||
| 55 | impl ConfigItem<'_> for MainConfig { | ||
| 56 | type Struct = MainConfig; | ||
| 57 | const FILE_NAME: &'static str = "main.yml"; | ||
| 58 | } | ||
src/app/config/mod.rs deleted −19
| @@ -1,19 +0,0 @@ | |||
| 1 | mod commands; | ||
| 2 | |||
| 3 | mod config; | ||
| 4 | pub use config::*; | ||
| 5 | |||
| 6 | mod main; | ||
| 7 | pub use main::*; | ||
| 8 | |||
| 9 | mod page_commands; | ||
| 10 | pub use page_commands::*; | ||
| 11 | |||
| 12 | mod keybindings; | ||
| 13 | pub use keybindings::*; | ||
| 14 | |||
| 15 | mod layouts; | ||
| 16 | pub use layouts::*; | ||
| 17 | |||
| 18 | mod colors; | ||
| 19 | pub use colors::*; | ||
src/app/config/page_commands.rs deleted −73
| @@ -1,73 +0,0 @@ | |||
| 1 | use std::collections::HashMap; | ||
| 2 | |||
| 3 | use serde::{Deserialize, Serialize}; | ||
| 4 | |||
| 5 | use crate::traits::ConfigItem; | ||
| 6 | |||
| 7 | #[derive(Clone, Serialize, Deserialize)] | ||
| 8 | pub struct PageCommandsConfig(pub HashMap<String, Vec<PageCommand>>); | ||
| 9 | |||
| 10 | impl PageCommandsConfig { | ||
| 11 | fn blank() -> Self { | ||
| 12 | Self(HashMap::default()) | ||
| 13 | } | ||
| 14 | } | ||
| 15 | |||
| 16 | impl Default for PageCommandsConfig { | ||
| 17 | fn default() -> Self { | ||
| 18 | let mut out = Self::blank(); | ||
| 19 | |||
| 20 | out.0.insert( | ||
| 21 | String::from("item_info:video"), | ||
| 22 | vec![ | ||
| 23 | PageCommand::from("Watch video", "video_player"), | ||
| 24 | PageCommand::from("Play audio", "audio_player"), | ||
| 25 | PageCommand::from("Play audio (loop)", "audio_loop"), | ||
| 26 | PageCommand::from("Download video", "video_downloader"), | ||
| 27 | PageCommand::from("Download audio", "audio_downloader"), | ||
| 28 | PageCommand::from("Visit channel", "{goto_channel}"), | ||
| 29 | PageCommand::from("{mode}", "{toggle_mode}"), | ||
| 30 | ], | ||
| 31 | ); | ||
| 32 | |||
| 33 | out.0.insert( | ||
| 34 | String::from("item_info:playlist"), | ||
| 35 | vec![ | ||
| 36 | PageCommand::from("Switch view", "{switch_view}"), | ||
| 37 | PageCommand::from("Watch all", "video_player"), | ||
| 38 | PageCommand::from("Play all audio", "audio_player"), | ||
| 39 | PageCommand::from("Shuffle play all audio", "audio_playlist_shuffle"), | ||
| 40 | PageCommand::from( | ||
| 41 | "Shuffle play all audio (loop)", | ||
| 42 | "audio_playlist_shuffle_loop", | ||
| 43 | ), | ||
| 44 | PageCommand::from("Download all video", "video_downloader"), | ||
| 45 | PageCommand::from("Download all audio", "audio_downloader"), | ||
| 46 | PageCommand::from("Visit channel", "{goto_channel}"), | ||
| 47 | PageCommand::from("{mode}", "{toggle_mode}"), | ||
| 48 | ], | ||
| 49 | ); | ||
| 50 | |||
| 51 | out | ||
| 52 | } | ||
| 53 | } | ||
| 54 | |||
| 55 | #[derive(Clone, Serialize, Deserialize)] | ||
| 56 | pub struct PageCommand { | ||
| 57 | pub label: String, | ||
| 58 | pub command: String, | ||
| 59 | } | ||
| 60 | |||
| 61 | impl PageCommand { | ||
| 62 | fn from(label: &str, command: &str) -> Self { | ||
| 63 | Self { | ||
| 64 | label: label.to_string(), | ||
| 65 | command: command.to_string(), | ||
| 66 | } | ||
| 67 | } | ||
| 68 | } | ||
| 69 | |||
| 70 | impl ConfigItem<'_> for PageCommandsConfig { | ||
| 71 | type Struct = PageCommandsConfig; | ||
| 72 | const FILE_NAME: &'static str = "page_commands.yml"; | ||
| 73 | } | ||
src/app/mod.rs deleted −3
| @@ -1,3 +0,0 @@ | |||
| 1 | pub mod app; | ||
| 2 | pub mod config; | ||
| 3 | pub mod pages; | ||
src/app/pages/channel.rs deleted −472
| @@ -1,472 +0,0 @@ | |||
| 1 | use std::{collections::LinkedList, error::Error}; | ||
| 2 | |||
| 3 | use crossterm::event::KeyEvent; | ||
| 4 | use serde::{Deserialize, Serialize}; | ||
| 5 | use tui::{ | ||
| 6 | backend::Backend, | ||
| 7 | layout::{Alignment, Rect}, | ||
| 8 | style::{Color, Style}, | ||
| 9 | widgets::{Block, BorderType, Borders, Paragraph}, | ||
| 10 | Frame, | ||
| 11 | }; | ||
| 12 | |||
| 13 | use crate::{ | ||
| 14 | app::{ | ||
| 15 | app::{App, AppNoState}, | ||
| 16 | config::{ | ||
| 17 | Action, ChannelItemTransitional, ConstraintTransitional, ItemTransitional, | ||
| 18 | LayoutConfig, RowItemTransitional, RowTransitional, | ||
| 19 | }, | ||
| 20 | }, | ||
| 21 | functions::download_all_thumbnails, | ||
| 22 | structs::{FullChannel, Item, ListItem, MiniPlayList, MiniVideo, Page, WatchHistory}, | ||
| 23 | traits::{ItemTrait, PageTrait}, | ||
| 24 | widgets::{horizontal_split::HorizontalSplit, item_display::ItemDisplay, text_list::TextList}, | ||
| 25 | }; | ||
| 26 | |||
| 27 | use super::{global::GlobalItem, item_info::DisplayItem}; | ||
| 28 | |||
| 29 | #[derive(Debug, Clone, Copy, PartialEq, Serialize, Deserialize)] | ||
| 30 | pub enum ChannelPage { | ||
| 31 | Home, | ||
| 32 | Playlists, | ||
| 33 | Videos, | ||
| 34 | } | ||
| 35 | |||
| 36 | #[derive(Debug, Clone)] | ||
| 37 | pub enum ChannelItem { | ||
| 38 | InfoDisplay(ChannelDisplayItem), | ||
| 39 | SelectItems(ChannelPage), | ||
| 40 | } | ||
| 41 | |||
| 42 | #[derive(Debug, Clone)] | ||
| 43 | pub enum ChannelDisplayItem { | ||
| 44 | Playlists(Vec<MiniPlayList>, TextList), | ||
| 45 | Videos(Vec<MiniVideo>, TextList), | ||
| 46 | Home(FullChannel), | ||
| 47 | Unknown, | ||
| 48 | } | ||
| 49 | |||
| 50 | impl ItemTrait for ChannelItem { | ||
| 51 | fn load_item(&self, app: &App, _: &mut WatchHistory) -> Result<Item, Box<dyn Error>> { | ||
| 52 | let mut this = self.clone(); | ||
| 53 | |||
| 54 | if let Page::Channel(channel_page, id) = &app.page { | ||
| 55 | if let ChannelItem::InfoDisplay(displayitem) = &mut this { | ||
| 56 | match channel_page { | ||
| 57 | ChannelPage::Home => { | ||
| 58 | let channel = app.client.channel(id, None)?; | ||
| 59 | let mut linked_list = LinkedList::new(); | ||
| 60 | linked_list.push_back(( | ||
| 61 | channel.authorThumbnails[4].url.clone(), | ||
| 62 | channel.authorId.clone(), | ||
| 63 | )); | ||
| 64 | if app.config.main.display_thumbnails { | ||
| 65 | let _ = download_all_thumbnails(linked_list); | ||
| 66 | } | ||
| 67 | |||
| 68 | *displayitem = ChannelDisplayItem::Home(channel.into()); | ||
| 69 | } | ||
| 70 | ChannelPage::Playlists => { | ||
| 71 | let mut textlist = TextList::default(); | ||
| 72 | let playlists = app | ||
| 73 | .client | ||
| 74 | .channel_playlists(id, None)? | ||
| 75 | .playlists | ||
| 76 | .into_iter() | ||
| 77 | .map(|item| { | ||
| 78 | textlist.items.push(item.title.clone()); | ||
| 79 | item.into() | ||
| 80 | }) | ||
| 81 | .collect::<Vec<MiniPlayList>>(); | ||
| 82 | |||
| 83 | let mut linked_list = LinkedList::new(); | ||
| 84 | for item in playlists.iter() { | ||
| 85 | if let Some(thumbnail) = &item.thumbnail { | ||
| 86 | linked_list | ||
| 87 | .push_back((thumbnail.clone(), item.playlist_id.clone())); | ||
| 88 | } | ||
| 89 | } | ||
| 90 | if app.config.main.display_thumbnails { | ||
| 91 | let _ = download_all_thumbnails(linked_list); | ||
| 92 | } | ||
| 93 | |||
| 94 | *displayitem = ChannelDisplayItem::Playlists(playlists, textlist); | ||
| 95 | } | ||
| 96 | |||
| 97 | ChannelPage::Videos => { | ||
| 98 | let mut textlist = TextList::default(); | ||
| 99 | let videos = app | ||
| 100 | .client | ||
| 101 | .channel_videos(id, None)? | ||
| 102 | .videos | ||
| 103 | .into_iter() | ||
| 104 | .map(|item| { | ||
| 105 | textlist.items.push(item.title.clone()); | ||
| 106 | item.into() | ||
| 107 | }) | ||
| 108 | .collect::<Vec<MiniVideo>>(); | ||
| 109 | |||
| 110 | let mut linked_list = LinkedList::new(); | ||
| 111 | for item in videos.iter() { | ||
| 112 | linked_list | ||
| 113 | .push_back((item.video_thumbnail.clone(), item.video_id.clone())); | ||
| 114 | } | ||
| 115 | |||
| 116 | if app.config.main.display_thumbnails { | ||
| 117 | let _ = download_all_thumbnails(linked_list); | ||
| 118 | } | ||
| 119 | *displayitem = ChannelDisplayItem::Videos(videos, textlist); | ||
| 120 | } | ||
| 121 | } | ||
| 122 | } | ||
| 123 | } | ||
| 124 | |||
| 125 | Ok(Item::Channel(this)) | ||
| 126 | } | ||
| 127 | |||
| 128 | fn render_item<B: Backend>( | ||
| 129 | &mut self, | ||
| 130 | frame: &mut Frame<B>, | ||
| 131 | rect: Rect, | ||
| 132 | app: AppNoState, | ||
| 133 | selected: bool, | ||
| 134 | hover: bool, | ||
| 135 | popup_focus: bool, | ||
| 136 | popup_render: bool, | ||
| 137 | ) -> (bool, AppNoState) { | ||
| 138 | let mut out = (false, app); | ||
| 139 | |||
| 140 | let mut style = Style::default().fg(if selected { | ||
| 141 | Color::LightBlue | ||
| 142 | } else if hover { | ||
| 143 | Color::LightRed | ||
| 144 | } else { | ||
| 145 | Color::Reset | ||
| 146 | }); | ||
| 147 | |||
| 148 | match self { | ||
| 149 | ChannelItem::InfoDisplay(displayitem) => match displayitem { | ||
| 150 | ChannelDisplayItem::Unknown => { | ||
| 151 | let block = Block::default() | ||
| 152 | .border_type(BorderType::Rounded) | ||
| 153 | .borders(Borders::ALL) | ||
| 154 | .border_style(style); | ||
| 155 | |||
| 156 | frame.render_widget(block, rect); | ||
| 157 | } | ||
| 158 | ChannelDisplayItem::Home(channel) => { | ||
| 159 | let block = Block::default() | ||
| 160 | .border_type(BorderType::Rounded) | ||
| 161 | .borders(Borders::ALL) | ||
| 162 | .border_style(style); | ||
| 163 | |||
| 164 | let inner = block.inner(rect); | ||
| 165 | frame.render_widget(block, rect); | ||
| 166 | if !popup_render { | ||
| 167 | frame.render_widget( | ||
| 168 | ItemDisplay { | ||
| 169 | item: ListItem::FullChannel(channel.clone()), | ||
| 170 | render_image: !popup_focus, | ||
| 171 | }, | ||
| 172 | inner, | ||
| 173 | ); | ||
| 174 | } | ||
| 175 | } | ||
| 176 | ChannelDisplayItem::Videos(videos, textlist) => { | ||
| 177 | let split = HorizontalSplit::default() | ||
| 178 | .percentages(vec![60, 40]) | ||
| 179 | .border_style(Style::default().fg(if selected { | ||
| 180 | Color::LightBlue | ||
| 181 | } else if hover { | ||
| 182 | Color::LightRed | ||
| 183 | } else { | ||
| 184 | Color::Reset | ||
| 185 | })); | ||
| 186 | |||
| 187 | let chunks = split.inner(rect); | ||
| 188 | |||
| 189 | frame.render_widget(split, rect); | ||
| 190 | |||
| 191 | match &mut textlist.area { | ||
| 192 | Some(area) if *area != chunks[0] => { | ||
| 193 | *area = chunks[0]; | ||
| 194 | out.0 = true; | ||
| 195 | } | ||
| 196 | None => { | ||
| 197 | textlist.area = Some(chunks[0]); | ||
| 198 | out.0 = true; | ||
| 199 | } | ||
| 200 | |||
| 201 | _ => {} | ||
| 202 | }; | ||
| 203 | |||
| 204 | textlist.area(chunks[0]); | ||
| 205 | |||
| 206 | let mut textlist = textlist.clone(); | ||
| 207 | |||
| 208 | if selected { | ||
| 209 | textlist.selected_style(Style::default().fg(Color::LightRed)); | ||
| 210 | } else { | ||
| 211 | textlist.selected_style(Style::default().fg(Color::LightYellow)); | ||
| 212 | } | ||
| 213 | |||
| 214 | if let Some(item) = videos.iter().nth(textlist.selected) { | ||
| 215 | if !popup_render { | ||
| 216 | frame.render_widget( | ||
| 217 | ItemDisplay { | ||
| 218 | item: ListItem::MiniVideo(item.clone()), | ||
| 219 | render_image: !popup_focus, | ||
| 220 | }, | ||
| 221 | chunks[1], | ||
| 222 | ); | ||
| 223 | } | ||
| 224 | } | ||
| 225 | |||
| 226 | frame.render_widget(textlist, chunks[0]); | ||
| 227 | } | ||
| 228 | ChannelDisplayItem::Playlists(playlists, textlist) => { | ||
| 229 | let split = HorizontalSplit::default() | ||
| 230 | .percentages(vec![60, 40]) | ||
| 231 | .border_style(Style::default().fg(if selected { | ||
| 232 | Color::LightBlue | ||
| 233 | } else if hover { | ||
| 234 | Color::LightRed | ||
| 235 | } else { | ||
| 236 | Color::Reset | ||
| 237 | })); | ||
| 238 | |||
| 239 | let chunks = split.inner(rect); | ||
| 240 | |||
| 241 | frame.render_widget(split, rect); | ||
| 242 | |||
| 243 | textlist.area(chunks[0]); | ||
| 244 | |||
| 245 | let mut textlist = textlist.clone(); | ||
| 246 | |||
| 247 | if selected { | ||
| 248 | textlist.selected_style(Style::default().fg(Color::LightRed)); | ||
| 249 | } else { | ||
| 250 | textlist.selected_style(Style::default().fg(Color::LightYellow)); | ||
| 251 | } | ||
| 252 | |||
| 253 | if let Some(item) = playlists.iter().nth(textlist.selected) { | ||
| 254 | if !popup_focus { | ||
| 255 | frame.render_widget( | ||
| 256 | ItemDisplay { | ||
| 257 | item: ListItem::MiniPlayList(item.clone()), | ||
| 258 | render_image: !popup_focus, | ||
| 259 | }, | ||
| 260 | chunks[1], | ||
| 261 | ); | ||
| 262 | } | ||
| 263 | } | ||
| 264 | |||
| 265 | frame.render_widget(textlist, chunks[0]); | ||
| 266 | } | ||
| 267 | }, | ||
| 268 | ChannelItem::SelectItems(selected_page) => { | ||
| 269 | if !hover { | ||
| 270 | if let Page::Channel(channel_page, _) = &out.1.page { | ||
| 271 | if *selected_page == *channel_page { | ||
| 272 | style = style.fg(Color::LightYellow); | ||
| 273 | } | ||
| 274 | } | ||
| 275 | } | ||
| 276 | |||
| 277 | let block = Block::default() | ||
| 278 | .border_type(BorderType::Rounded) | ||
| 279 | .borders(Borders::ALL) | ||
| 280 | .border_style(style); | ||
| 281 | let paragraph = Paragraph::new(format!("{:?}", selected_page)) | ||
| 282 | .block(block) | ||
| 283 | .alignment(Alignment::Center); | ||
| 284 | |||
| 285 | frame.render_widget(paragraph, rect); | ||
| 286 | } | ||
| 287 | } | ||
| 288 | out | ||
| 289 | } | ||
| 290 | |||
| 291 | fn key_input(&mut self, key: KeyEvent, app: App) -> (bool, App) { | ||
| 292 | let action = match app.config.keybindings.0.get(&key) { | ||
| 293 | Some(action) => action, | ||
| 294 | None => return (false, app), | ||
| 295 | }; | ||
| 296 | |||
| 297 | match self { | ||
| 298 | ChannelItem::InfoDisplay(displayitem) => match displayitem { | ||
| 299 | ChannelDisplayItem::Videos(videos, textlist) => match action { | ||
| 300 | Action::Up => { | ||
| 301 | textlist.up(); | ||
| 302 | } | ||
| 303 | Action::Down => { | ||
| 304 | textlist.down(); | ||
| 305 | } | ||
| 306 | Action::FirstItem => textlist.first(), | ||
| 307 | Action::LastItem => textlist.last(), | ||
| 308 | Action::Select => { | ||
| 309 | let state = app.config.layouts.item_info.clone().into(); | ||
| 310 | let mut history = app.history.clone(); | ||
| 311 | history.push(app.into()); | ||
| 312 | |||
| 313 | return ( | ||
| 314 | false, | ||
| 315 | App { | ||
| 316 | history, | ||
| 317 | page: Page::ItemDisplay(DisplayItem::Video( | ||
| 318 | videos[textlist.selected].video_id.clone(), | ||
| 319 | )), | ||
| 320 | selectable: App::selectable(&state), | ||
| 321 | state, | ||
| 322 | ..Default::default() | ||
| 323 | }, | ||
| 324 | ); | ||
| 325 | } | ||
| 326 | _ => {} | ||
| 327 | }, | ||
| 328 | |||
| 329 | ChannelDisplayItem::Playlists(playlists, textlist) => match action { | ||
| 330 | Action::Up => { | ||
| 331 | textlist.up(); | ||
| 332 | } | ||
| 333 | Action::Down => { | ||
| 334 | textlist.down(); | ||
| 335 | } | ||
| 336 | Action::FirstItem => textlist.first(), | ||
| 337 | Action::LastItem => textlist.last(), | ||
| 338 | Action::Select => { | ||
| 339 | let state = app.config.layouts.item_info.clone().into(); | ||
| 340 | let mut history = app.history.clone(); | ||
| 341 | history.push(app.into()); | ||
| 342 | |||
| 343 | return ( | ||
| 344 | false, | ||
| 345 | App { | ||
| 346 | history, | ||
| 347 | page: Page::ItemDisplay(DisplayItem::PlayList( | ||
| 348 | playlists[textlist.selected].playlist_id.clone(), | ||
| 349 | )), | ||
| 350 | selectable: App::selectable(&state), | ||
| 351 | state, | ||
| 352 | ..Default::default() | ||
| 353 | }, | ||
| 354 | ); | ||
| 355 | } | ||
| 356 | _ => {} | ||
| 357 | }, | ||
| 358 | |||
| 359 | ChannelDisplayItem::Home(_) => {}, | ||
| 360 | _ => unreachable!(), | ||
| 361 | }, | ||
| 362 | _ => { | ||
| 363 | unreachable!() | ||
| 364 | } | ||
| 365 | } | ||
| 366 | |||
| 367 | (true, app) | ||
| 368 | } | ||
| 369 | |||
| 370 | fn select(&mut self, app: App) -> (App, bool) { | ||
| 371 | let cloned = self.clone(); | ||
| 372 | match &cloned { | ||
| 373 | ChannelItem::InfoDisplay(_) => (app, true), | ||
| 374 | ChannelItem::SelectItems(tab) => { | ||
| 375 | if let Page::Channel(channel_page, id) = &app.page.clone() { | ||
| 376 | if *tab == *channel_page { | ||
| 377 | return (app, false); | ||
| 378 | } | ||
| 379 | |||
| 380 | let state = app.config.layouts.channel.clone().into(); | ||
| 381 | let mut history = app.history.clone(); | ||
| 382 | history.push(app.into()); | ||
| 383 | |||
| 384 | return ( | ||
| 385 | App { | ||
| 386 | history, | ||
| 387 | page: Page::Channel(tab.clone(), id.clone()), | ||
| 388 | selectable: App::selectable(&state), | ||
| 389 | state, | ||
| 390 | ..Default::default() | ||
| 391 | }, | ||
| 392 | false, | ||
| 393 | ); | ||
| 394 | } else { | ||
| 395 | (app, false) | ||
| 396 | } | ||
| 397 | } | ||
| 398 | } | ||
| 399 | } | ||
| 400 | |||
| 401 | fn selectable(&self) -> bool { | ||
| 402 | true | ||
| 403 | } | ||
| 404 | } | ||
| 405 | |||
| 406 | pub struct Channel; | ||
| 407 | |||
| 408 | impl PageTrait for Channel { | ||
| 409 | fn default() -> LayoutConfig { | ||
| 410 | LayoutConfig { | ||
| 411 | layout: vec![ | ||
| 412 | RowTransitional { | ||
| 413 | items: vec![ | ||
| 414 | RowItemTransitional { | ||
| 415 | item: ItemTransitional::Global(GlobalItem::SearchBar), | ||
| 416 | constraint: ConstraintTransitional::Min(16), | ||
| 417 | }, | ||
| 418 | RowItemTransitional { | ||
| 419 | item: ItemTransitional::Global(GlobalItem::SearchSettings), | ||
| 420 | constraint: ConstraintTransitional::Length(5), | ||
| 421 | }, | ||
| 422 | ], | ||
| 423 | centered: false, | ||
| 424 | height: ConstraintTransitional::Length(3), | ||
| 425 | }, | ||
| 426 | RowTransitional { | ||
| 427 | items: vec![ | ||
| 428 | RowItemTransitional { | ||
| 429 | item: ItemTransitional::Channel(ChannelItemTransitional::SelectItems( | ||
| 430 | ChannelPage::Home, | ||
| 431 | )), | ||
| 432 | constraint: ConstraintTransitional::Length(15), | ||
| 433 | }, | ||
| 434 | RowItemTransitional { | ||
| 435 | item: ItemTransitional::Channel(ChannelItemTransitional::SelectItems( | ||
| 436 | ChannelPage::Videos, | ||
| 437 | )), | ||
| 438 | constraint: ConstraintTransitional::Length(15), | ||
| 439 | }, | ||
| 440 | RowItemTransitional { | ||
| 441 | item: ItemTransitional::Channel(ChannelItemTransitional::SelectItems( | ||
| 442 | ChannelPage::Playlists, | ||
| 443 | )), | ||
| 444 | constraint: ConstraintTransitional::Length(15), | ||
| 445 | }, | ||
| 446 | ], | ||
| 447 | centered: true, | ||
| 448 | height: ConstraintTransitional::Length(3), | ||
| 449 | }, | ||
| 450 | RowTransitional { | ||
| 451 | items: vec![RowItemTransitional { | ||
| 452 | item: ItemTransitional::Channel(ChannelItemTransitional::InfoDisplay), | ||
| 453 | constraint: ConstraintTransitional::Percentage(100), | ||
| 454 | }], | ||
| 455 | centered: false, | ||
| 456 | height: ConstraintTransitional::Min(6), | ||
| 457 | }, | ||
| 458 | RowTransitional { | ||
| 459 | items: vec![RowItemTransitional { | ||
| 460 | item: ItemTransitional::Global(GlobalItem::MessageBar), | ||
| 461 | constraint: ConstraintTransitional::Percentage(100), | ||
| 462 | }], | ||
| 463 | centered: false, | ||
| 464 | height: ConstraintTransitional::Length(3), | ||
| 465 | }, | ||
| 466 | ], | ||
| 467 | min: (46, 15), | ||
| 468 | message: String::from("Loading channel info..."), | ||
| 469 | def_selected: None, | ||
| 470 | } | ||
| 471 | } | ||
| 472 | } | ||
src/app/pages/global.rs deleted −285
| @@ -1,285 +0,0 @@ | |||
| 1 | use std::fmt; | ||
| 2 | |||
| 3 | use crossterm::event::{KeyCode, KeyEvent}; | ||
| 4 | use serde::{Deserialize, Serialize}; | ||
| 5 | use tui::{ | ||
| 6 | backend::Backend, | ||
| 7 | layout::{Alignment, Rect}, | ||
| 8 | style::{Color, Style}, | ||
| 9 | widgets::{Block, BorderType, Borders, Paragraph, Clear}, | ||
| 10 | Frame, | ||
| 11 | }; | ||
| 12 | |||
| 13 | use crate::{ | ||
| 14 | app::app::{App, AppNoState}, | ||
| 15 | functions::center_rect, | ||
| 16 | structs::{Item, Page, WatchHistory, MessageText}, | ||
| 17 | traits::ItemTrait, | ||
| 18 | widgets::{ horizontal_split::HorizontalSplit}, | ||
| 19 | }; | ||
| 20 | |||
| 21 | #[derive(Debug, Clone, Serialize, Deserialize)] | ||
| 22 | pub enum GlobalItem { | ||
| 23 | SearchBar, | ||
| 24 | SearchSettings, | ||
| 25 | MessageBar, | ||
| 26 | } | ||
| 27 | |||
| 28 | #[derive(Debug, Clone, Copy, PartialEq)] | ||
| 29 | pub enum Mode { | ||
| 30 | Youtube, | ||
| 31 | Invidious, | ||
| 32 | } | ||
| 33 | |||
| 34 | impl fmt::Display for Mode { | ||
| 35 | fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { | ||
| 36 | match self { | ||
| 37 | Mode::Youtube => write!(f, "Youtube"), | ||
| 38 | Mode::Invidious => write!(f, "Invidious"), | ||
| 39 | } | ||
| 40 | } | ||
| 41 | } | ||
| 42 | |||
| 43 | impl Mode { | ||
| 44 | pub fn toggle(&mut self) { | ||
| 45 | match self { | ||
| 46 | Mode::Youtube => *self = Mode::Invidious, | ||
| 47 | Mode::Invidious => *self = Mode::Youtube, | ||
| 48 | } | ||
| 49 | } | ||
| 50 | } | ||
| 51 | |||
| 52 | impl ItemTrait for GlobalItem { | ||
| 53 | fn select(&mut self, mut app: App) -> (App, bool) { | ||
| 54 | let selected = match self { | ||
| 55 | GlobalItem::SearchBar => true, | ||
| 56 | GlobalItem::SearchSettings => { | ||
| 57 | app.popup_focus = true; | ||
| 58 | app.term_clear = true; | ||
| 59 | true | ||
| 60 | } | ||
| 61 | GlobalItem::MessageBar => unreachable!() | ||
| 62 | }; | ||
| 63 | |||
| 64 | (app, selected) | ||
| 65 | } | ||
| 66 | |||
| 67 | fn selectable(&self) -> bool { | ||
| 68 | match self { | ||
| 69 | GlobalItem::SearchBar | GlobalItem::SearchSettings => true, | ||
| 70 | _ => false, | ||
| 71 | } | ||
| 72 | } | ||
| 73 | |||
| 74 | fn key_input(&mut self, key: KeyEvent, mut app: App) -> (bool, App) { | ||
| 75 | match self { | ||
| 76 | GlobalItem::SearchBar => match key.code { | ||
| 77 | KeyCode::Char(c) => { | ||
| 78 | app.render = true; | ||
| 79 | app.search_text.insert(app.search_index, c); | ||
| 80 | app.search_index += 1; | ||
| 81 | } | ||
| 82 | KeyCode::Backspace => { | ||
| 83 | if app.search_index != 0 && app.search_text.len() != 0 { | ||
| 84 | app.render = true; | ||
| 85 | app.search_text = format!( | ||
| 86 | "{}{}", | ||
| 87 | &app.search_text[0..app.search_index - 1], | ||
| 88 | &app.search_text[app.search_index..app.search_text.len()] | ||
| 89 | ); | ||
| 90 | app.search_index -= 1; | ||
| 91 | }; | ||
| 92 | } | ||
| 93 | KeyCode::Left => { | ||
| 94 | if app.search_index > 0 { | ||
| 95 | app.render = true; | ||
| 96 | app.search_index -= 1; | ||
| 97 | } | ||
| 98 | } | ||
| 99 | KeyCode::Right => { | ||
| 100 | if app.search_index < app.search_text.len() { | ||
| 101 | app.render = true; | ||
| 102 | app.search_index += 1; | ||
| 103 | } | ||
| 104 | } | ||
| 105 | KeyCode::Enter => { | ||
| 106 | app.render = true; | ||
| 107 | if app.search_text.len() == 0 { | ||
| 108 | app.message = MessageText::Text(String::from("Search term cannot be empty")); | ||
| 109 | } else { | ||
| 110 | let state = app.config.layouts.search.clone().into(); | ||
| 111 | let mut history = app.history.clone(); | ||
| 112 | let search_text = app.search_text.clone(); | ||
| 113 | let search_index = app.search_index; | ||
| 114 | let search_settings = app.search_settings.clone(); | ||
| 115 | history.push(app.into()); | ||
| 116 | |||
| 117 | return ( | ||
| 118 | false, | ||
| 119 | App { | ||
| 120 | history, | ||
| 121 | page: Page::Search, | ||
| 122 | selectable: App::selectable(&state), | ||
| 123 | state, | ||
| 124 | search_text, | ||
| 125 | search_index, | ||
| 126 | search_settings, | ||
| 127 | load: true, | ||
| 128 | ..Default::default() | ||
| 129 | }, | ||
| 130 | ); | ||
| 131 | } | ||
| 132 | } | ||
| 133 | _ => {} | ||
| 134 | }, | ||
| 135 | GlobalItem::SearchSettings => { | ||
| 136 | app.search_settings.key_input(key, &app.config); | ||
| 137 | } | ||
| 138 | _ => {} | ||
| 139 | } | ||
| 140 | |||
| 141 | (true, app) | ||
| 142 | } | ||
| 143 | |||
| 144 | fn render_item<B: Backend>( | ||
| 145 | &mut self, | ||
| 146 | frame: &mut Frame<B>, | ||
| 147 | rect: Rect, | ||
| 148 | app: AppNoState, | ||
| 149 | selected: bool, | ||
| 150 | hover: bool, | ||
| 151 | _: bool, | ||
| 152 | popup_render: bool, | ||
| 153 | ) -> (bool, AppNoState) { | ||
| 154 | let area = frame.size(); | ||
| 155 | let mut out = (false, app); | ||
| 156 | match self { | ||
| 157 | GlobalItem::SearchBar => { | ||
| 158 | let block = Block::default() | ||
| 159 | .border_type(BorderType::Rounded) | ||
| 160 | .borders(Borders::ALL) | ||
| 161 | .border_style(tui::style::Style::default().fg(if selected { | ||
| 162 | Color::LightBlue | ||
| 163 | } else if hover { | ||
| 164 | Color::LightRed | ||
| 165 | } else { | ||
| 166 | Color::Reset | ||
| 167 | })) | ||
| 168 | .title("Search YouTube") | ||
| 169 | .title_alignment(Alignment::Center); | ||
| 170 | let mut text = out.1.search_text.clone(); | ||
| 171 | if selected { | ||
| 172 | text.push(' '); | ||
| 173 | text.replace_range(out.1.search_index..out.1.search_index + 1, "█"); | ||
| 174 | // text = format!("{}█{}", &text[0..out.1.search_index], &text[out.1.search_index+1..text.len()]); | ||
| 175 | } | ||
| 176 | let paragraph = Paragraph::new(text).block(block); | ||
| 177 | frame.render_widget(paragraph, rect); | ||
| 178 | } | ||
| 179 | GlobalItem::MessageBar => { | ||
| 180 | let message = out.1.message.clone(); | ||
| 181 | let block = Block::default() | ||
| 182 | .border_type(BorderType::Rounded) | ||
| 183 | .borders(Borders::ALL) | ||
| 184 | .border_style(Style::default().fg(if message.is_some() { | ||
| 185 | Color::LightRed | ||
| 186 | } else { | ||
| 187 | Color::Reset | ||
| 188 | })); | ||
| 189 | let paragraph = | ||
| 190 | Paragraph::new(message.clone().to_string()) | ||
| 191 | .block(block); | ||
| 192 | frame.render_widget(paragraph, rect); | ||
| 193 | } | ||
| 194 | GlobalItem::SearchSettings => { | ||
| 195 | let block = Block::default() | ||
| 196 | .border_type(BorderType::Rounded) | ||
| 197 | .borders(Borders::ALL) | ||
| 198 | .border_style(Style::default().fg(if selected { | ||
| 199 | Color::LightYellow | ||
| 200 | } else if hover { | ||
| 201 | Color::LightRed | ||
| 202 | } else { | ||
| 203 | Color::Reset | ||
| 204 | })); | ||
| 205 | let paragraph = Paragraph::new(String::from("...")).block(block); | ||
| 206 | frame.render_widget(paragraph, rect); | ||
| 207 | |||
| 208 | if selected { | ||
| 209 | if popup_render { | ||
| 210 | match center_rect((area.width * 70 / 100, area.height * 70 / 100), area) { | ||
| 211 | Ok(rect) => { | ||
| 212 | let split = HorizontalSplit::default() | ||
| 213 | .percentages(vec![40, 60]) | ||
| 214 | .border_style(Style::default().fg(if selected { | ||
| 215 | Color::LightBlue | ||
| 216 | } else if hover { | ||
| 217 | Color::LightRed | ||
| 218 | } else { | ||
| 219 | Color::Reset | ||
| 220 | })); | ||
| 221 | let chunks = split.inner(rect); | ||
| 222 | |||
| 223 | frame.render_widget(split, rect); | ||
| 224 | |||
| 225 | out.1.search_settings.text_list.area(chunks[0]); | ||
| 226 | |||
| 227 | if out.1.search_settings.row { | ||
| 228 | out.1 | ||
| 229 | .search_settings | ||
| 230 | .text_list | ||
| 231 | .selected_style(Style::default().fg(Color::LightRed)); | ||
| 232 | |||
| 233 | out.1 | ||
| 234 | .search_settings | ||
| 235 | .select_text_list | ||
| 236 | .selected_style(Style::default().fg(Color::LightYellow)); | ||
| 237 | } else { | ||
| 238 | out.1 | ||
| 239 | .search_settings | ||
| 240 | .text_list | ||
| 241 | .selected_style(Style::default().fg(Color::LightYellow)); | ||
| 242 | |||
| 243 | out.1 | ||
| 244 | .search_settings | ||
| 245 | .select_text_list | ||
| 246 | .selected_style(Style::default().fg(Color::LightRed)); | ||
| 247 | } | ||
| 248 | |||
| 249 | frame.render_widget(Clear, chunks[0]); | ||
| 250 | frame.render_widget(Clear, chunks[1]); | ||
| 251 | |||
| 252 | frame.render_widget( | ||
| 253 | out.1.search_settings.text_list.clone(), | ||
| 254 | chunks[0], | ||
| 255 | ); | ||
| 256 | |||
| 257 | out.1.search_settings.select_text_list.area(chunks[1]); | ||
| 258 | |||
| 259 | frame.render_widget( | ||
| 260 | out.1.search_settings.select_text_list.clone(), | ||
| 261 | chunks[1], | ||
| 262 | ); | ||
| 263 | |||
| 264 | } | ||
| 265 | Err(_) => { | ||
| 266 | out.1.message = MessageText::Text(String::from("Screen too small")); | ||
| 267 | } | ||
| 268 | } | ||
| 269 | //panic!("{:?}", rect); | ||
| 270 | } else { | ||
| 271 | out.0 = true; | ||
| 272 | } | ||
| 273 | } | ||
| 274 | } | ||
| 275 | } | ||
| 276 | |||
| 277 | out | ||
| 278 | } | ||
| 279 | |||
| 280 | fn load_item(&self, _: &App, _: &mut WatchHistory) -> Result<Item, Box<dyn std::error::Error>> { | ||
| 281 | Ok(Item::Global(self.clone())) | ||
| 282 | } | ||
| 283 | } | ||
| 284 | |||
| 285 | impl GlobalItem {} | ||
src/app/pages/item_info.rs deleted −545
| @@ -1,545 +0,0 @@ | |||
| 1 | use std::{collections::LinkedList, error::Error}; | ||
| 2 | |||
| 3 | use crate::{ | ||
| 4 | app::{ | ||
| 5 | app::{App, AppNoState}, | ||
| 6 | config::{ | ||
| 7 | Action, ConstraintTransitional, ItemTransitional, LayoutConfig, PageCommand, | ||
| 8 | RowItemTransitional, RowTransitional, | ||
| 9 | }, | ||
| 10 | pages::{channel::*, global::*}, | ||
| 11 | }, | ||
| 12 | functions::download_all_thumbnails, | ||
| 13 | structs::{FullPlayList, FullVideo, Item, ListItem, Page, WatchHistory, MessageText}, | ||
| 14 | traits::{ItemTrait, PageTrait}, | ||
| 15 | widgets::{horizontal_split::HorizontalSplit, item_display::ItemDisplay, text_list::TextList}, | ||
| 16 | }; | ||
| 17 | use crossterm::event::KeyEvent; | ||
| 18 | use tui::{ | ||
| 19 | backend::Backend, | ||
| 20 | layout::Rect, | ||
| 21 | style::{Color, Style}, | ||
| 22 | Frame, | ||
| 23 | }; | ||
| 24 | |||
| 25 | use super::global::GlobalItem; | ||
| 26 | |||
| 27 | #[derive(Clone)] | ||
| 28 | pub enum ItemInfoItem { | ||
| 29 | Unknown, | ||
| 30 | Video(VideoItemInfo), | ||
| 31 | PlayList(PlayListItemInfo), | ||
| 32 | } | ||
| 33 | |||
| 34 | #[derive(Clone)] | ||
| 35 | pub struct VideoItemInfo { | ||
| 36 | video: FullVideo, | ||
| 37 | list: TextList, | ||
| 38 | mode: Mode, | ||
| 39 | commands: Vec<PageCommand>, | ||
| 40 | } | ||
| 41 | |||
| 42 | #[derive(Clone)] | ||
| 43 | pub struct PlayListItemInfo { | ||
| 44 | playlist: FullPlayList, | ||
| 45 | video_view_list: TextList, | ||
| 46 | playlist_view_list: TextList, | ||
| 47 | display_view: PlayListDisplayView, | ||
| 48 | mode: Mode, | ||
| 49 | commands: Vec<PageCommand>, | ||
| 50 | } | ||
| 51 | |||
| 52 | #[derive(Clone, Copy)] | ||
| 53 | pub enum PlayListDisplayView { | ||
| 54 | VideoList, | ||
| 55 | PlayListView, | ||
| 56 | } | ||
| 57 | |||
| 58 | impl PlayListDisplayView { | ||
| 59 | pub fn toggle(self) -> Self { | ||
| 60 | match self { | ||
| 61 | PlayListDisplayView::VideoList => PlayListDisplayView::PlayListView, | ||
| 62 | PlayListDisplayView::PlayListView => PlayListDisplayView::VideoList, | ||
| 63 | } | ||
| 64 | } | ||
| 65 | } | ||
| 66 | |||
| 67 | impl ItemTrait for ItemInfoItem { | ||
| 68 | fn reset(&mut self) { | ||
| 69 | // panic!("Got here!"); | ||
| 70 | *self = Self::Unknown; | ||
| 71 | } | ||
| 72 | fn select(&mut self, app: App) -> (App, bool) { | ||
| 73 | let selected = true; | ||
| 74 | |||
| 75 | (app, selected) | ||
| 76 | } | ||
| 77 | |||
| 78 | fn selectable(&self) -> bool { | ||
| 79 | true | ||
| 80 | } | ||
| 81 | |||
| 82 | fn key_input(&mut self, key: KeyEvent, mut app: App) -> (bool, App) { | ||
| 83 | let action = match app.config.keybindings.0.get(&key) { | ||
| 84 | Some(action) => *action, | ||
| 85 | None => return (false, app), | ||
| 86 | }; | ||
| 87 | match self { | ||
| 88 | ItemInfoItem::Video(videoinfo) => match action { | ||
| 89 | Action::Up => videoinfo.list.up(), | ||
| 90 | Action::Down => videoinfo.list.down(), | ||
| 91 | Action::FirstItem => videoinfo.list.first(), | ||
| 92 | Action::LastItem => videoinfo.list.last(), | ||
| 93 | Action::Select => { | ||
| 94 | let command = &videoinfo.commands[videoinfo.list.selected]; | ||
| 95 | |||
| 96 | match command.command.as_str() { | ||
| 97 | "{toggle_mode}" => videoinfo.mode.toggle(), | ||
| 98 | "{goto_channel}" => { | ||
| 99 | let state = app.config.layouts.channel.clone().into(); | ||
| 100 | let mut history = app.history.clone(); | ||
| 101 | history.push(app.into()); | ||
| 102 | |||
| 103 | return ( | ||
| 104 | false, | ||
| 105 | App { | ||
| 106 | history, | ||
| 107 | page: Page::Channel( | ||
| 108 | ChannelPage::Home, | ||
| 109 | videoinfo.video.channel_id.clone(), | ||
| 110 | ), | ||
| 111 | selectable: App::selectable(&state), | ||
| 112 | state, | ||
| 113 | ..Default::default() | ||
| 114 | }, | ||
| 115 | ); | ||
| 116 | } | ||
| 117 | _ => { | ||
| 118 | match app.config.commands.0.get(&command.command) { | ||
| 119 | Some(command) => { | ||
| 120 | let mut env = app.config.main.env.clone(); | ||
| 121 | |||
| 122 | env.insert( | ||
| 123 | String::from("embed_url"), | ||
| 124 | format!( | ||
| 125 | "{}/embed/{}", | ||
| 126 | match videoinfo.mode { | ||
| 127 | Mode::Invidious => app.client.server.as_str(), | ||
| 128 | Mode::Youtube => "https://youtube.com", | ||
| 129 | }, | ||
| 130 | videoinfo.video.video_id | ||
| 131 | ), | ||
| 132 | ); | ||
| 133 | |||
| 134 | match command.run_command(&env) { | ||
| 135 | Some(e) => { | ||
| 136 | app.message = MessageText::Text(format!("Unknown variable `{}`", e)) | ||
| 137 | } | ||
| 138 | None => app.message = MessageText::Text(command.message.clone()), | ||
| 139 | } | ||
| 140 | } | ||
| 141 | None => { | ||
| 142 | app.message = | ||
| 143 | MessageText::Text(format!("Unkown command `{}`", &command.command)); | ||
| 144 | } | ||
| 145 | }; | ||
| 146 | } | ||
| 147 | }; | ||
| 148 | } | ||
| 149 | _ => {} | ||
| 150 | }, | ||
| 151 | |||
| 152 | ItemInfoItem::PlayList(playlistinfo) => match playlistinfo.display_view { | ||
| 153 | PlayListDisplayView::PlayListView => match action { | ||
| 154 | Action::Up => playlistinfo.playlist_view_list.up(), | ||
| 155 | Action::Down => playlistinfo.playlist_view_list.down(), | ||
| 156 | Action::FirstItem => playlistinfo.playlist_view_list.first(), | ||
| 157 | Action::LastItem => playlistinfo.playlist_view_list.last(), | ||
| 158 | Action::Select => { | ||
| 159 | let command = | ||
| 160 | &playlistinfo.commands[playlistinfo.playlist_view_list.selected]; | ||
| 161 | |||
| 162 | match command.command.as_str() { | ||
| 163 | "{toggle_mode}" => playlistinfo.mode.toggle(), | ||
| 164 | "{goto_channel}" => { | ||
| 165 | let state = app.config.layouts.channel.clone().into(); | ||
| 166 | let mut history = app.history.clone(); | ||
| 167 | history.push(app.into()); | ||
| 168 | |||
| 169 | return ( | ||
| 170 | false, | ||
| 171 | App { | ||
| 172 | history, | ||
| 173 | page: Page::Channel( | ||
| 174 | ChannelPage::Home, | ||
| 175 | playlistinfo.playlist.playlist_id.clone(), | ||
| 176 | ), | ||
| 177 | selectable: App::selectable(&state), | ||
| 178 | state, | ||
| 179 | ..Default::default() | ||
| 180 | }, | ||
| 181 | ); | ||
| 182 | } | ||
| 183 | |||
| 184 | "{switch_view}" => { | ||
| 185 | playlistinfo.display_view = playlistinfo.display_view.toggle() | ||
| 186 | } | ||
| 187 | _ => { | ||
| 188 | match app.config.commands.0.get(&command.command) { | ||
| 189 | Some(command) => { | ||
| 190 | let mut env = app.config.main.env.clone(); | ||
| 191 | |||
| 192 | env.insert( | ||
| 193 | String::from("embed_url"), | ||
| 194 | format!( | ||
| 195 | "{}/playlist?list={}", | ||
| 196 | match playlistinfo.mode { | ||
| 197 | Mode::Invidious => app.client.server.as_str(), | ||
| 198 | Mode::Youtube => "https://youtube.com", | ||
| 199 | }, | ||
| 200 | playlistinfo.playlist.playlist_id | ||
| 201 | ), | ||
| 202 | ); | ||
| 203 | |||
| 204 | match command.run_command(&env) { | ||
| 205 | Some(e) => { | ||
| 206 | app.message = | ||
| 207 | MessageText::Text(format!("Unknown variable `{}`", e)) | ||
| 208 | } | ||
| 209 | None => app.message = MessageText::Text(command.message.clone()), | ||
| 210 | } | ||
| 211 | } | ||
| 212 | None => { | ||
| 213 | app.message = | ||
| 214 | MessageText::Text(format!("Unkown command `{}`", &command.command)); | ||
| 215 | } | ||
| 216 | }; | ||
| 217 | } | ||
| 218 | }; | ||
| 219 | } | ||
| 220 | |||
| 221 | _ => {} | ||
| 222 | }, | ||
| 223 | PlayListDisplayView::VideoList => match action { | ||
| 224 | Action::Up => playlistinfo.video_view_list.up(), | ||
| 225 | Action::Down => playlistinfo.video_view_list.down(), | ||
| 226 | Action::FirstItem => playlistinfo.video_view_list.first(), | ||
| 227 | Action::LastItem => playlistinfo.video_view_list.last(), | ||
| 228 | Action::Select => match playlistinfo.video_view_list.selected { | ||
| 229 | 0 => { | ||
| 230 | playlistinfo.display_view = playlistinfo.display_view.toggle(); | ||
| 231 | } | ||
| 232 | |||
| 233 | x => { | ||
| 234 | let state = app.config.layouts.item_info.clone().into(); | ||
| 235 | let mut history = app.history.clone(); | ||
| 236 | history.push(app.into()); | ||
| 237 | |||
| 238 | return ( | ||
| 239 | false, | ||
| 240 | App { | ||
| 241 | history, | ||
| 242 | page: Page::ItemDisplay(DisplayItem::Video( | ||
| 243 | playlistinfo.playlist.videos[x - 1].video_id.clone(), | ||
| 244 | )), | ||
| 245 | selectable: App::selectable(&state), | ||
| 246 | state, | ||
| 247 | ..Default::default() | ||
| 248 | }, | ||
| 249 | ); | ||
| 250 | } | ||
| 251 | }, | ||
| 252 | |||
| 253 | _ => {} | ||
| 254 | }, | ||
| 255 | }, | ||
| 256 | _ => {} | ||
| 257 | } | ||
| 258 | |||
| 259 | (true, app) | ||
| 260 | } | ||
| 261 | |||
| 262 | fn load_item( | ||
| 263 | &self, | ||
| 264 | app: &App, | ||
| 265 | watch_history: &mut WatchHistory, | ||
| 266 | ) -> Result<Item, Box<dyn Error>> { | ||
| 267 | let mut this = self.clone(); | ||
| 268 | |||
| 269 | if let ItemInfoItem::Unknown = this { | ||
| 270 | match &app.page { | ||
| 271 | Page::ItemDisplay(display_item) => match display_item { | ||
| 272 | DisplayItem::Video(id) => { | ||
| 273 | // panic!("Got here"); | ||
| 274 | let mut list = TextList::default(); | ||
| 275 | let video: FullVideo = app.client.video(id, None)?.into(); | ||
| 276 | if app.config.main.display_thumbnails { | ||
| 277 | let _ = download_all_thumbnails(LinkedList::from([( | ||
| 278 | video.video_thumbnail.clone(), | ||
| 279 | video.video_id.clone(), | ||
| 280 | )])); | ||
| 281 | } | ||
| 282 | let commands = app | ||
| 283 | .config | ||
| 284 | .page_commands | ||
| 285 | .0 | ||
| 286 | .get("item_info:video") | ||
| 287 | .unwrap_or(&Vec::new()) | ||
| 288 | .clone(); | ||
| 289 | list.items(commands.iter().map(|item| item.label.to_string()).collect()); | ||
| 290 | |||
| 291 | let iteminfo = VideoItemInfo { | ||
| 292 | video, | ||
| 293 | list, | ||
| 294 | mode: Mode::Youtube, | ||
| 295 | commands, | ||
| 296 | }; | ||
| 297 | |||
| 298 | watch_history.push( | ||
| 299 | iteminfo.video.video_id.clone(), | ||
| 300 | ListItem::FullVideo(iteminfo.video.clone()), | ||
| 301 | &app.config, | ||
| 302 | ); | ||
| 303 | |||
| 304 | this = ItemInfoItem::Video(iteminfo); | ||
| 305 | } | ||
| 306 | |||
| 307 | DisplayItem::PlayList(id) => { | ||
| 308 | let mut videos_text_list = TextList::default(); | ||
| 309 | let mut playlist_text_list = TextList::default(); | ||
| 310 | let playlist: FullPlayList = app.client.playlist(id, None)?.into(); | ||
| 311 | if app.config.main.display_thumbnails { | ||
| 312 | let _ = download_all_thumbnails( | ||
| 313 | playlist | ||
| 314 | .videos | ||
| 315 | .iter() | ||
| 316 | .map(|v| (v.video_thumbnail.clone(), v.video_id.clone())) | ||
| 317 | .collect(), | ||
| 318 | ); | ||
| 319 | } | ||
| 320 | |||
| 321 | videos_text_list.items = vec![String::from("Swtich view")]; | ||
| 322 | videos_text_list | ||
| 323 | .items | ||
| 324 | .extend(playlist.videos.iter().map(|v| v.title.clone())); | ||
| 325 | |||
| 326 | let commands = app | ||
| 327 | .config | ||
| 328 | .page_commands | ||
| 329 | .0 | ||
| 330 | .get("item_info:playlist") | ||
| 331 | .unwrap_or(&Vec::new()) | ||
| 332 | .clone(); | ||
| 333 | playlist_text_list | ||
| 334 | .items(commands.iter().map(|item| item.label.to_string()).collect()); | ||
| 335 | |||
| 336 | let iteminfo = PlayListItemInfo { | ||
| 337 | playlist: playlist, | ||
| 338 | video_view_list: videos_text_list, | ||
| 339 | playlist_view_list: playlist_text_list, | ||
| 340 | mode: Mode::Youtube, | ||
| 341 | display_view: PlayListDisplayView::PlayListView, | ||
| 342 | commands, | ||
| 343 | }; | ||
| 344 | |||
| 345 | watch_history.push( | ||
| 346 | iteminfo.playlist.playlist_id.clone(), | ||
| 347 | ListItem::FullPlayList(iteminfo.playlist.clone()), | ||
| 348 | &app.config, | ||
| 349 | ); | ||
| 350 | |||
| 351 | this = ItemInfoItem::PlayList(iteminfo); | ||
| 352 | } | ||
| 353 | }, | ||
| 354 | |||
| 355 | _ => {} | ||
| 356 | } | ||
| 357 | } | ||
| 358 | Ok(Item::ItemInfo(this)) | ||
| 359 | } | ||
| 360 | |||
| 361 | fn render_item<B: Backend>( | ||
| 362 | &mut self, | ||
| 363 | frame: &mut Frame<B>, | ||
| 364 | rect: Rect, | ||
| 365 | app: AppNoState, | ||
| 366 | selected: bool, | ||
| 367 | hover: bool, | ||
| 368 | popup_focus: bool, | ||
| 369 | popup_render: bool, | ||
| 370 | ) -> (bool, AppNoState) { | ||
| 371 | let out = (false, app); | ||
| 372 | |||
| 373 | if popup_render { | ||
| 374 | return out; | ||
| 375 | } | ||
| 376 | |||
| 377 | match self { | ||
| 378 | ItemInfoItem::Video(videoinfo) => { | ||
| 379 | // list.items[videoinfo.list.items.len() - 1] = format!("Mode: {}", videoinfo.mode); | ||
| 380 | |||
| 381 | let split = HorizontalSplit::default() | ||
| 382 | .percentages(vec![40, 60]) | ||
| 383 | .border_style(Style::default().fg(if selected { | ||
| 384 | Color::LightBlue | ||
| 385 | } else if hover { | ||
| 386 | Color::LightRed | ||
| 387 | } else { | ||
| 388 | Color::Reset | ||
| 389 | })); | ||
| 390 | |||
| 391 | let chunks = split.inner(rect); | ||
| 392 | |||
| 393 | videoinfo.list.area(chunks[1]); | ||
| 394 | |||
| 395 | let mut list = videoinfo.list.clone(); | ||
| 396 | |||
| 397 | list.items.iter_mut().for_each(|item| match item.as_str() { | ||
| 398 | "{mode}" => *item = format!("Mode: {}", videoinfo.mode), | ||
| 399 | _ => {} | ||
| 400 | }); | ||
| 401 | if selected { | ||
| 402 | list.selected_style(Style::default().fg(Color::LightRed)); | ||
| 403 | } else { | ||
| 404 | list.selected_style(Style::default().fg(Color::LightYellow)); | ||
| 405 | } | ||
| 406 | |||
| 407 | frame.render_widget(split, rect); | ||
| 408 | |||
| 409 | if !popup_render { | ||
| 410 | let item_display = ItemDisplay { | ||
| 411 | item: ListItem::FullVideo(videoinfo.video.clone()), | ||
| 412 | render_image: !popup_focus, | ||
| 413 | }; | ||
| 414 | |||
| 415 | frame.render_widget(item_display, chunks[0]); | ||
| 416 | } | ||
| 417 | |||
| 418 | frame.render_widget(list, chunks[1]); | ||
| 419 | } | ||
| 420 | |||
| 421 | ItemInfoItem::PlayList(playlistinfo) => { | ||
| 422 | let split = HorizontalSplit::default() | ||
| 423 | .percentages(vec![40, 60]) | ||
| 424 | .border_style(Style::default().fg(if selected { | ||
| 425 | Color::LightBlue | ||
| 426 | } else if hover { | ||
| 427 | Color::LightRed | ||
| 428 | } else { | ||
| 429 | Color::Reset | ||
| 430 | })); | ||
| 431 | |||
| 432 | let chunks = split.inner(rect); | ||
| 433 | |||
| 434 | frame.render_widget(split, rect); | ||
| 435 | |||
| 436 | if !popup_render { | ||
| 437 | let item_display = ItemDisplay { | ||
| 438 | item: ListItem::FullPlayList(playlistinfo.playlist.clone()), | ||
| 439 | render_image: !popup_focus, | ||
| 440 | }; | ||
| 441 | |||
| 442 | frame.render_widget(item_display, chunks[0]); | ||
| 443 | } | ||
| 444 | |||
| 445 | match playlistinfo.display_view { | ||
| 446 | PlayListDisplayView::VideoList => { | ||
| 447 | playlistinfo.video_view_list.area(chunks[1]); | ||
| 448 | let mut list = playlistinfo.video_view_list.clone(); | ||
| 449 | list.area(chunks[1]); | ||
| 450 | if selected { | ||
| 451 | list.selected_style(Style::default().fg(Color::LightRed)); | ||
| 452 | } else { | ||
| 453 | list.selected_style(Style::default().fg(Color::LightYellow)); | ||
| 454 | } | ||
| 455 | |||
| 456 | frame.render_widget(list, chunks[1]); | ||
| 457 | } | ||
| 458 | PlayListDisplayView::PlayListView => { | ||
| 459 | playlistinfo.playlist_view_list.area(chunks[1]); | ||
| 460 | let mut list = playlistinfo.playlist_view_list.clone(); | ||
| 461 | |||
| 462 | list.items.iter_mut().for_each(|item| match item.as_str() { | ||
| 463 | "{mode}" => *item = format!("Mode: {}", playlistinfo.mode), | ||
| 464 | _ => {} | ||
| 465 | }); | ||
| 466 | |||
| 467 | list.area(chunks[1]); | ||
| 468 | |||
| 469 | if selected { | ||
| 470 | list.selected_style(Style::default().fg(Color::LightRed)); | ||
| 471 | } else { | ||
| 472 | list.selected_style(Style::default().fg(Color::LightYellow)); | ||
| 473 | } | ||
| 474 | |||
| 475 | frame.render_widget(list, chunks[1]); | ||
| 476 | } | ||
| 477 | } | ||
| 478 | } | ||
| 479 | |||
| 480 | ItemInfoItem::Unknown => { | ||
| 481 | let split = HorizontalSplit::default() | ||
| 482 | .percentages(vec![40, 60]) | ||
| 483 | .border_style(Style::default().fg(if selected { | ||
| 484 | Color::LightBlue | ||
| 485 | } else if hover { | ||
| 486 | Color::LightRed | ||
| 487 | } else { | ||
| 488 | Color::Reset | ||
| 489 | })); | ||
| 490 | |||
| 491 | frame.render_widget(split, rect); | ||
| 492 | } | ||
| 493 | } | ||
| 494 | out | ||
| 495 | } | ||
| 496 | } | ||
| 497 | |||
| 498 | #[derive(Debug, Clone, PartialEq)] | ||
| 499 | pub enum DisplayItem { | ||
| 500 | Video(String), | ||
| 501 | PlayList(String), | ||
| 502 | } | ||
| 503 | |||
| 504 | pub struct ItemInfo; | ||
| 505 | impl PageTrait for ItemInfo { | ||
| 506 | fn default() -> LayoutConfig { | ||
| 507 | LayoutConfig { | ||
| 508 | layout: vec![ | ||
| 509 | RowTransitional { | ||
| 510 | items: vec![ | ||
| 511 | RowItemTransitional { | ||
| 512 | item: ItemTransitional::Global(GlobalItem::SearchBar), | ||
| 513 | constraint: ConstraintTransitional::Min(16), | ||
| 514 | }, | ||
| 515 | RowItemTransitional { | ||
| 516 | item: ItemTransitional::Global(GlobalItem::SearchSettings), | ||
| 517 | constraint: ConstraintTransitional::Length(5), | ||
| 518 | }, | ||
| 519 | ], | ||
| 520 | centered: false, | ||
| 521 | height: ConstraintTransitional::Length(3), | ||
| 522 | }, | ||
| 523 | RowTransitional { | ||
| 524 | items: vec![RowItemTransitional { | ||
| 525 | item: ItemTransitional::ItemInfo, | ||
| 526 | constraint: ConstraintTransitional::Percentage(100), | ||
| 527 | }], | ||
| 528 | centered: false, | ||
| 529 | height: ConstraintTransitional::Min(6), | ||
| 530 | }, | ||
| 531 | RowTransitional { | ||
| 532 | items: vec![RowItemTransitional { | ||
| 533 | item: ItemTransitional::Global(GlobalItem::MessageBar), | ||
| 534 | constraint: ConstraintTransitional::Percentage(100), | ||
| 535 | }], | ||
| 536 | centered: false, | ||
| 537 | height: ConstraintTransitional::Length(3), | ||
| 538 | }, | ||
| 539 | ], | ||
| 540 | min: (21, 12), | ||
| 541 | message: String::from("Loading item info..."), | ||
| 542 | def_selected: Some((0,1)), | ||
| 543 | } | ||
| 544 | } | ||
| 545 | } | ||
src/app/pages/main_menu.rs deleted −393
| @@ -1,393 +0,0 @@ | |||
| 1 | use std::{collections::LinkedList, error::Error, fs}; | ||
| 2 | |||
| 3 | use crate::{ | ||
| 4 | app::{ | ||
| 5 | app::{App, AppNoState}, | ||
| 6 | config::{ | ||
| 7 | Action, ConstraintTransitional, ItemTransitional, LayoutConfig, | ||
| 8 | MainMenuItemTransitional, RowItemTransitional, RowTransitional, | ||
| 9 | }, | ||
| 10 | pages::{global::*, item_info::*}, | ||
| 11 | }, | ||
| 12 | functions::download_all_thumbnails, | ||
| 13 | structs::{Item, ListItem, Page, WatchHistory}, | ||
| 14 | traits::{ItemTrait, PageTrait}, | ||
| 15 | widgets::{horizontal_split::HorizontalSplit, item_display::ItemDisplay, text_list::TextList}, | ||
| 16 | }; | ||
| 17 | use crossterm::event::KeyEvent; | ||
| 18 | use serde::{Deserialize, Serialize}; | ||
| 19 | use tui::{ | ||
| 20 | backend::Backend, | ||
| 21 | layout::{Alignment, Rect}, | ||
| 22 | style::{Color, Style}, | ||
| 23 | widgets::{Block, BorderType, Borders, Paragraph}, | ||
| 24 | Frame, | ||
| 25 | }; | ||
| 26 | #[derive(Debug, Clone)] | ||
| 27 | pub enum MainMenuItem { | ||
| 28 | SeletorTab(MainMenuSelector), | ||
| 29 | VideoList(Option<(LinkedList<ListItem>, TextList, Option<usize>)>), // Videos, List, page | ||
| 30 | } | ||
| 31 | |||
| 32 | // app.client.trending(None) | ||
| 33 | |||
| 34 | impl ItemTrait for MainMenuItem { | ||
| 35 | fn load_item(&self, app: &App, _: &mut WatchHistory) -> Result<Item, Box<dyn Error>> { | ||
| 36 | let mut this = self.clone(); | ||
| 37 | |||
| 38 | match &mut this { | ||
| 39 | MainMenuItem::VideoList(enum_items) => match app.page { | ||
| 40 | Page::MainMenu(tab) => match tab { | ||
| 41 | MainMenuSelector::Trending => { | ||
| 42 | let list: LinkedList<ListItem> = app | ||
| 43 | .client | ||
| 44 | .trending(None)? | ||
| 45 | .videos | ||
| 46 | .into_iter() | ||
| 47 | .map(|t| ListItem::MiniVideo(t.into())) | ||
| 48 | .collect(); | ||
| 49 | |||
| 50 | if app.config.main.display_thumbnails { | ||
| 51 | let _ = download_all_thumbnails( | ||
| 52 | list.iter() | ||
| 53 | .map(|t| match t { | ||
| 54 | ListItem::MiniVideo(v) => { | ||
| 55 | (v.video_thumbnail.clone(), v.video_id.clone()) | ||
| 56 | } | ||
| 57 | _ => unreachable!(), | ||
| 58 | }) | ||
| 59 | .collect(), | ||
| 60 | ); | ||
| 61 | } | ||
| 62 | |||
| 63 | if let Some((video_list, text_list, _)) = enum_items { | ||
| 64 | *text_list = TextList::default(); | ||
| 65 | text_list.items(textlist_from_video_list(&list)); | ||
| 66 | |||
| 67 | *video_list = list; | ||
| 68 | } else { | ||
| 69 | let mut text_list = TextList::default(); | ||
| 70 | text_list.items(textlist_from_video_list(&list)); | ||
| 71 | *enum_items = Some((list, text_list, None)); | ||
| 72 | }; | ||
| 73 | } | ||
| 74 | |||
| 75 | MainMenuSelector::Popular => { | ||
| 76 | let list: LinkedList<ListItem> = app | ||
| 77 | .client | ||
| 78 | .popular(None)? | ||
| 79 | .items | ||
| 80 | .into_iter() | ||
| 81 | .map(|t| ListItem::MiniVideo(t.into())) | ||
| 82 | .collect(); | ||
| 83 | |||
| 84 | if app.config.main.display_thumbnails { | ||
| 85 | let _ = download_all_thumbnails( | ||
| 86 | list.iter() | ||
| 87 | .map(|t| match t { | ||
| 88 | ListItem::MiniVideo(v) => { | ||
| 89 | (v.video_thumbnail.clone(), v.video_id.clone()) | ||
| 90 | } | ||
| 91 | _ => unreachable!(), | ||
| 92 | }) | ||
| 93 | .collect(), | ||
| 94 | ); | ||
| 95 | } | ||
| 96 | |||
| 97 | let mut text_list = TextList::default(); | ||
| 98 | |||
| 99 | if let Some((video_list, text_list, _)) = enum_items { | ||
| 100 | *text_list = TextList::default(); | ||
| 101 | text_list.items(textlist_from_video_list(&list)); | ||
| 102 | |||
| 103 | *video_list = list; | ||
| 104 | } else { | ||
| 105 | text_list.items(textlist_from_video_list(&list)); | ||
| 106 | *enum_items = Some((list, text_list, None)); | ||
| 107 | }; | ||
| 108 | } | ||
| 109 | |||
| 110 | MainMenuSelector::History => { | ||
| 111 | let mut list = LinkedList::new(); | ||
| 112 | let mut text_list = TextList::default(); | ||
| 113 | |||
| 114 | app.watch_history.0.iter().for_each(|t| { | ||
| 115 | let file = fs::read_to_string( | ||
| 116 | home::home_dir() | ||
| 117 | .expect("Cannot get your home directory") | ||
| 118 | .join(".local/share/youtube-tui/watch_history/info") | ||
| 119 | .join(format!("{}.json", t.id())), | ||
| 120 | ); | ||
| 121 | |||
| 122 | if let Ok(file) = file { | ||
| 123 | let item: ListItem = serde_json::from_str(&file).unwrap(); | ||
| 124 | |||
| 125 | let title = item.to_string(); | ||
| 126 | |||
| 127 | list.push_back(item); | ||
| 128 | text_list.items.push(title); | ||
| 129 | } | ||
| 130 | }); | ||
| 131 | |||
| 132 | *enum_items = Some((list, text_list, None)); | ||
| 133 | } | ||
| 134 | }, | ||
| 135 | |||
| 136 | _ => {} | ||
| 137 | }, | ||
| 138 | _ => {} | ||
| 139 | } | ||
| 140 | |||
| 141 | Ok(Item::MainMenu(this)) | ||
| 142 | } | ||
| 143 | |||
| 144 | fn render_item<B: Backend>( | ||
| 145 | &mut self, | ||
| 146 | frame: &mut Frame<B>, | ||
| 147 | rect: Rect, | ||
| 148 | app: AppNoState, | ||
| 149 | selected: bool, | ||
| 150 | hover: bool, | ||
| 151 | popup_focus: bool, | ||
| 152 | popup_render: bool, | ||
| 153 | ) -> (bool, AppNoState) { | ||
| 154 | let out = (false, app); | ||
| 155 | |||
| 156 | if popup_render { | ||
| 157 | return out; | ||
| 158 | } | ||
| 159 | |||
| 160 | let mut style = Style::default().fg(if selected { | ||
| 161 | Color::LightBlue | ||
| 162 | } else if hover { | ||
| 163 | Color::LightRed | ||
| 164 | } else { | ||
| 165 | Color::Reset | ||
| 166 | }); | ||
| 167 | |||
| 168 | match self { | ||
| 169 | MainMenuItem::SeletorTab(selector) => { | ||
| 170 | if !hover && &out.1.page == &(Page::MainMenu(*selector)) { | ||
| 171 | style = style.fg(Color::LightYellow); | ||
| 172 | } | ||
| 173 | let text = match selector { | ||
| 174 | MainMenuSelector::Trending => "Trending", | ||
| 175 | MainMenuSelector::Popular => "Popular", | ||
| 176 | MainMenuSelector::History => "History", | ||
| 177 | }; | ||
| 178 | |||
| 179 | let block = Block::default() | ||
| 180 | .border_type(BorderType::Rounded) | ||
| 181 | .borders(Borders::ALL) | ||
| 182 | .border_style(style); | ||
| 183 | let paragraph = Paragraph::new(text) | ||
| 184 | .block(block) | ||
| 185 | .alignment(Alignment::Center); | ||
| 186 | |||
| 187 | frame.render_widget(paragraph, rect); | ||
| 188 | } | ||
| 189 | MainMenuItem::VideoList(data) => { | ||
| 190 | let split = HorizontalSplit::default() | ||
| 191 | .percentages(vec![60, 40]) | ||
| 192 | .border_style(Style::default().fg(if selected { | ||
| 193 | Color::LightBlue | ||
| 194 | } else if hover { | ||
| 195 | Color::LightRed | ||
| 196 | } else { | ||
| 197 | Color::Reset | ||
| 198 | })); | ||
| 199 | |||
| 200 | let chunks = split.inner(rect); | ||
| 201 | |||
| 202 | frame.render_widget(split, rect); | ||
| 203 | |||
| 204 | if let Some((videos, list, _)) = data { | ||
| 205 | if selected { | ||
| 206 | list.selected_style(Style::default().fg(Color::LightRed)); | ||
| 207 | } else { | ||
| 208 | list.selected_style(Style::default().fg(Color::LightYellow)); | ||
| 209 | } | ||
| 210 | |||
| 211 | if let Some(item) = videos.iter().nth(list.selected) { | ||
| 212 | if !popup_render { | ||
| 213 | frame.render_widget(ItemDisplay { item: item.clone(), render_image: !popup_focus }, chunks[1]); | ||
| 214 | } | ||
| 215 | } | ||
| 216 | |||
| 217 | list.area(chunks[0]); | ||
| 218 | |||
| 219 | let list = list.clone(); | ||
| 220 | |||
| 221 | frame.render_widget(list, chunks[0]); | ||
| 222 | } | ||
| 223 | } | ||
| 224 | } | ||
| 225 | out | ||
| 226 | } | ||
| 227 | |||
| 228 | fn reset(&mut self) { | ||
| 229 | if let Self::VideoList(something) = self { | ||
| 230 | *something = None; | ||
| 231 | } | ||
| 232 | } | ||
| 233 | |||
| 234 | fn select(&mut self, mut app: App) -> (App, bool) { | ||
| 235 | let selected = match self { | ||
| 236 | MainMenuItem::SeletorTab(selector) => { | ||
| 237 | if app.page == (Page::MainMenu(*selector)) { | ||
| 238 | return (app, false); | ||
| 239 | } | ||
| 240 | app.page = Page::MainMenu(*selector); | ||
| 241 | app.load = true; | ||
| 242 | false | ||
| 243 | } | ||
| 244 | |||
| 245 | _ => true, | ||
| 246 | }; | ||
| 247 | |||
| 248 | (app, selected) | ||
| 249 | } | ||
| 250 | |||
| 251 | fn selectable(&self) -> bool { | ||
| 252 | true | ||
| 253 | } | ||
| 254 | |||
| 255 | fn key_input(&mut self, key: KeyEvent, app: App) -> (bool, App) { | ||
| 256 | match self { | ||
| 257 | MainMenuItem::VideoList(Some((list, textlist, _))) => { | ||
| 258 | let action = match app.config.keybindings.0.get(&key) { | ||
| 259 | Some(action) => action, | ||
| 260 | None => return (false, app), | ||
| 261 | }; | ||
| 262 | match action { | ||
| 263 | Action::Up => textlist.up(), | ||
| 264 | Action::Down => textlist.down(), | ||
| 265 | Action::FirstItem => textlist.first(), | ||
| 266 | Action::LastItem => textlist.last(), | ||
| 267 | Action::Select => { | ||
| 268 | let state = app.config.layouts.item_info.clone().into(); | ||
| 269 | let mut history = app.history.clone(); | ||
| 270 | history.push(app.into()); | ||
| 271 | |||
| 272 | return ( | ||
| 273 | false, | ||
| 274 | App { | ||
| 275 | history, | ||
| 276 | page: Page::ItemDisplay( | ||
| 277 | match list.iter().nth(textlist.selected).unwrap() { | ||
| 278 | ListItem::FullVideo(item) => { | ||
| 279 | DisplayItem::Video(item.video_id.clone()) | ||
| 280 | } | ||
| 281 | ListItem::FullPlayList(item) => { | ||
| 282 | DisplayItem::PlayList(item.playlist_id.clone()) | ||
| 283 | } | ||
| 284 | ListItem::MiniPlayList(item) => { | ||
| 285 | DisplayItem::PlayList(item.playlist_id.clone()) | ||
| 286 | } | ||
| 287 | ListItem::MiniVideo(item) => { | ||
| 288 | DisplayItem::Video(item.video_id.clone()) | ||
| 289 | } | ||
| 290 | _ => unreachable!(), | ||
| 291 | }, | ||
| 292 | ), | ||
| 293 | selectable: App::selectable(&state), | ||
| 294 | state, | ||
| 295 | ..Default::default() | ||
| 296 | }, | ||
| 297 | ); | ||
| 298 | } | ||
| 299 | _ => {} | ||
| 300 | } | ||
| 301 | } | ||
| 302 | _ => {} | ||
| 303 | } | ||
| 304 | |||
| 305 | (true, app) | ||
| 306 | } | ||
| 307 | } | ||
| 308 | |||
| 309 | impl MainMenuItem {} | ||
| 310 | |||
| 311 | pub fn textlist_from_video_list(original: &LinkedList<ListItem>) -> Vec<String> { | ||
| 312 | original.iter().map(|item| item.to_string()).collect() | ||
| 313 | } | ||
| 314 | |||
| 315 | #[derive(Debug, Clone, Copy, PartialEq, Serialize, Deserialize)] | ||
| 316 | pub enum MainMenuSelector { | ||
| 317 | Trending, | ||
| 318 | Popular, | ||
| 319 | History, | ||
| 320 | } | ||
| 321 | |||
| 322 | impl Default for MainMenuSelector { | ||
| 323 | fn default() -> Self { | ||
| 324 | Self::Popular | ||
| 325 | } | ||
| 326 | } | ||
| 327 | |||
| 328 | pub struct MainMenu; | ||
| 329 | impl PageTrait for MainMenu { | ||
| 330 | fn default() -> LayoutConfig { | ||
| 331 | LayoutConfig { | ||
| 332 | layout: vec![ | ||
| 333 | RowTransitional { | ||
| 334 | items: vec![ | ||
| 335 | RowItemTransitional { | ||
| 336 | item: ItemTransitional::Global(GlobalItem::SearchBar), | ||
| 337 | constraint: ConstraintTransitional::Min(16), | ||
| 338 | }, | ||
| 339 | RowItemTransitional { | ||
| 340 | item: ItemTransitional::Global(GlobalItem::SearchSettings), | ||
| 341 | constraint: ConstraintTransitional::Length(5), | ||
| 342 | }, | ||
| 343 | ], | ||
| 344 | centered: false, | ||
| 345 | height: ConstraintTransitional::Length(3), | ||
| 346 | }, | ||
| 347 | RowTransitional { | ||
| 348 | items: vec![ | ||
| 349 | RowItemTransitional { | ||
| 350 | item: ItemTransitional::MainMenu( | ||
| 351 | MainMenuItemTransitional::SelectorTab(MainMenuSelector::Popular), | ||
| 352 | ), | ||
| 353 | constraint: ConstraintTransitional::Length(15), | ||
| 354 | }, | ||
| 355 | RowItemTransitional { | ||
| 356 | item: ItemTransitional::MainMenu( | ||
| 357 | MainMenuItemTransitional::SelectorTab(MainMenuSelector::Trending), | ||
| 358 | ), | ||
| 359 | constraint: ConstraintTransitional::Length(15), | ||
| 360 | }, | ||
| 361 | RowItemTransitional { | ||
| 362 | item: ItemTransitional::MainMenu( | ||
| 363 | MainMenuItemTransitional::SelectorTab(MainMenuSelector::History), | ||
| 364 | ), | ||
| 365 | constraint: ConstraintTransitional::Length(15), | ||
| 366 | }, | ||
| 367 | ], | ||
| 368 | centered: true, | ||
| 369 | height: ConstraintTransitional::Length(3), | ||
| 370 | }, | ||
| 371 | RowTransitional { | ||
| 372 | items: vec![RowItemTransitional { | ||
| 373 | item: ItemTransitional::MainMenu(MainMenuItemTransitional::VideoList), | ||
| 374 | constraint: ConstraintTransitional::Percentage(100), | ||
| 375 | }], | ||
| 376 | centered: false, | ||
| 377 | height: ConstraintTransitional::Min(6), | ||
| 378 | }, | ||
| 379 | RowTransitional { | ||
| 380 | items: vec![RowItemTransitional { | ||
| 381 | item: ItemTransitional::Global(GlobalItem::MessageBar), | ||
| 382 | constraint: ConstraintTransitional::Percentage(100), | ||
| 383 | }], | ||
| 384 | centered: false, | ||
| 385 | height: ConstraintTransitional::Length(3), | ||
| 386 | }, | ||
| 387 | ], | ||
| 388 | min: (45, 15), | ||
| 389 | message: String::from("Loading home page..."), | ||
| 390 | def_selected: None, | ||
| 391 | } | ||
| 392 | } | ||
| 393 | } | ||
src/app/pages/mod.rs deleted −5
| @@ -1,5 +0,0 @@ | |||
| 1 | pub mod channel; | ||
| 2 | pub mod global; | ||
| 3 | pub mod item_info; | ||
| 4 | pub mod main_menu; | ||
| 5 | pub mod search; | ||
src/app/pages/search.rs deleted −389
| @@ -1,389 +0,0 @@ | |||
| 1 | use std::{collections::LinkedList, error::Error}; | ||
| 2 | |||
| 3 | use crossterm::event::KeyEvent; | ||
| 4 | use invidious::structs::hidden::SearchItem as InvidiousSearchItem; | ||
| 5 | use tui::{ | ||
| 6 | backend::Backend, | ||
| 7 | layout::Rect, | ||
| 8 | style::{Color, Style}, | ||
| 9 | Frame, | ||
| 10 | }; | ||
| 11 | |||
| 12 | use crate::{ | ||
| 13 | app::{ | ||
| 14 | app::{App, AppNoState}, | ||
| 15 | config::{ | ||
| 16 | Action, ConstraintTransitional, ItemTransitional, LayoutConfig, RowItemTransitional, | ||
| 17 | RowTransitional, SearchItemTransitional, | ||
| 18 | }, | ||
| 19 | }, | ||
| 20 | functions::download_all_thumbnails, | ||
| 21 | structs::{Item, ListItem, MiniChannel, MiniPlayList, MiniVideo, Page, WatchHistory}, | ||
| 22 | traits::{ItemTrait, PageTrait}, | ||
| 23 | widgets::{horizontal_split::HorizontalSplit, item_display::ItemDisplay, text_list::TextList}, | ||
| 24 | }; | ||
| 25 | |||
| 26 | use super::{ | ||
| 27 | channel::ChannelPage, global::GlobalItem, item_info::DisplayItem, | ||
| 28 | main_menu::textlist_from_video_list, | ||
| 29 | }; | ||
| 30 | |||
| 31 | #[derive(Debug, Clone)] | ||
| 32 | pub enum SearchItem { | ||
| 33 | Search { | ||
| 34 | results: Option<LinkedList<ListItem>>, | ||
| 35 | text_list: TextList, | ||
| 36 | }, | ||
| 37 | } | ||
| 38 | |||
| 39 | impl ItemTrait for SearchItem { | ||
| 40 | fn select(&mut self, app: App) -> (App, bool) { | ||
| 41 | (app, true) | ||
| 42 | } | ||
| 43 | |||
| 44 | fn selectable(&self) -> bool { | ||
| 45 | true | ||
| 46 | } | ||
| 47 | |||
| 48 | fn key_input(&mut self, key: KeyEvent, app: App) -> (bool, App) { | ||
| 49 | let action = match app.config.keybindings.0.get(&key) { | ||
| 50 | Some(action) => action, | ||
| 51 | None => return (false, app), | ||
| 52 | }; | ||
| 53 | match self { | ||
| 54 | SearchItem::Search { results, text_list } => match action { | ||
| 55 | Action::Up => text_list.up(), | ||
| 56 | Action::Down => text_list.down(), | ||
| 57 | Action::FirstItem => text_list.first(), | ||
| 58 | Action::LastItem => text_list.last(), | ||
| 59 | Action::Select => { | ||
| 60 | if let Some(results_unwrapped) = results { | ||
| 61 | match results_unwrapped.iter().nth(text_list.selected).unwrap() { | ||
| 62 | ListItem::PageTurner(b) => { | ||
| 63 | let new_page_no; | ||
| 64 | if *b { | ||
| 65 | new_page_no = app.page_no + 1; | ||
| 66 | } else { | ||
| 67 | new_page_no = app.page_no - 1; | ||
| 68 | } | ||
| 69 | |||
| 70 | *results = None; | ||
| 71 | *text_list = TextList::default(); | ||
| 72 | |||
| 73 | let state = app.config.layouts.search.clone().into(); | ||
| 74 | let mut history = app.history.clone(); | ||
| 75 | let search_text = app.search_text.clone(); | ||
| 76 | let search_settings = app.search_settings.clone(); | ||
| 77 | history.push(app.into()); | ||
| 78 | |||
| 79 | return ( | ||
| 80 | false, | ||
| 81 | App { | ||
| 82 | history, | ||
| 83 | page: Page::Search, | ||
| 84 | selectable: App::selectable(&state), | ||
| 85 | state, | ||
| 86 | search_text, | ||
| 87 | search_settings, | ||
| 88 | load: true, | ||
| 89 | page_no: new_page_no, | ||
| 90 | ..Default::default() | ||
| 91 | }, | ||
| 92 | ); | ||
| 93 | } | ||
| 94 | |||
| 95 | ListItem::MiniVideo(video) => { | ||
| 96 | let state = app.config.layouts.item_info.clone().into(); | ||
| 97 | let mut history = app.history.clone(); | ||
| 98 | history.push(app.into()); | ||
| 99 | |||
| 100 | return ( | ||
| 101 | false, | ||
| 102 | App { | ||
| 103 | history, | ||
| 104 | page: Page::ItemDisplay(DisplayItem::Video( | ||
| 105 | video.video_id.clone(), | ||
| 106 | )), | ||
| 107 | selectable: App::selectable(&state), | ||
| 108 | state, | ||
| 109 | ..Default::default() | ||
| 110 | }, | ||
| 111 | ); | ||
| 112 | } | ||
| 113 | |||
| 114 | ListItem::MiniPlayList(playlist) => { | ||
| 115 | let state = app.config.layouts.item_info.clone().into(); | ||
| 116 | let mut history = app.history.clone(); | ||
| 117 | history.push(app.into()); | ||
| 118 | |||
| 119 | return ( | ||
| 120 | false, | ||
| 121 | App { | ||
| 122 | history, | ||
| 123 | page: Page::ItemDisplay(DisplayItem::PlayList( | ||
| 124 | playlist.playlist_id.clone(), | ||
| 125 | )), | ||
| 126 | selectable: App::selectable(&state), | ||
| 127 | state, | ||
| 128 | ..Default::default() | ||
| 129 | }, | ||
| 130 | ); | ||
| 131 | } | ||
| 132 | |||
| 133 | ListItem::MiniChannel(channel) => { | ||
| 134 | let state = app.config.layouts.channel.clone().into(); | ||
| 135 | let mut history = app.history.clone(); | ||
| 136 | history.push(app.into()); | ||
| 137 | |||
| 138 | return ( | ||
| 139 | false, | ||
| 140 | App { | ||
| 141 | history, | ||
| 142 | page: Page::Channel( | ||
| 143 | ChannelPage::Home, | ||
| 144 | channel.author_id.clone(), | ||
| 145 | ), | ||
| 146 | selectable: App::selectable(&state), | ||
| 147 | state, | ||
| 148 | ..Default::default() | ||
| 149 | }, | ||
| 150 | ); | ||
| 151 | } | ||
| 152 | |||
| 153 | _ => {} | ||
| 154 | } | ||
| 155 | } | ||
| 156 | } | ||
| 157 | _ => {} | ||
| 158 | }, | ||
| 159 | } | ||
| 160 | |||
| 161 | (true, app) | ||
| 162 | } | ||
| 163 | |||
| 164 | fn load_item(&self, app: &App, _: &mut WatchHistory) -> Result<Item, Box<dyn Error>> { | ||
| 165 | let mut this = self.clone(); | ||
| 166 | |||
| 167 | match &mut this { | ||
| 168 | SearchItem::Search { results, text_list } => { | ||
| 169 | // panic!("got here"); | ||
| 170 | |||
| 171 | let mut args = vec![app.search_text.clone()]; | ||
| 172 | args.extend(app.search_settings.clone().to_vec()); | ||
| 173 | |||
| 174 | let invidious_results = app | ||
| 175 | .client | ||
| 176 | .search(Some(&format!( | ||
| 177 | "page={}&q={}", | ||
| 178 | app.page_no, | ||
| 179 | args.join("&").as_str() | ||
| 180 | )))? | ||
| 181 | .items; | ||
| 182 | |||
| 183 | let mut items = LinkedList::new(); | ||
| 184 | |||
| 185 | for item in invidious_results { | ||
| 186 | match item { | ||
| 187 | InvidiousSearchItem::Video { | ||
| 188 | title: _, | ||
| 189 | videoId: _, | ||
| 190 | author: _, | ||
| 191 | authorId: _, | ||
| 192 | authorUrl: _, | ||
| 193 | lengthSeconds: _, | ||
| 194 | videoThumbnails: _, | ||
| 195 | description: _, | ||
| 196 | descriptionHtml: _, | ||
| 197 | viewCount: _, | ||
| 198 | published: _, | ||
| 199 | publishedText: _, | ||
| 200 | liveNow: _, | ||
| 201 | paid: _, | ||
| 202 | premium: _, | ||
| 203 | } => { | ||
| 204 | items.push_back(ListItem::MiniVideo(MiniVideo::from(item))); | ||
| 205 | } | ||
| 206 | |||
| 207 | InvidiousSearchItem::Playlist { | ||
| 208 | title: _, | ||
| 209 | playlistId: _, | ||
| 210 | author: _, | ||
| 211 | authorId: _, | ||
| 212 | authorUrl: _, | ||
| 213 | videoCount: _, | ||
| 214 | videos: _, | ||
| 215 | } => { | ||
| 216 | items.push_back(ListItem::MiniPlayList(MiniPlayList::from(item))); | ||
| 217 | } | ||
| 218 | |||
| 219 | InvidiousSearchItem::Channel { | ||
| 220 | author: _, | ||
| 221 | authorId: _, | ||
| 222 | authorUrl: _, | ||
| 223 | authorThumbnails: _, | ||
| 224 | subCount: _, | ||
| 225 | videoCount: _, | ||
| 226 | description: _, | ||
| 227 | descriptionHtml: _, | ||
| 228 | } => { | ||
| 229 | items.push_back(ListItem::MiniChannel(MiniChannel::from(item))); | ||
| 230 | } | ||
| 231 | |||
| 232 | _ => {} | ||
| 233 | } | ||
| 234 | } | ||
| 235 | |||
| 236 | let mut minimum_length = 0; | ||
| 237 | |||
| 238 | if app.page_no != 1 { | ||
| 239 | minimum_length += 1; | ||
| 240 | items.push_front(ListItem::PageTurner(false)); | ||
| 241 | } | ||
| 242 | |||
| 243 | if items.len() != minimum_length { | ||
| 244 | items.push_back(ListItem::PageTurner(true)); | ||
| 245 | } | ||
| 246 | |||
| 247 | text_list.items = textlist_from_video_list(&items); | ||
| 248 | |||
| 249 | let mut thumbnails = LinkedList::new(); | ||
| 250 | |||
| 251 | for item in items.iter() { | ||
| 252 | match item { | ||
| 253 | ListItem::MiniVideo(video) => { | ||
| 254 | thumbnails | ||
| 255 | .push_back((video.video_thumbnail.clone(), video.video_id.clone())); | ||
| 256 | } | ||
| 257 | |||
| 258 | ListItem::MiniPlayList(playlist) => { | ||
| 259 | if let Some(thumbnail) = &playlist.thumbnail { | ||
| 260 | thumbnails | ||
| 261 | .push_back((thumbnail.clone(), playlist.playlist_id.clone())); | ||
| 262 | } | ||
| 263 | } | ||
| 264 | |||
| 265 | ListItem::MiniChannel(channel) => { | ||
| 266 | thumbnails.push_back(( | ||
| 267 | format!("https:{}", channel.thumbnail.clone()), | ||
| 268 | channel.author_id.clone(), | ||
| 269 | )); | ||
| 270 | |||
| 271 | // panic!("{:?}", channel.thumbnail.clone()); | ||
| 272 | } | ||
| 273 | |||
| 274 | _ => {} | ||
| 275 | } | ||
| 276 | } | ||
| 277 | |||
| 278 | if app.config.main.display_thumbnails { | ||
| 279 | let _ = download_all_thumbnails(thumbnails); | ||
| 280 | } | ||
| 281 | |||
| 282 | *results = Some(items); | ||
| 283 | } | ||
| 284 | } | ||
| 285 | |||
| 286 | Ok(Item::Search(this)) | ||
| 287 | } | ||
| 288 | |||
| 289 | fn render_item<B: Backend>( | ||
| 290 | &mut self, | ||
| 291 | frame: &mut Frame<B>, | ||
| 292 | rect: Rect, | ||
| 293 | app: AppNoState, | ||
| 294 | selected: bool, | ||
| 295 | hover: bool, | ||
| 296 | popup_focus: bool, | ||
| 297 | popup_render: bool, | ||
| 298 | ) -> (bool, AppNoState) { | ||
| 299 | let out = (false, app); | ||
| 300 | |||
| 301 | if popup_render { | ||
| 302 | return out; | ||
| 303 | } | ||
| 304 | |||
| 305 | match self { | ||
| 306 | SearchItem::Search { results, text_list } => { | ||
| 307 | let split = HorizontalSplit::default() | ||
| 308 | .percentages(vec![60, 40]) | ||
| 309 | .border_style(Style::default().fg(if selected { | ||
| 310 | Color::LightBlue | ||
| 311 | } else if hover { | ||
| 312 | Color::LightRed | ||
| 313 | } else { | ||
| 314 | Color::Reset | ||
| 315 | })); | ||
| 316 | |||
| 317 | let chunks = split.inner(rect); | ||
| 318 | |||
| 319 | frame.render_widget(split, rect); | ||
| 320 | |||
| 321 | text_list.area(chunks[0]); | ||
| 322 | |||
| 323 | let mut text_list = text_list.clone(); | ||
| 324 | |||
| 325 | if let Some(result) = results { | ||
| 326 | if let Some(item) = result.iter().nth(text_list.selected) { | ||
| 327 | if !popup_render { | ||
| 328 | frame.render_widget(ItemDisplay { item: item.clone(), render_image: !popup_focus }, chunks[1]); | ||
| 329 | } | ||
| 330 | } | ||
| 331 | } | ||
| 332 | |||
| 333 | if selected { | ||
| 334 | text_list.selected_style(Style::default().fg(Color::LightRed)); | ||
| 335 | } else { | ||
| 336 | text_list.selected_style(Style::default().fg(Color::LightYellow)); | ||
| 337 | } | ||
| 338 | |||
| 339 | frame.render_widget(text_list, chunks[0]); | ||
| 340 | } | ||
| 341 | } | ||
| 342 | |||
| 343 | out | ||
| 344 | } | ||
| 345 | } | ||
| 346 | |||
| 347 | pub struct Search; | ||
| 348 | |||
| 349 | impl PageTrait for Search { | ||
| 350 | fn default() -> LayoutConfig { | ||
| 351 | LayoutConfig { | ||
| 352 | layout: vec![ | ||
| 353 | RowTransitional { | ||
| 354 | items: vec![ | ||
| 355 | RowItemTransitional { | ||
| 356 | item: ItemTransitional::Global(GlobalItem::SearchBar), | ||
| 357 | constraint: ConstraintTransitional::Min(16), | ||
| 358 | }, | ||
| 359 | RowItemTransitional { | ||
| 360 | item: ItemTransitional::Global(GlobalItem::SearchSettings), | ||
| 361 | constraint: ConstraintTransitional::Length(5), | ||
| 362 | }, | ||
| 363 | ], | ||
| 364 | centered: false, | ||
| 365 | height: ConstraintTransitional::Length(3), | ||
| 366 | }, | ||
| 367 | RowTransitional { | ||
| 368 | items: vec![RowItemTransitional { | ||
| 369 | item: ItemTransitional::Search(SearchItemTransitional::Search), | ||
| 370 | constraint: ConstraintTransitional::Percentage(100), | ||
| 371 | }], | ||
| 372 | centered: false, | ||
| 373 | height: ConstraintTransitional::Min(6), | ||
| 374 | }, | ||
| 375 | RowTransitional { | ||
| 376 | items: vec![RowItemTransitional { | ||
| 377 | item: ItemTransitional::Global(GlobalItem::MessageBar), | ||
| 378 | constraint: ConstraintTransitional::Percentage(100), | ||
| 379 | }], | ||
| 380 | centered: false, | ||
| 381 | height: ConstraintTransitional::Length(3), | ||
| 382 | }, | ||
| 383 | ], | ||
| 384 | min: (45, 12), | ||
| 385 | message: String::from("Loading search results..."), | ||
| 386 | def_selected: Some((0,1)), | ||
| 387 | } | ||
| 388 | } | ||
| 389 | } | ||
src/config/appearance.rs added +160
| @@ -0,0 +1,160 @@ | |||
| 1 | use super::{serde::BorderTypeSerde, ConfigTrait}; | ||
| 2 | use serde::{Deserialize, Serialize}; | ||
| 3 | use tui::{style::Color, widgets::BorderType}; | ||
| 4 | use typemap::Key; | ||
| 5 | |||
| 6 | #[derive(Default, Serialize, Deserialize, Clone)] | ||
| 7 | pub struct AppearanceConfigSerde { | ||
| 8 | #[serde(default)] | ||
| 9 | pub borders: BorderTypeSerde, | ||
| 10 | #[serde(default)] | ||
| 11 | pub colors: ColorsConfig, | ||
| 12 | } | ||
| 13 | |||
| 14 | #[derive(Clone)] | ||
| 15 | pub struct AppearanceConfig { | ||
| 16 | pub borders: BorderType, | ||
| 17 | pub colors: ColorsConfig, | ||
| 18 | } | ||
| 19 | |||
| 20 | #[derive(Clone, Copy, Serialize, Deserialize)] | ||
| 21 | pub struct ColorsConfig { | ||
| 22 | #[serde(default = "outline_default")] | ||
| 23 | pub outline: Color, | ||
| 24 | #[serde(default = "outline_selected_default")] | ||
| 25 | pub outline_selected: Color, | ||
| 26 | #[serde(default = "outline_hover_default")] | ||
| 27 | pub outline_hover: Color, | ||
| 28 | #[serde(default = "outline_secondary_default")] | ||
| 29 | pub outline_secondary: Color, | ||
| 30 | #[serde(default = "message_outline_default")] | ||
| 31 | pub message_outline: Color, | ||
| 32 | #[serde(default = "message_error_outline_default")] | ||
| 33 | pub message_error_outline: Color, | ||
| 34 | #[serde(default = "error_text_default")] | ||
| 35 | pub error_text: Color, | ||
| 36 | #[serde(default)] | ||
| 37 | pub item_info: ItemInfoColors, | ||
| 38 | } | ||
| 39 | |||
| 40 | #[derive(Clone, Copy, Serialize, Deserialize)] | ||
| 41 | pub struct ItemInfoColors { | ||
| 42 | #[serde(default = "tag_default")] | ||
| 43 | pub tag: Color, | ||
| 44 | #[serde(default = "title_default")] | ||
| 45 | pub title: Color, | ||
| 46 | #[serde(default = "description_default")] | ||
| 47 | pub description: Color, | ||
| 48 | #[serde(default = "author_default")] | ||
| 49 | pub author: Color, | ||
| 50 | #[serde(default = "viewcount_default")] | ||
| 51 | pub viewcount: Color, | ||
| 52 | #[serde(default = "length_default")] | ||
| 53 | pub length: Color, | ||
| 54 | #[serde(default = "published_default")] | ||
| 55 | pub published: Color, | ||
| 56 | } | ||
| 57 | |||
| 58 | impl Default for ColorsConfig { | ||
| 59 | fn default() -> Self { | ||
| 60 | Self { | ||
| 61 | outline: outline_default(), | ||
| 62 | outline_selected: outline_selected_default(), | ||
| 63 | outline_hover: outline_hover_default(), | ||
| 64 | outline_secondary: outline_secondary_default(), | ||
| 65 | message_outline: message_outline_default(), | ||
| 66 | message_error_outline: message_error_outline_default(), | ||
| 67 | error_text: error_text_default(), | ||
| 68 | item_info: ItemInfoColors::default(), | ||
| 69 | } | ||
| 70 | } | ||
| 71 | } | ||
| 72 | |||
| 73 | impl Default for ItemInfoColors { | ||
| 74 | fn default() -> Self { | ||
| 75 | Self { | ||
| 76 | tag: tag_default(), | ||
| 77 | title: title_default(), | ||
| 78 | description: description_default(), | ||
| 79 | author: author_default(), | ||
| 80 | viewcount: viewcount_default(), | ||
| 81 | length: length_default(), | ||
| 82 | published: published_default(), | ||
| 83 | } | ||
| 84 | } | ||
| 85 | } | ||
| 86 | |||
| 87 | impl From<AppearanceConfigSerde> for AppearanceConfig { | ||
| 88 | fn from(original: AppearanceConfigSerde) -> Self { | ||
| 89 | Self { | ||
| 90 | borders: original.borders.into(), | ||
| 91 | colors: original.colors, | ||
| 92 | } | ||
| 93 | } | ||
| 94 | } | ||
| 95 | |||
| 96 | impl ConfigTrait for AppearanceConfigSerde { | ||
| 97 | const LABEL: &'static str = "appearance"; | ||
| 98 | } | ||
| 99 | |||
| 100 | impl Key for AppearanceConfig { | ||
| 101 | type Value = Self; | ||
| 102 | } | ||
| 103 | |||
| 104 | // defaults | ||
| 105 | |||
| 106 | fn outline_default() -> Color { | ||
| 107 | Color::Reset | ||
| 108 | } | ||
| 109 | |||
| 110 | fn outline_selected_default() -> Color { | ||
| 111 | Color::LightBlue | ||
| 112 | } | ||
| 113 | |||
| 114 | fn outline_hover_default() -> Color { | ||
| 115 | Color::LightRed | ||
| 116 | } | ||
| 117 | |||
| 118 | fn outline_secondary_default() -> Color { | ||
| 119 | Color::LightYellow | ||
| 120 | } | ||
| 121 | |||
| 122 | fn message_outline_default() -> Color { | ||
| 123 | Color::Rgb(255, 127, 0) | ||
| 124 | } | ||
| 125 | |||
| 126 | fn message_error_outline_default() -> Color { | ||
| 127 | Color::LightRed | ||
| 128 | } | ||
| 129 | |||
| 130 | fn error_text_default() -> Color { | ||
| 131 | Color::LightRed | ||
| 132 | } | ||
| 133 | |||
| 134 | fn tag_default() -> Color { | ||
| 135 | Color::Gray | ||
| 136 | } | ||
| 137 | |||
| 138 | fn title_default() -> Color { | ||
| 139 | Color::LightBlue | ||
| 140 | } | ||
| 141 | |||
| 142 | fn description_default() -> Color { | ||
| 143 | Color::Gray | ||
| 144 | } | ||
| 145 | |||
| 146 | fn author_default() -> Color { | ||
| 147 | Color::LightGreen | ||
| 148 | } | ||
| 149 | |||
| 150 | fn viewcount_default() -> Color { | ||
| 151 | Color::LightYellow | ||
| 152 | } | ||
| 153 | |||
| 154 | fn length_default() -> Color { | ||
| 155 | Color::LightCyan | ||
| 156 | } | ||
| 157 | |||
| 158 | fn published_default() -> Color { | ||
| 159 | Color::LightMagenta | ||
| 160 | } | ||
src/config/configtrait.rs added +64
| @@ -0,0 +1,64 @@ | |||
| 1 | use serde::{de::DeserializeOwned, Serialize}; | ||
| 2 | use std::{ | ||
| 3 | error::Error, | ||
| 4 | fs::{self, OpenOptions}, | ||
| 5 | io::Write, | ||
| 6 | }; | ||
| 7 | |||
| 8 | pub const EXTENSION: &'static str = "yml"; | ||
| 9 | |||
| 10 | // Trait for loading, saving config files | ||
| 11 | pub trait ConfigTrait { | ||
| 12 | const LABEL: &'static str; | ||
| 13 | |||
| 14 | fn load() -> Result<Box<Self>, Box<dyn Error>> | ||
| 15 | where | ||
| 16 | Self: Serialize + DeserializeOwned + Default + Clone, | ||
| 17 | { | ||
| 18 | let mut config_path = home::home_dir().expect("cannot get home directory"); | ||
| 19 | config_path.push(".config"); | ||
| 20 | config_path.push("youtube-tui"); | ||
| 21 | config_path.push(format!("{}.{}", Self::LABEL, EXTENSION)); | ||
| 22 | |||
| 23 | // The config struct | ||
| 24 | let config: Self = { | ||
| 25 | || -> Result<Self, Box<dyn Error>> { | ||
| 26 | let content = match fs::read_to_string(&config_path) { | ||
| 27 | Ok(content) => content, | ||
| 28 | // If the config file does not exist returns Self::defult() | ||
| 29 | Err(_) => return Ok(Self::default()), | ||
| 30 | }; | ||
| 31 | |||
| 32 | match serde_yaml::from_str::<Self>(&content) { | ||
| 33 | Ok(config) => Ok(config), | ||
| 34 | // If there is error parsing the json file, create a backup with current time and returns | ||
| 35 | // Self::default() | ||
| 36 | Err(_) => { | ||
| 37 | let mut new_path = config_path.clone(); | ||
| 38 | new_path.pop(); | ||
| 39 | new_path.push(format!( | ||
| 40 | "{}-{}.{}", | ||
| 41 | Self::LABEL, | ||
| 42 | chrono::offset::Local::now(), | ||
| 43 | EXTENSION | ||
| 44 | )); | ||
| 45 | fs::rename(&config_path, &new_path)?; | ||
| 46 | Ok(Self::default()) | ||
| 47 | } | ||
| 48 | } | ||
| 49 | } | ||
| 50 | }()?; | ||
| 51 | |||
| 52 | // Overwrites the old config file with added options (if any), | ||
| 53 | // but it also removes things like comments in the old config file | ||
| 54 | let mut file = OpenOptions::new() | ||
| 55 | .write(true) | ||
| 56 | .create(true) | ||
| 57 | .truncate(true) | ||
| 58 | .open(&config_path)?; | ||
| 59 | |||
| 60 | file.write(serde_yaml::to_string(&config)?.as_bytes())?; | ||
| 61 | |||
| 62 | Ok(Box::new(config)) | ||
| 63 | } | ||
| 64 | } | ||
src/config/keybindings.rs added +57
| @@ -0,0 +1,57 @@ | |||
| 1 | use super::ConfigTrait; | ||
| 2 | use crate::global::keyaction::KeyAction; | ||
| 3 | use crossterm::event::KeyCode; | ||
| 4 | use serde::{Deserialize, Serialize}; | ||
| 5 | use std::collections::HashMap; | ||
| 6 | use typemap::Key; | ||
| 7 | |||
| 8 | // The outer HashMap<KeyCode, T> gets a value for whatever code is being pressed | ||
| 9 | // The inner HashMap<u8, KeyAction> gets the action using a u8 representing a key modifier | ||
| 10 | // The u8 for each modifier key can be found in https://docs.rs/crossterm/latest/src/crossterm/event.rs.html#587-603 | ||
| 11 | // The sum of u8 for each key modifier would mean having all of those modifiers at the same time | ||
| 12 | #[derive(Serialize, Deserialize, Clone)] | ||
| 13 | pub struct KeyBindingsConfig(pub HashMap<KeyCode, HashMap<u8, KeyAction>>); | ||
| 14 | |||
| 15 | impl ConfigTrait for KeyBindingsConfig { | ||
| 16 | const LABEL: &'static str = "keybindings"; | ||
| 17 | } | ||
| 18 | |||
| 19 | impl Key for KeyBindingsConfig { | ||
| 20 | type Value = Self; | ||
| 21 | } | ||
| 22 | |||
| 23 | impl Default for KeyBindingsConfig { | ||
| 24 | fn default() -> Self { | ||
| 25 | let mut map = HashMap::new(); | ||
| 26 | |||
| 27 | let mut left = HashMap::new(); | ||
| 28 | left.insert(0, KeyAction::MoveLeft); | ||
| 29 | map.insert(KeyCode::Left, left); | ||
| 30 | |||
| 31 | let mut right = HashMap::new(); | ||
| 32 | right.insert(0, KeyAction::MoveRight); | ||
| 33 | map.insert(KeyCode::Right, right); | ||
| 34 | |||
| 35 | let mut up = HashMap::new(); | ||
| 36 | up.insert(0, KeyAction::MoveUp); | ||
| 37 | map.insert(KeyCode::Up, up); | ||
| 38 | |||
| 39 | let mut down = HashMap::new(); | ||
| 40 | down.insert(0, KeyAction::MoveDown); | ||
| 41 | map.insert(KeyCode::Down, down); | ||
| 42 | |||
| 43 | let mut enter = HashMap::new(); | ||
| 44 | enter.insert(0, KeyAction::Select); | ||
| 45 | map.insert(KeyCode::Enter, enter); | ||
| 46 | |||
| 47 | let mut escape = HashMap::new(); | ||
| 48 | escape.insert(0, KeyAction::Deselect); | ||
| 49 | map.insert(KeyCode::Esc, escape); | ||
| 50 | |||
| 51 | let mut q = HashMap::new(); | ||
| 52 | q.insert(0, KeyAction::Exit); | ||
| 53 | map.insert(KeyCode::Char('q'), q); | ||
| 54 | |||
| 55 | Self(map) | ||
| 56 | } | ||
| 57 | } | ||
src/config/main.rs added +84
| @@ -0,0 +1,84 @@ | |||
| 1 | use super::ConfigTrait; | ||
| 2 | use serde::{Deserialize, Serialize}; | ||
| 3 | use std::collections::HashMap; | ||
| 4 | use typemap::Key; | ||
| 5 | |||
| 6 | #[derive(Serialize, Deserialize, Clone)] | ||
| 7 | pub struct MainConfig { | ||
| 8 | #[serde(default = "invidious_instance_default")] | ||
| 9 | pub invidious_instance: String, | ||
| 10 | #[serde(default = "allow_unicode_default")] | ||
| 11 | pub allow_unicode: bool, | ||
| 12 | #[serde(default = "message_bar_default_default")] | ||
| 13 | pub message_bar_default: String, | ||
| 14 | #[serde(default = "images_default")] | ||
| 15 | pub images: Images, | ||
| 16 | #[serde(default = "image_index_default")] | ||
| 17 | // The image to download from the array of images provided by the invidious api | ||
| 18 | // 0 is usually `maxres` and 3 (default) is good enough for normal uses without having huge files sizes | ||
| 19 | // Check `https://{any invidious instance}/api/v1/videos/{any valid video id}` property videoThumbnails in Firefox dev tools to see it for yourself | ||
| 20 | pub image_index: usize, | ||
| 21 | #[serde(default)] | ||
| 22 | pub env: HashMap<String, String>, | ||
| 23 | } | ||
| 24 | |||
| 25 | impl Key for MainConfig { | ||
| 26 | type Value = Self; | ||
| 27 | } | ||
| 28 | |||
| 29 | impl Default for MainConfig { | ||
| 30 | fn default() -> Self { | ||
| 31 | Self { | ||
| 32 | invidious_instance: invidious_instance_default(), | ||
| 33 | allow_unicode: allow_unicode_default(), | ||
| 34 | message_bar_default: message_bar_default_default(), | ||
| 35 | images: images_default(), | ||
| 36 | image_index: image_index_default(), | ||
| 37 | |||
| 38 | env: HashMap::default(), | ||
| 39 | } | ||
| 40 | } | ||
| 41 | } | ||
| 42 | |||
| 43 | impl ConfigTrait for MainConfig { | ||
| 44 | const LABEL: &'static str = "main"; | ||
| 45 | } | ||
| 46 | |||
| 47 | #[derive(Clone, Copy, Serialize, Deserialize, PartialEq, Eq)] | ||
| 48 | pub enum Images { | ||
| 49 | r#None, | ||
| 50 | HalfBlocks, | ||
| 51 | Sixels, | ||
| 52 | } | ||
| 53 | |||
| 54 | impl Images { | ||
| 55 | pub fn display(&self) -> bool { | ||
| 56 | !(self == &Self::None) | ||
| 57 | } | ||
| 58 | |||
| 59 | pub fn use_sixels(&self) -> bool { | ||
| 60 | self == &Self::Sixels | ||
| 61 | } | ||
| 62 | } | ||
| 63 | |||
| 64 | // default functions | ||
| 65 | |||
| 66 | fn invidious_instance_default() -> String { | ||
| 67 | String::from("https://invidious.sethforprivacy.com") | ||
| 68 | } | ||
| 69 | |||
| 70 | fn message_bar_default_default() -> String { | ||
| 71 | String::from("All good :)") | ||
| 72 | } | ||
| 73 | |||
| 74 | const fn images_default() -> Images { | ||
| 75 | Images::HalfBlocks | ||
| 76 | } | ||
| 77 | |||
| 78 | const fn image_index_default() -> usize { | ||
| 79 | 4 | ||
| 80 | } | ||
| 81 | |||
| 82 | const fn allow_unicode_default() -> bool { | ||
| 83 | false | ||
| 84 | } | ||
src/config/mod.rs added +14
| @@ -0,0 +1,14 @@ | |||
| 1 | mod configtrait; | ||
| 2 | pub use configtrait::*; | ||
| 3 | mod main; | ||
| 4 | pub use main::*; | ||
| 5 | mod appearance; | ||
| 6 | pub use appearance::*; | ||
| 7 | mod search; | ||
| 8 | pub use search::*; | ||
| 9 | mod pages; | ||
| 10 | pub use pages::*; | ||
| 11 | mod keybindings; | ||
| 12 | pub use keybindings::*; | ||
| 13 | |||
| 14 | pub mod serde; | ||
src/config/pages.rs added +221
| @@ -0,0 +1,221 @@ | |||
| 1 | use super::ConfigTrait; | ||
| 2 | use crate::items::{ItemList, MessageBar, PageButton, SearchBar}; | ||
| 3 | use serde::{Deserialize, Serialize}; | ||
| 4 | use std::slice; | ||
| 5 | use tui::layout::Constraint; | ||
| 6 | use tui_additions::framework::{Framework, FrameworkItem, Row, RowItem, State}; | ||
| 7 | use typemap::Key; | ||
| 8 | |||
| 9 | // Minimum screen dimention for the tui to display without panicking, | ||
| 10 | // is automatically generated from PageConfig | ||
| 11 | // will be inserted into `framework.data.state` | ||
| 12 | #[derive(Clone, Copy)] | ||
| 13 | pub struct MinDimentions { | ||
| 14 | pub width: u16, | ||
| 15 | pub height: u16, | ||
| 16 | } | ||
| 17 | |||
| 18 | impl MinDimentions { | ||
| 19 | pub const fn new(width: u16, height: u16) -> Self { | ||
| 20 | Self { width, height } | ||
| 21 | } | ||
| 22 | } | ||
| 23 | |||
| 24 | impl Default for MinDimentions { | ||
| 25 | fn default() -> Self { | ||
| 26 | Self { | ||
| 27 | width: 0, | ||
| 28 | height: 0, | ||
| 29 | } | ||
| 30 | } | ||
| 31 | } | ||
| 32 | |||
| 33 | impl Key for MinDimentions { | ||
| 34 | type Value = Self; | ||
| 35 | } | ||
| 36 | |||
| 37 | #[derive(Clone, Serialize, Deserialize)] | ||
| 38 | pub struct PagesConfig { | ||
| 39 | #[serde(default = "main_menu_default")] | ||
| 40 | pub main_menu: PageConfig, | ||
| 41 | } | ||
| 42 | |||
| 43 | impl Key for PagesConfig { | ||
| 44 | type Value = Self; | ||
| 45 | } | ||
| 46 | |||
| 47 | impl ConfigTrait for PagesConfig { | ||
| 48 | const LABEL: &'static str = "pages"; | ||
| 49 | } | ||
| 50 | |||
| 51 | impl Default for PagesConfig { | ||
| 52 | fn default() -> Self { | ||
| 53 | Self { | ||
| 54 | main_menu: main_menu_default(), | ||
| 55 | } | ||
| 56 | } | ||
| 57 | } | ||
| 58 | |||
| 59 | // This struct impls Into<State>, the corresponding page is converted into State on page load | ||
| 60 | // Each page has its own minimum width and height, which is automatically determined by the items in the page | ||
| 61 | // If it doesn't meet the minimum dimentions, a "protective screen" will be shown to prevent panicking | ||
| 62 | #[derive(Clone, Serialize, Deserialize)] | ||
| 63 | pub struct PageConfig { | ||
| 64 | pub layout: Vec<PageRow>, | ||
| 65 | pub message: String, | ||
| 66 | } | ||
| 67 | |||
| 68 | impl PageConfig { | ||
| 69 | pub fn min_width(&self) -> u16 { | ||
| 70 | self.layout | ||
| 71 | .iter() | ||
| 72 | .map(|row| { | ||
| 73 | row.iter() | ||
| 74 | .map(|item| constraint_to_u16(&item.width())) | ||
| 75 | .sum::<u16>() | ||
| 76 | }) | ||
| 77 | .max() | ||
| 78 | .unwrap() | ||
| 79 | } | ||
| 80 | |||
| 81 | pub fn min_height(&self) -> u16 { | ||
| 82 | self.layout | ||
| 83 | .iter() | ||
| 84 | .map(|row| { | ||
| 85 | row.iter() | ||
| 86 | .map(|item| constraint_to_u16(&item.height())) | ||
| 87 | .max() | ||
| 88 | .unwrap() | ||
| 89 | }) | ||
| 90 | .sum::<u16>() | ||
| 91 | } | ||
| 92 | |||
| 93 | pub fn to_state(&self, framework: &mut Framework) -> State { | ||
| 94 | State( | ||
| 95 | self.layout | ||
| 96 | .iter() | ||
| 97 | .map(|row| Row { | ||
| 98 | centered: row.is_centered(), | ||
| 99 | height: max_constraint( | ||
| 100 | &row.iter().map(|item| item.height()).collect::<Vec<_>>(), | ||
| 101 | ), | ||
| 102 | items: row | ||
| 103 | .iter() | ||
| 104 | .map(|item| RowItem { | ||
| 105 | item: item.to_framework_item(framework), | ||
| 106 | width: item.width(), | ||
| 107 | }) | ||
| 108 | .collect::<Vec<_>>(), | ||
| 109 | }) | ||
| 110 | .collect::<Vec<_>>(), | ||
| 111 | ) | ||
| 112 | } | ||
| 113 | } | ||
| 114 | |||
| 115 | // CenteredRow will have its items centered, while NonCenteredRow will align to the left | ||
| 116 | #[derive(Clone, Serialize, Deserialize)] | ||
| 117 | pub enum PageRow { | ||
| 118 | CenteredRow(Vec<PageItems>), | ||
| 119 | NonCenteredRow(Vec<PageItems>), | ||
| 120 | } | ||
| 121 | |||
| 122 | impl PageRow { | ||
| 123 | pub fn iter(&self) -> slice::Iter<PageItems> { | ||
| 124 | match self { | ||
| 125 | Self::CenteredRow(iter) | Self::NonCenteredRow(iter) => iter.iter(), | ||
| 126 | } | ||
| 127 | } | ||
| 128 | |||
| 129 | pub fn is_centered(&self) -> bool { | ||
| 130 | match self { | ||
| 131 | Self::CenteredRow(_) => true, | ||
| 132 | Self::NonCenteredRow(_) => false, | ||
| 133 | } | ||
| 134 | } | ||
| 135 | |||
| 136 | pub fn from_vec(items: Vec<PageItems>, centered: bool) -> Self { | ||
| 137 | if centered { | ||
| 138 | Self::CenteredRow(items) | ||
| 139 | } else { | ||
| 140 | Self::NonCenteredRow(items) | ||
| 141 | } | ||
| 142 | } | ||
| 143 | } | ||
| 144 | |||
| 145 | // PageItems will be converted into Box<dyn FrameworkItem> on page load to be used an item in the framework | ||
| 146 | // Seen https://docs.rs/tui-additions/latest/tui_additions/framework/trait.FrameworkItem.html | ||
| 147 | // Each item has a minimum width and height for it to render without panicking | ||
| 148 | #[derive(Clone, Copy, Serialize, Deserialize)] | ||
| 149 | pub enum PageItems { | ||
| 150 | SearchBar, | ||
| 151 | ItemList, | ||
| 152 | MessageBar, | ||
| 153 | Trending, | ||
| 154 | Popular, | ||
| 155 | } | ||
| 156 | |||
| 157 | impl PageItems { | ||
| 158 | pub fn to_framework_item(&self, framework: &mut Framework) -> Box<dyn FrameworkItem> { | ||
| 159 | match *self { | ||
| 160 | PageItems::SearchBar => Box::new(SearchBar::default()), | ||
| 161 | PageItems::Popular => Box::new(PageButton::Popular), | ||
| 162 | PageItems::Trending => Box::new(PageButton::Trending), | ||
| 163 | PageItems::MessageBar => Box::new(MessageBar::default()), | ||
| 164 | PageItems::ItemList => Box::new(ItemList::new(framework)), | ||
| 165 | } | ||
| 166 | } | ||
| 167 | |||
| 168 | pub fn width(&self) -> Constraint { | ||
| 169 | match self { | ||
| 170 | Self::Popular | Self::Trending => Constraint::Length(15), | ||
| 171 | Self::SearchBar => Constraint::Min(16), | ||
| 172 | Self::MessageBar => Constraint::Min(3), | ||
| 173 | Self::ItemList => Constraint::Min(6), | ||
| 174 | } | ||
| 175 | } | ||
| 176 | |||
| 177 | pub fn height(&self) -> Constraint { | ||
| 178 | match self { | ||
| 179 | Self::Popular | Self::Trending | Self::MessageBar | Self::SearchBar => { | ||
| 180 | Constraint::Length(3) | ||
| 181 | } | ||
| 182 | Self::ItemList => Constraint::Min(6), | ||
| 183 | } | ||
| 184 | } | ||
| 185 | } | ||
| 186 | |||
| 187 | fn constraint_to_u16(constraint: &Constraint) -> u16 { | ||
| 188 | match constraint { | ||
| 189 | Constraint::Max(length) | Constraint::Min(length) | Constraint::Length(length) => *length, | ||
| 190 | _ => unreachable!(), | ||
| 191 | } | ||
| 192 | } | ||
| 193 | |||
| 194 | fn max_constraint(constraints: &[Constraint]) -> Constraint { | ||
| 195 | let mut max_out = Constraint::Length(0); | ||
| 196 | let mut max = 0_u16; | ||
| 197 | |||
| 198 | constraints.iter().for_each(|constraint| { | ||
| 199 | let self_len = constraint_to_u16(constraint); | ||
| 200 | if self_len > max { | ||
| 201 | max = self_len; | ||
| 202 | max_out = *constraint; | ||
| 203 | } | ||
| 204 | }); | ||
| 205 | |||
| 206 | max_out | ||
| 207 | } | ||
| 208 | |||
| 209 | // default functions | ||
| 210 | |||
| 211 | fn main_menu_default() -> PageConfig { | ||
| 212 | PageConfig { | ||
| 213 | layout: vec![ | ||
| 214 | PageRow::from_vec(vec![PageItems::SearchBar], false), | ||
| 215 | PageRow::from_vec(vec![PageItems::Trending, PageItems::Popular], true), | ||
| 216 | PageRow::from_vec(vec![PageItems::ItemList], false), | ||
| 217 | PageRow::from_vec(vec![PageItems::MessageBar], false), | ||
| 218 | ], | ||
| 219 | message: String::from("Loading main menu..."), | ||
| 220 | } | ||
| 221 | } | ||
src/config/search.rs added +161
| @@ -0,0 +1,161 @@ | |||
| 1 | use crate::{config::ConfigTrait, global::traits::asurlstring::AsUrlString}; | ||
| 2 | use serde::{Deserialize, Serialize}; | ||
| 3 | use typemap::Key; | ||
| 4 | |||
| 5 | // can be turned into URL Params for the search term with filters | ||
| 6 | #[derive(Clone, Default, Serialize, Deserialize, PartialEq, Eq)] | ||
| 7 | pub struct Search { | ||
| 8 | pub query: String, | ||
| 9 | pub filters: SearchFilters, | ||
| 10 | } | ||
| 11 | |||
| 12 | impl Key for Search { | ||
| 13 | type Value = Self; | ||
| 14 | } | ||
| 15 | |||
| 16 | impl ConfigTrait for Search { | ||
| 17 | const LABEL: &'static str = "search"; | ||
| 18 | } | ||
| 19 | |||
| 20 | impl ToString for Search { | ||
| 21 | fn to_string(&self) -> String { | ||
| 22 | vec![ | ||
| 23 | format!("q={}", self.query), | ||
| 24 | self.filters.sort.as_url_string(), | ||
| 25 | self.filters.date.as_url_string(), | ||
| 26 | self.filters.duration.as_url_string(), | ||
| 27 | self.filters.r#type.as_url_string(), | ||
| 28 | ] | ||
| 29 | .join("&") | ||
| 30 | } | ||
| 31 | } | ||
| 32 | |||
| 33 | // Search filters | ||
| 34 | |||
| 35 | #[derive(Default, Clone, Copy, Serialize, Deserialize, PartialEq, Eq)] | ||
| 36 | pub struct SearchFilters { | ||
| 37 | pub sort: SearchFilterSort, | ||
| 38 | pub date: SearchFilterDate, | ||
| 39 | pub duration: SearchFilterDuration, | ||
| 40 | pub r#type: SearchFilterType, | ||
| 41 | } | ||
| 42 | |||
| 43 | #[derive(Clone, Copy, Serialize, Deserialize, PartialEq, Eq)] | ||
| 44 | pub enum SearchFilterSort { | ||
| 45 | Relevance, | ||
| 46 | Rating, | ||
| 47 | Date, | ||
| 48 | Views, | ||
| 49 | } | ||
| 50 | |||
| 51 | #[derive(Clone, Copy, Serialize, Deserialize, PartialEq, Eq)] | ||
| 52 | pub enum SearchFilterDate { | ||
| 53 | None, | ||
| 54 | Hour, | ||
| 55 | Day, | ||
| 56 | Week, | ||
| 57 | Month, | ||
| 58 | Year, | ||
| 59 | } | ||
| 60 | |||
| 61 | #[derive(Clone, Copy, Serialize, Deserialize, PartialEq, Eq)] | ||
| 62 | pub enum SearchFilterDuration { | ||
| 63 | None, | ||
| 64 | Short, | ||
| 65 | Medium, | ||
| 66 | Long, | ||
| 67 | } | ||
| 68 | |||
| 69 | #[derive(Clone, Copy, Serialize, Deserialize, PartialEq, Eq)] | ||
| 70 | pub enum SearchFilterType { | ||
| 71 | All, | ||
| 72 | Video, | ||
| 73 | Channel, | ||
| 74 | Playlist, | ||
| 75 | } | ||
| 76 | |||
| 77 | impl Default for SearchFilterSort { | ||
| 78 | fn default() -> Self { | ||
| 79 | Self::Relevance | ||
| 80 | } | ||
| 81 | } | ||
| 82 | |||
| 83 | impl Default for SearchFilterDate { | ||
| 84 | fn default() -> Self { | ||
| 85 | Self::None | ||
| 86 | } | ||
| 87 | } | ||
| 88 | |||
| 89 | impl Default for SearchFilterDuration { | ||
| 90 | fn default() -> Self { | ||
| 91 | Self::None | ||
| 92 | } | ||
| 93 | } | ||
| 94 | |||
| 95 | impl Default for SearchFilterType { | ||
| 96 | fn default() -> Self { | ||
| 97 | Self::All | ||
| 98 | } | ||
| 99 | } | ||
| 100 | |||
| 101 | impl ToString for SearchFilterSort { | ||
| 102 | fn to_string(&self) -> String { | ||
| 103 | match self { | ||
| 104 | Self::Relevance => String::from("relevance"), | ||
| 105 | Self::Rating => String::from("rating"), | ||
| 106 | Self::Date => String::from("date"), | ||
| 107 | Self::Views => String::from("views"), | ||
| 108 | } | ||
| 109 | } | ||
| 110 | } | ||
| 111 | |||
| 112 | impl ToString for SearchFilterDate { | ||
| 113 | fn to_string(&self) -> String { | ||
| 114 | match self { | ||
| 115 | Self::None => String::from("none"), | ||
| 116 | Self::Hour => String::from("hour"), | ||
| 117 | Self::Day => String::from("day"), | ||
| 118 | Self::Week => String::from("week"), | ||
| 119 | Self::Month => String::from("month"), | ||
| 120 | Self::Year => String::from("year"), | ||
| 121 | } | ||
| 122 | } | ||
| 123 | } | ||
| 124 | |||
| 125 | impl ToString for SearchFilterDuration { | ||
| 126 | fn to_string(&self) -> String { | ||
| 127 | match self { | ||
| 128 | Self::None => String::from("none"), | ||
| 129 | Self::Short => String::from("short"), | ||
| 130 | Self::Medium => String::from("medium"), | ||
| 131 | Self::Long => String::from("long"), | ||
| 132 | } | ||
| 133 | } | ||
| 134 | } | ||
| 135 | |||
| 136 | impl ToString for SearchFilterType { | ||
| 137 | fn to_string(&self) -> String { | ||
| 138 | match self { | ||
| 139 | Self::All => String::from("all"), | ||
| 140 | Self::Video => String::from("video"), | ||
| 141 | Self::Channel => String::from("channel"), | ||
| 142 | Self::Playlist => String::from("playlist"), | ||
| 143 | } | ||
| 144 | } | ||
| 145 | } | ||
| 146 | |||
| 147 | impl AsUrlString for SearchFilterSort { | ||
| 148 | const TAG: &'static str = "sort"; | ||
| 149 | } | ||
| 150 | |||
| 151 | impl AsUrlString for SearchFilterDate { | ||
| 152 | const TAG: &'static str = "date"; | ||
| 153 | } | ||
| 154 | |||
| 155 | impl AsUrlString for SearchFilterDuration { | ||
| 156 | const TAG: &'static str = "duration"; | ||
| 157 | } | ||
| 158 | |||
| 159 | impl AsUrlString for SearchFilterType { | ||
| 160 | const TAG: &'static str = "type"; | ||
| 161 | } | ||
src/config/serde.rs added +29
| @@ -0,0 +1,29 @@ | |||
| 1 | // Structs that impl Into<WhatEverStruct> because WhatEverStruct does not impl Serde | ||
| 2 | |||
| 3 | use serde::{Deserialize, Serialize}; | ||
| 4 | use tui::widgets::BorderType; | ||
| 5 | |||
| 6 | #[derive(Serialize, Deserialize, Clone, Copy)] | ||
| 7 | pub enum BorderTypeSerde { | ||
| 8 | Plain, | ||
| 9 | Rounded, | ||
| 10 | Double, | ||
| 11 | Thick, | ||
| 12 | } | ||
| 13 | |||
| 14 | impl Default for BorderTypeSerde { | ||
| 15 | fn default() -> Self { | ||
| 16 | Self::Rounded | ||
| 17 | } | ||
| 18 | } | ||
| 19 | |||
| 20 | impl Into<BorderType> for BorderTypeSerde { | ||
| 21 | fn into(self) -> BorderType { | ||
| 22 | match self { | ||
| 23 | Self::Plain => BorderType::Plain, | ||
| 24 | Self::Rounded => BorderType::Rounded, | ||
| 25 | Self::Thick => BorderType::Thick, | ||
| 26 | Self::Double => BorderType::Double, | ||
| 27 | } | ||
| 28 | } | ||
| 29 | } | ||
src/exit.rs added +15
| @@ -0,0 +1,15 @@ | |||
| 1 | use home::home_dir; | ||
| 2 | use std::{error::Error, fs}; | ||
| 3 | |||
| 4 | // exit tasks: | ||
| 5 | // - remove `~/.cache` | ||
| 6 | pub fn exit() -> Result<(), Box<dyn Error>> { | ||
| 7 | let home_dir = home_dir().unwrap(); | ||
| 8 | let cache_path = home_dir.join(".cache/youtube-tui/"); | ||
| 9 | |||
| 10 | if cache_path.exists() { | ||
| 11 | fs::remove_dir_all(cache_path)?; | ||
| 12 | } | ||
| 13 | |||
| 14 | Ok(()) | ||
| 15 | } | ||
src/functions/center_rect.rs deleted −36
| @@ -1,36 +0,0 @@ | |||
| 1 | use tui::layout::Rect; | ||
| 2 | |||
| 3 | pub fn center_rect(rect: (u16, u16), frame_rect: Rect) -> Result<Rect, Rect> { | ||
| 4 | let width_too_big = rect.0 > frame_rect.width; | ||
| 5 | let height_too_big = rect.1 > frame_rect.height; | ||
| 6 | |||
| 7 | if width_too_big || height_too_big { | ||
| 8 | return Err(Rect { | ||
| 9 | width: if width_too_big { | ||
| 10 | frame_rect.width | ||
| 11 | } else { | ||
| 12 | rect.0 | ||
| 13 | }, | ||
| 14 | height: if height_too_big { | ||
| 15 | frame_rect.height | ||
| 16 | } else { | ||
| 17 | rect.1 | ||
| 18 | }, | ||
| 19 | x: if width_too_big { | ||
| 20 | frame_rect.x | ||
| 21 | } else { | ||
| 22 | (frame_rect.x + frame_rect.width - rect.0) / 2 | ||
| 23 | }, | ||
| 24 | y: if height_too_big { | ||
| 25 | frame_rect.y | ||
| 26 | } else { | ||
| 27 | (frame_rect.y + frame_rect.height - rect.1) / 2 | ||
| 28 | }, | ||
| 29 | }); | ||
| 30 | } | ||
| 31 | |||
| 32 | let x = (frame_rect.x + frame_rect.width - rect.0) / 2; | ||
| 33 | let y = (frame_rect.y + frame_rect.height - rect.1) / 2; | ||
| 34 | |||
| 35 | Ok(Rect::new(x, y, rect.0, rect.1)) | ||
| 36 | } | ||
src/functions/download_all_thumbnails.rs deleted −54
| @@ -1,54 +0,0 @@ | |||
| 1 | use std::{collections::LinkedList, error::Error, io::Cursor, thread}; | ||
| 2 | |||
| 3 | use futures::future::join_all; | ||
| 4 | use tokio::runtime::Runtime; | ||
| 5 | |||
| 6 | pub enum ItemType { | ||
| 7 | Video, | ||
| 8 | PlayList, | ||
| 9 | } | ||
| 10 | |||
| 11 | pub fn download_all_thumbnails( | ||
| 12 | list: LinkedList<(String, String)>, // (url, id) | ||
| 13 | ) -> Result<(), Box<dyn Error>> { | ||
| 14 | thread::spawn(move || { | ||
| 15 | let rt: Runtime = tokio::runtime::Runtime::new().unwrap(); | ||
| 16 | |||
| 17 | let _ = rt.block_on(download_items(list)); | ||
| 18 | }); | ||
| 19 | |||
| 20 | Ok(()) | ||
| 21 | } | ||
| 22 | |||
| 23 | pub async fn download_items(urls: LinkedList<(String, String)>) -> Result<(), Box<dyn Error>> { | ||
| 24 | let mut actions = Vec::new(); | ||
| 25 | let mut path = home::home_dir().expect("Cannot get your home directory"); | ||
| 26 | path.push(".cache"); | ||
| 27 | path.push("youtube-tui"); | ||
| 28 | path.push("thumbnails"); | ||
| 29 | |||
| 30 | for (url, video_id) in urls.iter() { | ||
| 31 | path.push(format!("{}.png", video_id)); | ||
| 32 | |||
| 33 | if !path.exists() { | ||
| 34 | actions.push(fetch_url( | ||
| 35 | url.as_str(), | ||
| 36 | path.clone().into_os_string().into_string().unwrap(), | ||
| 37 | )); | ||
| 38 | } | ||
| 39 | |||
| 40 | path.pop(); | ||
| 41 | } | ||
| 42 | |||
| 43 | join_all(actions).await; | ||
| 44 | |||
| 45 | Ok(()) | ||
| 46 | } | ||
| 47 | |||
| 48 | async fn fetch_url(url: &str, path: String) -> Result<(), Box<dyn Error>> { | ||
| 49 | let response = reqwest::get(url).await?; | ||
| 50 | let mut file = std::fs::File::create(path)?; | ||
| 51 | let mut content = Cursor::new(response.bytes().await?); | ||
| 52 | std::io::copy(&mut content, &mut file)?; | ||
| 53 | Ok(()) | ||
| 54 | } | ||
src/functions/insert_vec.rs deleted −6
| @@ -1,6 +0,0 @@ | |||
| 1 | pub fn insert_vec<T>(vec: &mut Vec<T>, to_insert: Vec<T>, mut index: usize) { | ||
| 2 | to_insert.into_iter().for_each(|x| { | ||
| 3 | vec.insert(index, x); | ||
| 4 | index += 1; | ||
| 5 | }); | ||
| 6 | } | ||
src/functions/mod.rs deleted −8
| @@ -1,8 +0,0 @@ | |||
| 1 | mod download_all_thumbnails; | ||
| 2 | pub use download_all_thumbnails::*; | ||
| 3 | |||
| 4 | mod insert_vec; | ||
| 5 | pub use insert_vec::*; | ||
| 6 | |||
| 7 | mod center_rect; | ||
| 8 | pub use center_rect::*; | ||
src/global/errors.rs added +21
| @@ -0,0 +1,21 @@ | |||
| 1 | use std::{error::Error, fmt::Display}; | ||
| 2 | |||
| 3 | // Errors for displaying custom string in the message bar if there is an error | ||
| 4 | #[derive(Debug)] | ||
| 5 | pub enum Errors { | ||
| 6 | BlankError, | ||
| 7 | StringError(String), | ||
| 8 | StrError(&'static str), | ||
| 9 | } | ||
| 10 | |||
| 11 | impl Display for Errors { | ||
| 12 | fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { | ||
| 13 | match self { | ||
| 14 | Self::BlankError => f.write_str("Is a blank error ¯\\_(ツ)_/¯"), | ||
| 15 | Self::StringError(e) => f.write_str(&e), | ||
| 16 | Self::StrError(e) => f.write_str(e), | ||
| 17 | } | ||
| 18 | } | ||
| 19 | } | ||
| 20 | |||
| 21 | impl Error for Errors {} | ||
src/global/functions/date_text.rs added +7
| @@ -0,0 +1,7 @@ | |||
| 1 | use chrono::{Datelike, NaiveDateTime}; | ||
| 2 | |||
| 3 | // Convert timestamp into DD/MM/YYYY | ||
| 4 | pub fn date_text(timestamp: u64) -> String { | ||
| 5 | let date = NaiveDateTime::from_timestamp(timestamp as i64, 0).date(); | ||
| 6 | format!("{}/{}/{}", date.day(), date.month(), date.year()) | ||
| 7 | } | ||
src/global/functions/download_all_images.rs added +67
| @@ -0,0 +1,67 @@ | |||
| 1 | use crate::global::item::Item; | ||
| 2 | use futures::future::join_all; | ||
| 3 | use std::{error::Error, fs, io::Cursor, thread}; | ||
| 4 | use tokio::runtime::Runtime; | ||
| 5 | |||
| 6 | pub struct DownloadRequest { | ||
| 7 | pub url: String, | ||
| 8 | pub id: String, | ||
| 9 | } | ||
| 10 | |||
| 11 | impl From<&Item> for DownloadRequest { | ||
| 12 | fn from(item: &Item) -> Self { | ||
| 13 | match item { | ||
| 14 | Item::MiniVideo(minivideo) => Self { | ||
| 15 | url: minivideo.thumbnail_url.clone(), | ||
| 16 | id: minivideo.id.clone(), | ||
| 17 | }, | ||
| 18 | } | ||
| 19 | } | ||
| 20 | } | ||
| 21 | |||
| 22 | // Function to download all thumbnails (or just any files) to `~/.cache/thumbnails` with no file exitension (cuz its not needed) | ||
| 23 | pub fn download_all_images(downloads: Vec<DownloadRequest>) { | ||
| 24 | thread::spawn(move || { | ||
| 25 | let rt: Runtime = tokio::runtime::Runtime::new().unwrap(); | ||
| 26 | |||
| 27 | let _ = rt.block_on(download_all_images_async(downloads)); | ||
| 28 | }); | ||
| 29 | } | ||
| 30 | |||
| 31 | // Create a `download_single()`s and join them into 1 future | ||
| 32 | // So all downloads will happen at the same time without waiting | ||
| 33 | async fn download_all_images_async(downloads: Vec<DownloadRequest>) { | ||
| 34 | let mut actions = Vec::new(); | ||
| 35 | let mut path = home::home_dir().expect("Cannot get your home directory"); | ||
| 36 | path.push(".cache/youtube-tui/thumbnails/"); | ||
| 37 | |||
| 38 | for download in downloads.into_iter() { | ||
| 39 | let mut path = path.clone(); | ||
| 40 | fs::create_dir_all(&path).unwrap(); | ||
| 41 | path.push(download.id); | ||
| 42 | |||
| 43 | if !path.exists() { | ||
| 44 | actions.push(download_single( | ||
| 45 | download.url, | ||
| 46 | path.clone().into_os_string().into_string().unwrap(), | ||
| 47 | )); | ||
| 48 | } | ||
| 49 | |||
| 50 | path.pop(); | ||
| 51 | } | ||
| 52 | |||
| 53 | join_all(actions).await; | ||
| 54 | } | ||
| 55 | |||
| 56 | // Download a single file | ||
| 57 | async fn download_single(url: String, path: String) -> Result<(), Box<dyn Error>> { | ||
| 58 | let response = reqwest::get(url).await?; | ||
| 59 | if !response.status().is_success() { | ||
| 60 | return Ok(()); | ||
| 61 | } | ||
| 62 | |||
| 63 | let mut file = std::fs::File::create(path)?; | ||
| 64 | let mut content = Cursor::new(response.bytes().await?); | ||
| 65 | std::io::copy(&mut content, &mut file)?; | ||
| 66 | Ok(()) | ||
| 67 | } | ||
src/global/functions/mod.rs added +8
| @@ -0,0 +1,8 @@ | |||
| 1 | mod secs_display_string; | ||
| 2 | pub use secs_display_string::secs_display_string; | ||
| 3 | mod viewcount_text; | ||
| 4 | pub use viewcount_text::viewcount_text; | ||
| 5 | mod date_text; | ||
| 6 | pub use date_text::date_text; | ||
| 7 | mod download_all_images; | ||
| 8 | pub use download_all_images::download_all_images; | ||
src/global/functions/secs_display_string.rs added +34
| @@ -0,0 +1,34 @@ | |||
| 1 | const SECS_IN_MINUTE: u32 = 60; | ||
| 2 | const SECS_IN_HOUR: u32 = 3600; | ||
| 3 | |||
| 4 | // Turns seconds into pretty format like 02:43 | ||
| 5 | pub fn secs_display_string(mut secs: u32) -> String { | ||
| 6 | let mut out = Vec::new(); | ||
| 7 | |||
| 8 | if secs >= SECS_IN_HOUR { | ||
| 9 | let hours = secs / SECS_IN_HOUR; | ||
| 10 | secs -= hours * SECS_IN_HOUR; | ||
| 11 | out.push(format!("{}", hours)); | ||
| 12 | } | ||
| 13 | |||
| 14 | if secs >= SECS_IN_MINUTE { | ||
| 15 | let minutes = secs / SECS_IN_MINUTE; | ||
| 16 | secs -= minutes * SECS_IN_MINUTE; | ||
| 17 | out.push(two_digit_num(minutes)); | ||
| 18 | } else if out.len() != 0 { | ||
| 19 | out.push(String::from("00")); | ||
| 20 | } | ||
| 21 | |||
| 22 | if out.len() == 0 { | ||
| 23 | out.push(String::from("00")); | ||
| 24 | } | ||
| 25 | out.push(two_digit_num(secs)); | ||
| 26 | |||
| 27 | out.join(":") | ||
| 28 | } | ||
| 29 | |||
| 30 | fn two_digit_num(num: u32) -> String { | ||
| 31 | let out = format!("{}", num); | ||
| 32 | |||
| 33 | format!("{}{}", "0".repeat(2 - out.len()), out) | ||
| 34 | } | ||
src/global/functions/viewcount_text.rs added +17
| @@ -0,0 +1,17 @@ | |||
| 1 | const UNITS: &[(&'static str, f64)] = &[ | ||
| 2 | ("B", 1_000_000_000_f64), | ||
| 3 | ("M", 1_000_000_f64), | ||
| 4 | ("K", 1_000_f64), | ||
| 5 | ("", 1_f64), | ||
| 6 | ]; | ||
| 7 | |||
| 8 | // Turns number into short hand like 1.56M instead of its full form | ||
| 9 | pub fn viewcount_text(views: u64) -> String { | ||
| 10 | for unit in UNITS.iter() { | ||
| 11 | if views >= unit.1 as u64 { | ||
| 12 | return format!("{:.2}{}", views as f64 / unit.1, unit.0); | ||
| 13 | } | ||
| 14 | } | ||
| 15 | |||
| 16 | unreachable!() | ||
| 17 | } | ||
src/global/invidiousclient.rs added +16
| @@ -0,0 +1,16 @@ | |||
| 1 | use invidious::reqwest::blocking::Client; | ||
| 2 | use typemap::Key; | ||
| 3 | |||
| 4 | // Holds the invidious client | ||
| 5 | #[derive(Clone)] | ||
| 6 | pub struct InvidiousClient(pub Client); | ||
| 7 | |||
| 8 | impl InvidiousClient { | ||
| 9 | pub fn new(instance: String) -> Self { | ||
| 10 | Self(Client::new(instance)) | ||
| 11 | } | ||
| 12 | } | ||
| 13 | |||
| 14 | impl Key for InvidiousClient { | ||
| 15 | type Value = Self; | ||
| 16 | } | ||
src/global/item.rs added +112
| @@ -0,0 +1,112 @@ | |||
| 1 | use std::fmt::Display; | ||
| 2 | |||
| 3 | use super::functions::{date_text, secs_display_string, viewcount_text}; | ||
| 4 | use invidious::structs::hidden::{PopularItem, SearchItem, TrendingVideo}; | ||
| 5 | |||
| 6 | // Items are things like a single video/playlist and channel | ||
| 7 | // they are displayed by the item info widget in `iteminfo.rs` | ||
| 8 | #[derive(Clone)] | ||
| 9 | pub enum Item { | ||
| 10 | // minivideos are all videos that appeared without actually clicking into the video | ||
| 11 | MiniVideo(MiniVideoItem), | ||
| 12 | } | ||
| 13 | |||
| 14 | #[derive(Clone)] | ||
| 15 | pub struct MiniVideoItem { | ||
| 16 | pub title: String, | ||
| 17 | pub id: String, | ||
| 18 | pub thumbnail_url: String, | ||
| 19 | pub length: String, | ||
| 20 | pub views: Option<String>, | ||
| 21 | pub channel: String, | ||
| 22 | pub channel_id: String, | ||
| 23 | pub published: String, | ||
| 24 | pub description: Option<String>, | ||
| 25 | } | ||
| 26 | |||
| 27 | impl Display for Item { | ||
| 28 | fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { | ||
| 29 | f.write_str(match self { | ||
| 30 | Self::MiniVideo(video) => &video.title, | ||
| 31 | }) | ||
| 32 | } | ||
| 33 | } | ||
| 34 | |||
| 35 | impl Item { | ||
| 36 | // the file save path for thumbnails (which is by their id) | ||
| 37 | pub fn thumbnail_id(&self) -> &str { | ||
| 38 | match self { | ||
| 39 | Self::MiniVideo(video) => &video.id, | ||
| 40 | } | ||
| 41 | } | ||
| 42 | |||
| 43 | // cannot impl From<T> because it also need `image_index` | ||
| 44 | pub fn from_trending_video(original: TrendingVideo, image_index: usize) -> Self { | ||
| 45 | Self::MiniVideo(MiniVideoItem { | ||
| 46 | title: original.title, | ||
| 47 | id: original.id, | ||
| 48 | thumbnail_url: original.thumbmails[image_index].url.clone(), | ||
| 49 | length: secs_display_string(original.length), | ||
| 50 | views: Some(viewcount_text(original.views)), | ||
| 51 | channel: original.author, | ||
| 52 | channel_id: original.author_id, | ||
| 53 | published: format!( | ||
| 54 | "{} [{}]", | ||
| 55 | original.published_text, | ||
| 56 | date_text(original.published) | ||
| 57 | ), | ||
| 58 | description: Some(original.description), | ||
| 59 | }) | ||
| 60 | } | ||
| 61 | |||
| 62 | pub fn from_popular_item(original: PopularItem, image_index: usize) -> Self { | ||
| 63 | Self::MiniVideo(MiniVideoItem { | ||
| 64 | title: original.title, | ||
| 65 | id: original.id, | ||
| 66 | thumbnail_url: original.thumbnails[image_index].url.clone(), | ||
| 67 | length: secs_display_string(original.length), | ||
| 68 | views: Some(viewcount_text(original.views)), | ||
| 69 | channel: original.author, | ||
| 70 | channel_id: original.author_id, | ||
| 71 | published: format!( | ||
| 72 | "{} [{}]", | ||
| 73 | original.published_text, | ||
| 74 | date_text(original.published) | ||
| 75 | ), | ||
| 76 | description: None, | ||
| 77 | }) | ||
| 78 | } | ||
| 79 | |||
| 80 | pub fn from_search_item(original: SearchItem, image_index: usize) -> Self { | ||
| 81 | match original { | ||
| 82 | SearchItem::Video { | ||
| 83 | title, | ||
| 84 | id, | ||
| 85 | author, | ||
| 86 | author_id, | ||
| 87 | author_url: _, | ||
| 88 | length, | ||
| 89 | thumbnails, | ||
| 90 | description, | ||
| 91 | description_html: _, | ||
| 92 | views, | ||
| 93 | published, | ||
| 94 | published_text, | ||
| 95 | live: _, | ||
| 96 | paid: _, | ||
| 97 | premium: _, | ||
| 98 | } => Self::MiniVideo(MiniVideoItem { | ||
| 99 | title, | ||
| 100 | id, | ||
| 101 | thumbnail_url: thumbnails[image_index].url.clone(), | ||
| 102 | length: secs_display_string(length as u32), | ||
| 103 | views: Some(viewcount_text(views)), | ||
| 104 | channel: author, | ||
| 105 | channel_id: author_id, | ||
| 106 | published: format!("{} [{}]", published_text, date_text(published)), | ||
| 107 | description: Some(description), | ||
| 108 | }), | ||
| 109 | _ => todo!(), | ||
| 110 | } | ||
| 111 | } | ||
| 112 | } | ||
src/global/keyaction.rs added +13
| @@ -0,0 +1,13 @@ | |||
| 1 | use serde::{Deserialize, Serialize}; | ||
| 2 | |||
| 3 | // Each key + modifier is bind to a key in a HashMap<KeyCode, HashMap<u8, KeyAction>> | ||
| 4 | #[derive(Serialize, Deserialize, Clone, Copy, PartialEq, Eq, Debug)] | ||
| 5 | pub enum KeyAction { | ||
| 6 | MoveLeft, | ||
| 7 | MoveRight, | ||
| 8 | MoveUp, | ||
| 9 | MoveDown, | ||
| 10 | Select, | ||
| 11 | Deselect, | ||
| 12 | Exit, | ||
| 13 | } | ||
src/global/message.rs added +24
| @@ -0,0 +1,24 @@ | |||
| 1 | use typemap::Key; | ||
| 2 | |||
| 3 | // Messages in the message bar, the struct is global | ||
| 4 | #[derive(Clone)] | ||
| 5 | pub enum Message { | ||
| 6 | Message(String), | ||
| 7 | Error(String), | ||
| 8 | None, | ||
| 9 | } | ||
| 10 | |||
| 11 | impl Key for Message { | ||
| 12 | type Value = Self; | ||
| 13 | } | ||
| 14 | |||
| 15 | impl Message { | ||
| 16 | // to_string is used by the message bar to convert Message to string | ||
| 17 | pub fn to_string(&self, default: &str) -> String { | ||
| 18 | match self { | ||
| 19 | Message::Message(msg) => msg.to_string(), | ||
| 20 | Message::Error(msg) => msg.to_string(), | ||
| 21 | Message::None => default.to_string(), | ||
| 22 | } | ||
| 23 | } | ||
| 24 | } | ||
src/global/mod.rs added +10
| @@ -0,0 +1,10 @@ | |||
| 1 | pub mod errors; | ||
| 2 | pub mod invidiousclient; | ||
| 3 | pub mod item; | ||
| 4 | pub mod keyaction; | ||
| 5 | pub mod message; | ||
| 6 | pub mod page; | ||
| 7 | pub mod tasks; | ||
| 8 | |||
| 9 | pub mod functions; | ||
| 10 | pub mod traits; | ||
src/global/page.rs added +52
| @@ -0,0 +1,52 @@ | |||
| 1 | use crate::config::{PageConfig, PagesConfig, Search}; | ||
| 2 | use tui_additions::framework::Framework; | ||
| 3 | use typemap::Key; | ||
| 4 | |||
| 5 | // Page can be converted into PageConfig, which can then be converted into State | ||
| 6 | // Covers all possible pages and its variants | ||
| 7 | #[derive(Clone, PartialEq, Eq)] | ||
| 8 | pub enum Page { | ||
| 9 | MainMenu(MainMenuPage), | ||
| 10 | Search(Search), | ||
| 11 | } | ||
| 12 | |||
| 13 | impl Default for Page { | ||
| 14 | fn default() -> Self { | ||
| 15 | Self::MainMenu(MainMenuPage::default()) | ||
| 16 | } | ||
| 17 | } | ||
| 18 | |||
| 19 | impl Key for Page { | ||
| 20 | type Value = Self; | ||
| 21 | } | ||
| 22 | |||
| 23 | #[derive(Clone, PartialEq, Eq)] | ||
| 24 | pub enum MainMenuPage { | ||
| 25 | Trending, | ||
| 26 | Popular, | ||
| 27 | } | ||
| 28 | |||
| 29 | impl Default for MainMenuPage { | ||
| 30 | fn default() -> Self { | ||
| 31 | Self::Trending | ||
| 32 | } | ||
| 33 | } | ||
| 34 | |||
| 35 | impl Page { | ||
| 36 | pub fn to_page_config(&self, framework: &Framework) -> PageConfig { | ||
| 37 | let pages_config = framework.data.global.get::<PagesConfig>().unwrap(); | ||
| 38 | match self { | ||
| 39 | Self::MainMenu(_) => pages_config.main_menu.clone(), | ||
| 40 | Self::Search(_) => todo!(), | ||
| 41 | } | ||
| 42 | } | ||
| 43 | |||
| 44 | // each page displays a text when loading, and that text is taken from config | ||
| 45 | pub fn load_msg(&self, framework: &Framework) -> String { | ||
| 46 | let pages_config = framework.data.global.get::<PagesConfig>().unwrap(); | ||
| 47 | match self { | ||
| 48 | Self::MainMenu(_) => pages_config.main_menu.message.clone(), | ||
| 49 | Self::Search(_) => todo!(), | ||
| 50 | } | ||
| 51 | } | ||
| 52 | } | ||
src/global/tasks.rs added +190
| @@ -0,0 +1,190 @@ | |||
| 1 | use crate::config::{AppearanceConfig, MinDimentions}; | ||
| 2 | |||
| 3 | use super::{message::Message, page::Page}; | ||
| 4 | use std::{error::Error, io::Stdout, mem}; | ||
| 5 | use tui::{ | ||
| 6 | backend::CrosstermBackend, layout::Alignment, style::Style, widgets::Paragraph, Frame, Terminal, | ||
| 7 | }; | ||
| 8 | use tui_additions::framework::{CursorState, Framework}; | ||
| 9 | use typemap::Key; | ||
| 10 | |||
| 11 | #[derive(Clone)] | ||
| 12 | pub enum Task { | ||
| 13 | RenderAll, | ||
| 14 | Reload, | ||
| 15 | RenderOnly(usize, usize), | ||
| 16 | LoadPage(Page), | ||
| 17 | } | ||
| 18 | |||
| 19 | #[derive(Clone, PartialEq, Eq)] | ||
| 20 | pub struct TaskQueue { | ||
| 21 | pub render: RenderTask, | ||
| 22 | pub reload: bool, | ||
| 23 | pub load_page: Option<Page>, | ||
| 24 | } | ||
| 25 | |||
| 26 | impl Default for TaskQueue { | ||
| 27 | fn default() -> Self { | ||
| 28 | Self { | ||
| 29 | render: RenderTask::None, | ||
| 30 | reload: false, | ||
| 31 | load_page: None, | ||
| 32 | } | ||
| 33 | } | ||
| 34 | } | ||
| 35 | |||
| 36 | impl TaskQueue { | ||
| 37 | // add task to queue | ||
| 38 | pub fn push(&mut self, task: Task) { | ||
| 39 | match task { | ||
| 40 | Task::RenderAll => self.render = RenderTask::All, | ||
| 41 | Task::Reload => self.reload = true, | ||
| 42 | Task::RenderOnly(x, y) => match &mut self.render { | ||
| 43 | RenderTask::Only(renders) => { | ||
| 44 | if !renders.contains(&(x, y)) { | ||
| 45 | renders.push((x, y)); | ||
| 46 | println!("{:?}", self.render); | ||
| 47 | } | ||
| 48 | } | ||
| 49 | RenderTask::None => self.render = RenderTask::Only(vec![(x, y)]), | ||
| 50 | _ => return, | ||
| 51 | }, | ||
| 52 | Task::LoadPage(page) => self.load_page = Some(page), | ||
| 53 | // _ => {} | ||
| 54 | } | ||
| 55 | } | ||
| 56 | |||
| 57 | pub fn is_empty(&self) -> bool { | ||
| 58 | self == &Self::default() | ||
| 59 | } | ||
| 60 | |||
| 61 | // runs all tasks in a task queue | ||
| 62 | pub fn run( | ||
| 63 | self, | ||
| 64 | framework: &mut Framework, | ||
| 65 | terminal: &mut Terminal<CrosstermBackend<Stdout>>, | ||
| 66 | ) -> Result<(), Box<dyn Error>> { | ||
| 67 | match self.render { | ||
| 68 | RenderTask::All => { | ||
| 69 | Self::render(framework, terminal)?; | ||
| 70 | } | ||
| 71 | RenderTask::Only(_locations) => { | ||
| 72 | // need to file an issue to tui-rs suggesting this as a feature | ||
| 73 | unimplemented!(); | ||
| 74 | } | ||
| 75 | RenderTask::None => {} | ||
| 76 | } | ||
| 77 | |||
| 78 | if self.reload { | ||
| 79 | // reload simply runs `.load()` on all items | ||
| 80 | *framework.data.global.get_mut::<Message>().unwrap() = | ||
| 81 | Message::Message(String::from("Reloading page...")); | ||
| 82 | Self::render(framework, terminal)?; | ||
| 83 | *framework.data.global.get_mut::<Message>().unwrap() = if let Err(e) = framework.load() { | ||
| 84 | Message::Error(format!("{}", e)) | ||
| 85 | } else { | ||
| 86 | Message::None | ||
| 87 | }; | ||
| 88 | Self::render(framework, terminal)?; | ||
| 89 | } | ||
| 90 | |||
| 91 | // save state in history, then replace all items by whats in the new page and run `.load()` on them | ||
| 92 | if let Some(page) = self.load_page { | ||
| 93 | *framework.data.global.get_mut::<Message>().unwrap() = | ||
| 94 | Message::Message(page.load_msg(framework)); | ||
| 95 | framework.push_history(); | ||
| 96 | |||
| 97 | let page_config = page.to_page_config(&framework); | ||
| 98 | *framework.data.state.get_mut::<MinDimentions>().unwrap() = | ||
| 99 | MinDimentions::new(page_config.min_width(), page_config.min_height()); | ||
| 100 | |||
| 101 | let state = page_config.to_state(framework); | ||
| 102 | framework.set_state(state); | ||
| 103 | *framework.data.state.get_mut::<Page>().unwrap() = page; | ||
| 104 | Self::render(framework, terminal)?; | ||
| 105 | *framework.data.global.get_mut::<Message>().unwrap() = Message::None; | ||
| 106 | |||
| 107 | framework.cursor = CursorState::default(); | ||
| 108 | *framework.data.global.get_mut::<Message>().unwrap() = if let Err(e) = framework.load() { | ||
| 109 | Message::Error(format!("{}", e)) | ||
| 110 | } else { | ||
| 111 | Message::None | ||
| 112 | }; | ||
| 113 | Self::render(framework, terminal)?; | ||
| 114 | } | ||
| 115 | |||
| 116 | Ok(()) | ||
| 117 | } | ||
| 118 | |||
| 119 | // the render task runs this function | ||
| 120 | pub fn render( | ||
| 121 | framework: &mut Framework, | ||
| 122 | terminal: &mut Terminal<CrosstermBackend<Stdout>>, | ||
| 123 | ) -> Result<(), Box<dyn Error>> { | ||
| 124 | terminal.draw(|frame: &mut Frame<CrosstermBackend<Stdout>>| { | ||
| 125 | let min_dimentions = framework.data.state.get::<MinDimentions>().unwrap(); | ||
| 126 | let area = frame.size(); | ||
| 127 | |||
| 128 | // if the minimum width and height is not meet, then displays a "protective screen" to prevent panicking | ||
| 129 | if area.width < min_dimentions.width || area.height < min_dimentions.height { | ||
| 130 | let paragraph = Paragraph::new(format!( | ||
| 131 | "{}Current: {} x {}\nRequired: {} x {}", | ||
| 132 | "\n".repeat(area.height as usize / 2 - 1), | ||
| 133 | area.width, | ||
| 134 | area.height, | ||
| 135 | min_dimentions.width, | ||
| 136 | min_dimentions.height | ||
| 137 | )) | ||
| 138 | .alignment(Alignment::Center) | ||
| 139 | .style( | ||
| 140 | Style::default().fg(framework | ||
| 141 | .data | ||
| 142 | .global | ||
| 143 | .get::<AppearanceConfig>() | ||
| 144 | .unwrap() | ||
| 145 | .colors | ||
| 146 | .error_text), | ||
| 147 | ); | ||
| 148 | frame.render_widget(paragraph, area); | ||
| 149 | return; | ||
| 150 | } | ||
| 151 | |||
| 152 | framework.render(frame); | ||
| 153 | })?; | ||
| 154 | |||
| 155 | Ok(()) | ||
| 156 | } | ||
| 157 | } | ||
| 158 | |||
| 159 | #[derive(Clone, PartialEq, Eq, Debug)] | ||
| 160 | pub enum RenderTask { | ||
| 161 | All, | ||
| 162 | None, | ||
| 163 | Only(Vec<(usize, usize)>), | ||
| 164 | } | ||
| 165 | |||
| 166 | #[derive(Clone, Default)] | ||
| 167 | pub struct Tasks { | ||
| 168 | // priority will get executed first, last will get executed after priority queue finished | ||
| 169 | pub priority: TaskQueue, | ||
| 170 | pub last: TaskQueue, | ||
| 171 | } | ||
| 172 | |||
| 173 | impl Tasks { | ||
| 174 | // clears and returns the `priority` task queue, if it is already cleared then returns the `last` task queue | ||
| 175 | pub fn pop(&mut self) -> Option<TaskQueue> { | ||
| 176 | if !self.priority.is_empty() { | ||
| 177 | return Some(mem::replace(&mut self.priority, TaskQueue::default())); | ||
| 178 | } | ||
| 179 | |||
| 180 | if !self.last.is_empty() { | ||
| 181 | return Some(mem::replace(&mut self.last, TaskQueue::default())); | ||
| 182 | } | ||
| 183 | |||
| 184 | None | ||
| 185 | } | ||
| 186 | } | ||
| 187 | |||
| 188 | impl Key for Tasks { | ||
| 189 | type Value = Self; | ||
| 190 | } | ||
src/global/traits/asurlstring.rs added +10
| @@ -0,0 +1,10 @@ | |||
| 1 | // A single URL param | ||
| 2 | pub trait AsUrlString { | ||
| 3 | const TAG: &'static str; | ||
| 4 | fn as_url_string(&self) -> String | ||
| 5 | where | ||
| 6 | Self: ToString, | ||
| 7 | { | ||
| 8 | format!("{}={}", Self::TAG, self.to_string()) | ||
| 9 | } | ||
| 10 | } | ||
src/global/traits/mod.rs added +1
| @@ -0,0 +1 @@ | |||
| 1 | pub mod asurlstring; | ||
src/init.rs added +62
| @@ -0,0 +1,62 @@ | |||
| 1 | use crate::{ | ||
| 2 | config::{ | ||
| 3 | AppearanceConfig, AppearanceConfigSerde, ConfigTrait, KeyBindingsConfig, MainConfig, | ||
| 4 | MinDimentions, PagesConfig, Search, | ||
| 5 | }, | ||
| 6 | global::{invidiousclient::InvidiousClient, message::Message, page::Page, tasks::Tasks}, | ||
| 7 | }; | ||
| 8 | use home::home_dir; | ||
| 9 | use std::{error::Error, fs}; | ||
| 10 | use tui_additions::framework::Framework; | ||
| 11 | |||
| 12 | // init tasks: | ||
| 13 | // - create folders like `~/.config/youtube-tui/` and `~/.cache/youtube-tui/thumbnails/` | ||
| 14 | // - load all config files | ||
| 15 | // - insert data | ||
| 16 | |||
| 17 | pub fn init(framework: &mut Framework) -> Result<(), Box<dyn Error>> { | ||
| 18 | // creating files | ||
| 19 | let home_dir = home_dir().unwrap(); | ||
| 20 | let config_path = home_dir.join(".config/youtube-tui/"); | ||
| 21 | let cache_path = home_dir.join(".cache/youtube-tui/"); | ||
| 22 | |||
| 23 | if !&config_path.exists() { | ||
| 24 | fs::create_dir_all(&config_path).unwrap(); | ||
| 25 | } | ||
| 26 | |||
| 27 | if !&cache_path.exists() { | ||
| 28 | fs::create_dir_all(&config_path).unwrap(); | ||
| 29 | } | ||
| 30 | |||
| 31 | // inserting data | ||
| 32 | let main_config = *MainConfig::load()?; | ||
| 33 | |||
| 34 | framework | ||
| 35 | .data | ||
| 36 | .global | ||
| 37 | .insert::<InvidiousClient>(InvidiousClient::new(main_config.invidious_instance.clone())); | ||
| 38 | framework | ||
| 39 | .data | ||
| 40 | .global | ||
| 41 | .insert::<AppearanceConfig>(AppearanceConfig::from(*AppearanceConfigSerde::load()?)); | ||
| 42 | framework.data.global.insert::<MainConfig>(main_config); | ||
| 43 | framework | ||
| 44 | .data | ||
| 45 | .global | ||
| 46 | .insert::<PagesConfig>(*PagesConfig::load()?); | ||
| 47 | framework | ||
| 48 | .data | ||
| 49 | .global | ||
| 50 | .insert::<KeyBindingsConfig>(*KeyBindingsConfig::load()?); | ||
| 51 | framework.data.global.insert::<Message>(Message::None); | ||
| 52 | |||
| 53 | framework.data.state.insert::<Tasks>(Tasks::default()); | ||
| 54 | framework.data.state.insert::<Page>(Page::default()); | ||
| 55 | framework.data.state.insert::<Search>(*Search::load()?); | ||
| 56 | framework | ||
| 57 | .data | ||
| 58 | .state | ||
| 59 | .insert::<MinDimentions>(MinDimentions::default()); | ||
| 60 | |||
| 61 | Ok(()) | ||
| 62 | } | ||
src/items/iteminfo.rs added +162
| @@ -0,0 +1,162 @@ | |||
| 1 | use tui::{ | ||
| 2 | layout::Rect, | ||
| 3 | style::Style, | ||
| 4 | widgets::{Paragraph, Wrap}, | ||
| 5 | }; | ||
| 6 | use tui_additions::framework::FrameworkItem; | ||
| 7 | use viuer::{print_from_file, Config}; | ||
| 8 | |||
| 9 | use crate::{ | ||
| 10 | config::{AppearanceConfig, MainConfig}, | ||
| 11 | global::item::Item, | ||
| 12 | }; | ||
| 13 | |||
| 14 | // an item info displays info of any `Item`s | ||
| 15 | #[derive(Clone)] | ||
| 16 | pub struct ItemInfo { | ||
| 17 | pub item: Option<Item>, | ||
| 18 | } | ||
| 19 | |||
| 20 | impl FrameworkItem for ItemInfo { | ||
| 21 | fn render( | ||
| 22 | &mut self, | ||
| 23 | frame: &mut tui::Frame<tui::backend::CrosstermBackend<std::io::Stdout>>, | ||
| 24 | framework: &mut tui_additions::framework::FrameworkClean, | ||
| 25 | area: tui::layout::Rect, | ||
| 26 | popup_render: bool, | ||
| 27 | _info: tui_additions::framework::ItemInfo, | ||
| 28 | ) { | ||
| 29 | if popup_render { | ||
| 30 | return; | ||
| 31 | } | ||
| 32 | |||
| 33 | let item = if let Some(item) = &self.item { | ||
| 34 | item | ||
| 35 | } else { | ||
| 36 | return; | ||
| 37 | }; | ||
| 38 | |||
| 39 | let main_config = framework.data.global.get::<MainConfig>().unwrap(); | ||
| 40 | let appearance = framework.data.global.get::<AppearanceConfig>().unwrap(); | ||
| 41 | |||
| 42 | // The scroll (space above) text info will be the height of the image, but if the image fail to display, the scroll will be 0 | ||
| 43 | let scroll = if main_config.images.display() { | ||
| 44 | let thumbnail_path = home::home_dir() | ||
| 45 | .unwrap() | ||
| 46 | .join(".cache/youtube-tui/thumbnails/") | ||
| 47 | .join(item.thumbnail_id()); | ||
| 48 | if thumbnail_path.exists() { | ||
| 49 | let config = Config { | ||
| 50 | width: Some(area.width as u32), | ||
| 51 | x: area.x, | ||
| 52 | y: area.y as i16, | ||
| 53 | use_sixel: main_config.images.use_sixels(), | ||
| 54 | ..Default::default() | ||
| 55 | }; | ||
| 56 | if let Ok((_, height)) = print_from_file(thumbnail_path, &config) { | ||
| 57 | height as u16 | ||
| 58 | } else { | ||
| 59 | 0 | ||
| 60 | } | ||
| 61 | } else { | ||
| 62 | 0 | ||
| 63 | } | ||
| 64 | } else { | ||
| 65 | 0 | ||
| 66 | }; | ||
| 67 | |||
| 68 | // Each "span" contains a string and a Style, and they are one line max each | ||
| 69 | // A "text" is used for descriptions in video/playlist and channels, and starts a new line if the old one runs out | ||
| 70 | let (spans, text) = match item { | ||
| 71 | Item::MiniVideo(minivideo) => { | ||
| 72 | let mut out = ( | ||
| 73 | vec![ | ||
| 74 | ( | ||
| 75 | String::from("[Video]"), | ||
| 76 | Style::default().fg(appearance.colors.item_info.tag), | ||
| 77 | ), | ||
| 78 | ( | ||
| 79 | minivideo.title.clone(), | ||
| 80 | Style::default().fg(appearance.colors.item_info.title), | ||
| 81 | ), | ||
| 82 | ( | ||
| 83 | format!("Uploaded by {}", minivideo.channel), | ||
| 84 | Style::default().fg(appearance.colors.item_info.author), | ||
| 85 | ), | ||
| 86 | ], | ||
| 87 | if let Some(description) = &minivideo.description { | ||
| 88 | Some(( | ||
| 89 | description.clone(), | ||
| 90 | Style::default().fg(appearance.colors.item_info.description), | ||
| 91 | )) | ||
| 92 | } else { | ||
| 93 | None | ||
| 94 | }, | ||
| 95 | ); | ||
| 96 | if let Some(views) = &minivideo.views { | ||
| 97 | out.0.push(( | ||
| 98 | format!("{} views", views), | ||
| 99 | Style::default().fg(appearance.colors.item_info.viewcount), | ||
| 100 | )); | ||
| 101 | } | ||
| 102 | out.0.extend(vec![ | ||
| 103 | ( | ||
| 104 | format!("Length: {}", minivideo.length), | ||
| 105 | Style::default().fg(appearance.colors.item_info.length), | ||
| 106 | ), | ||
| 107 | ( | ||
| 108 | format!("Published {}", minivideo.published), | ||
| 109 | Style::default().fg(appearance.colors.item_info.published), | ||
| 110 | ) | ||
| 111 | ].into_iter()); | ||
| 112 | out | ||
| 113 | } | ||
| 114 | }; | ||
| 115 | |||
| 116 | // puts each "span" in its own line | ||
| 117 | let mut y = if scroll >= area.height { 0 } else { scroll } + area.y; | ||
| 118 | let bottom = area.bottom(); | ||
| 119 | |||
| 120 | for (text, style) in spans.into_iter().take((bottom - y) as usize) { | ||
| 121 | let paragraph = Paragraph::new(text).style(style); | ||
| 122 | frame.render_widget( | ||
| 123 | paragraph, | ||
| 124 | Rect { | ||
| 125 | y, | ||
| 126 | height: 1, | ||
| 127 | ..area | ||
| 128 | }, | ||
| 129 | ); | ||
| 130 | y += 1; | ||
| 131 | } | ||
| 132 | |||
| 133 | if y > bottom || text.is_none() { | ||
| 134 | return; | ||
| 135 | } | ||
| 136 | |||
| 137 | // renders the "text" | ||
| 138 | let (text, style) = text.unwrap(); | ||
| 139 | if text.len() == 0 { | ||
| 140 | return; | ||
| 141 | } | ||
| 142 | let paragraph = Paragraph::new(format!("Description:\n{}", text)).style(style).wrap(Wrap { trim: true }); | ||
| 143 | frame.render_widget( | ||
| 144 | paragraph, | ||
| 145 | Rect { | ||
| 146 | y, | ||
| 147 | height: bottom - y, | ||
| 148 | ..area | ||
| 149 | }, | ||
| 150 | ); | ||
| 151 | } | ||
| 152 | |||
| 153 | fn selectable(&self) -> bool { | ||
| 154 | true | ||
| 155 | } | ||
| 156 | } | ||
| 157 | |||
| 158 | impl Default for ItemInfo { | ||
| 159 | fn default() -> Self { | ||
| 160 | Self { item: None } | ||
| 161 | } | ||
| 162 | } | ||
src/items/itemlist.rs added +226
| @@ -0,0 +1,226 @@ | |||
| 1 | use std::error::Error; | ||
| 2 | |||
| 3 | use tui::{layout::Constraint, style::Style}; | ||
| 4 | use tui_additions::{ | ||
| 5 | framework::{Framework, FrameworkItem}, | ||
| 6 | widgets::{Grid, TextList}, | ||
| 7 | }; | ||
| 8 | |||
| 9 | use super::ItemInfo; | ||
| 10 | use crate::{ | ||
| 11 | config::{AppearanceConfig, KeyBindingsConfig, MainConfig}, | ||
| 12 | global::{ | ||
| 13 | functions::download_all_images, | ||
| 14 | invidiousclient::InvidiousClient, | ||
| 15 | item::Item, | ||
| 16 | keyaction::KeyAction, | ||
| 17 | page::{MainMenuPage, Page}, | ||
| 18 | tasks::{Task, Tasks}, | ||
| 19 | }, | ||
| 20 | }; | ||
| 21 | |||
| 22 | // An item list displays a list of items | ||
| 23 | // It consists of a 1 x 2 grid, with the left cell displaying a text list, the right displaying item info of the currently hovered item | ||
| 24 | #[derive(Clone)] | ||
| 25 | pub struct ItemList { | ||
| 26 | pub info: ItemInfo, | ||
| 27 | pub items: Vec<Item>, | ||
| 28 | pub textlist: TextList, | ||
| 29 | pub grid: Grid, | ||
| 30 | } | ||
| 31 | |||
| 32 | impl ItemList { | ||
| 33 | pub fn new(framework: &mut Framework) -> Self { | ||
| 34 | Self { | ||
| 35 | info: ItemInfo::default(), | ||
| 36 | items: Vec::new(), | ||
| 37 | textlist: TextList::default() | ||
| 38 | .border_type( | ||
| 39 | framework | ||
| 40 | .data | ||
| 41 | .global | ||
| 42 | .get::<AppearanceConfig>() | ||
| 43 | .unwrap() | ||
| 44 | .borders, | ||
| 45 | ) | ||
| 46 | .ascii_only( | ||
| 47 | !framework | ||
| 48 | .data | ||
| 49 | .global | ||
| 50 | .get::<MainConfig>() | ||
| 51 | .unwrap() | ||
| 52 | .allow_unicode, | ||
| 53 | ) | ||
| 54 | .non_ascii_replace(' '), | ||
| 55 | grid: Grid::new( | ||
| 56 | vec![Constraint::Percentage(60), Constraint::Percentage(40)], | ||
| 57 | vec![Constraint::Percentage(100)], | ||
| 58 | ) | ||
| 59 | .unwrap(), | ||
| 60 | } | ||
| 61 | } | ||
| 62 | } | ||
| 63 | |||
| 64 | impl FrameworkItem for ItemList { | ||
| 65 | fn render( | ||
| 66 | &mut self, | ||
| 67 | frame: &mut tui::Frame<tui::backend::CrosstermBackend<std::io::Stdout>>, | ||
| 68 | framework: &mut tui_additions::framework::FrameworkClean, | ||
| 69 | area: tui::layout::Rect, | ||
| 70 | popup_render: bool, | ||
| 71 | info: tui_additions::framework::ItemInfo, | ||
| 72 | ) { | ||
| 73 | if popup_render { | ||
| 74 | return; | ||
| 75 | } | ||
| 76 | |||
| 77 | let appearance = framework.data.global.get::<AppearanceConfig>().unwrap(); | ||
| 78 | |||
| 79 | // creates the grid | ||
| 80 | self.grid.set_border_type(appearance.borders); | ||
| 81 | self.grid | ||
| 82 | .set_border_style(Style::default().fg(if info.hover { | ||
| 83 | appearance.colors.outline_hover | ||
| 84 | } else if info.selected { | ||
| 85 | appearance.colors.outline_selected | ||
| 86 | } else { | ||
| 87 | appearance.colors.outline | ||
| 88 | })); | ||
| 89 | |||
| 90 | let grid = self.grid.clone(); | ||
| 91 | let chunks = &grid.chunks(area).unwrap()[0]; | ||
| 92 | |||
| 93 | // creates the text list in cell (0, 1) | ||
| 94 | self.textlist.set_height(chunks[0].height); | ||
| 95 | self.textlist | ||
| 96 | .set_cursor_style(Style::default().fg(if info.selected { | ||
| 97 | appearance.colors.outline_hover | ||
| 98 | } else { | ||
| 99 | appearance.colors.outline_secondary | ||
| 100 | })); | ||
| 101 | |||
| 102 | let textlist = self.textlist.clone(); | ||
| 103 | |||
| 104 | frame.render_widget(grid, area); | ||
| 105 | frame.render_widget(textlist, chunks[0]); | ||
| 106 | |||
| 107 | // used the `.render()` function in self.info because it is an ItemInfo and impls FrameworkItem instead of Widget | ||
| 108 | self.info | ||
| 109 | .render(frame, framework, chunks[1], popup_render, info); | ||
| 110 | } | ||
| 111 | |||
| 112 | fn selectable(&self) -> bool { | ||
| 113 | true | ||
| 114 | } | ||
| 115 | |||
| 116 | fn load_item( | ||
| 117 | &mut self, | ||
| 118 | framework: &mut tui_additions::framework::FrameworkClean, | ||
| 119 | _info: tui_additions::framework::ItemInfo, | ||
| 120 | ) -> Result<(), Box<dyn Error>> { | ||
| 121 | let page = framework.data.state.get::<Page>().unwrap(); | ||
| 122 | let image_index = framework | ||
| 123 | .data | ||
| 124 | .global | ||
| 125 | .get::<MainConfig>() | ||
| 126 | .unwrap() | ||
| 127 | .image_index; | ||
| 128 | let client = &framework.data.global.get::<InvidiousClient>().unwrap().0; | ||
| 129 | |||
| 130 | // fetch the items using the invidious api | ||
| 131 | match page { | ||
| 132 | Page::MainMenu(MainMenuPage::Trending) => { | ||
| 133 | self.items = client | ||
| 134 | .trending(None)? | ||
| 135 | .videos | ||
| 136 | .into_iter() | ||
| 137 | .map(|item| Item::from_trending_video(item, image_index)) | ||
| 138 | .collect(); | ||
| 139 | } | ||
| 140 | Page::MainMenu(MainMenuPage::Popular) => { | ||
| 141 | self.items = client | ||
| 142 | .popular(None)? | ||
| 143 | .items | ||
| 144 | .into_iter() | ||
| 145 | .map(|item| Item::from_popular_item(item, image_index)) | ||
| 146 | .collect(); | ||
| 147 | } | ||
| 148 | Page::Search(search) => { | ||
| 149 | self.items = client | ||
| 150 | .search(Some(&search.to_string()))? | ||
| 151 | .items | ||
| 152 | .into_iter() | ||
| 153 | .map(|item| Item::from_search_item(item, image_index)) | ||
| 154 | .collect(); | ||
| 155 | } | ||
| 156 | } | ||
| 157 | |||
| 158 | // download thumbnails of all videos in the list | ||
| 159 | download_all_images(self.items.iter().map(|item| item.into()).collect()); | ||
| 160 | |||
| 161 | // update the items in text list | ||
| 162 | self.textlist.set_items(&self.items).unwrap(); | ||
| 163 | self.update(); | ||
| 164 | |||
| 165 | Ok(()) | ||
| 166 | } | ||
| 167 | |||
| 168 | fn key_event( | ||
| 169 | &mut self, | ||
| 170 | framework: &mut tui_additions::framework::FrameworkClean, | ||
| 171 | key: crossterm::event::KeyEvent, | ||
| 172 | _info: tui_additions::framework::ItemInfo, | ||
| 173 | ) -> Result<(), Box<dyn Error>> { | ||
| 174 | let action = if let Some(keyactions) = framework | ||
| 175 | .data | ||
| 176 | .global | ||
| 177 | .get::<KeyBindingsConfig>() | ||
| 178 | .unwrap() | ||
| 179 | .0 | ||
| 180 | .get(&key.code) | ||
| 181 | { | ||
| 182 | if let Some(action) = keyactions.get(&key.modifiers.bits()) { | ||
| 183 | *action | ||
| 184 | } else { | ||
| 185 | return Ok(()); | ||
| 186 | } | ||
| 187 | } else { | ||
| 188 | return Ok(()); | ||
| 189 | }; | ||
| 190 | |||
| 191 | // move the textlist cursor in the corresponding directions | ||
| 192 | let updated = match action { | ||
| 193 | KeyAction::MoveUp => self.textlist.up().is_ok(), | ||
| 194 | KeyAction::MoveDown => self.textlist.down().is_ok(), | ||
| 195 | KeyAction::MoveLeft => self.textlist.first().is_ok(), | ||
| 196 | KeyAction::MoveRight => self.textlist.last().is_ok(), | ||
| 197 | _ => false, | ||
| 198 | }; | ||
| 199 | |||
| 200 | // only create a render task if the key event actually changed something | ||
| 201 | if updated { | ||
| 202 | self.info.item = Some(self.items[self.textlist.selected].clone()); | ||
| 203 | framework | ||
| 204 | .data | ||
| 205 | .state | ||
| 206 | .get_mut::<Tasks>() | ||
| 207 | .unwrap() | ||
| 208 | .last | ||
| 209 | .push(Task::RenderAll); | ||
| 210 | } | ||
| 211 | |||
| 212 | Ok(()) | ||
| 213 | } | ||
| 214 | } | ||
| 215 | |||
| 216 | impl ItemList { | ||
| 217 | // change `self.item` to the currently selected item | ||
| 218 | pub fn update(&mut self) { | ||
| 219 | if self.items.len() == 0 { | ||
| 220 | self.info.item = None; | ||
| 221 | return; | ||
| 222 | } | ||
| 223 | |||
| 224 | self.info.item = Some(self.items[self.textlist.selected].clone()); | ||
| 225 | } | ||
| 226 | } | ||
src/items/messagebar.rs added +57
| @@ -0,0 +1,57 @@ | |||
| 1 | use crate::{ | ||
| 2 | config::{AppearanceConfig, MainConfig}, | ||
| 3 | global::message::Message, | ||
| 4 | }; | ||
| 5 | use tui::{ | ||
| 6 | style::Style, | ||
| 7 | widgets::{Block, Borders, Paragraph}, | ||
| 8 | }; | ||
| 9 | use tui_additions::framework::FrameworkItem; | ||
| 10 | |||
| 11 | #[derive(Clone, Copy, Default)] | ||
| 12 | pub struct MessageBar; | ||
| 13 | |||
| 14 | impl FrameworkItem for MessageBar { | ||
| 15 | fn render( | ||
| 16 | &mut self, | ||
| 17 | frame: &mut tui::Frame<tui::backend::CrosstermBackend<std::io::Stdout>>, | ||
| 18 | framework: &mut tui_additions::framework::FrameworkClean, | ||
| 19 | area: tui::layout::Rect, | ||
| 20 | popup_render: bool, | ||
| 21 | _info: tui_additions::framework::ItemInfo, | ||
| 22 | ) { | ||
| 23 | if popup_render { | ||
| 24 | return; | ||
| 25 | } | ||
| 26 | |||
| 27 | let appearance = framework.data.global.get::<AppearanceConfig>().unwrap(); | ||
| 28 | let message = framework.data.global.get::<Message>().unwrap(); | ||
| 29 | |||
| 30 | let block = Block::default() | ||
| 31 | .borders(Borders::ALL) | ||
| 32 | .border_type(appearance.borders) | ||
| 33 | .border_style(Style::default().fg(match message { | ||
| 34 | Message::None => appearance.colors.outline, | ||
| 35 | Message::Error(_) => appearance.colors.message_error_outline, | ||
| 36 | Message::Message(_) => appearance.colors.message_outline, | ||
| 37 | })); | ||
| 38 | |||
| 39 | let paragraph = Paragraph::new( | ||
| 40 | message.to_string( | ||
| 41 | &framework | ||
| 42 | .data | ||
| 43 | .global | ||
| 44 | .get::<MainConfig>() | ||
| 45 | .unwrap() | ||
| 46 | .message_bar_default, | ||
| 47 | ), | ||
| 48 | ) | ||
| 49 | .block(block); | ||
| 50 | |||
| 51 | frame.render_widget(paragraph, area); | ||
| 52 | } | ||
| 53 | |||
| 54 | fn selectable(&self) -> bool { | ||
| 55 | false | ||
| 56 | } | ||
| 57 | } | ||
src/items/mod.rs added +10
| @@ -0,0 +1,10 @@ | |||
| 1 | mod searchbar; | ||
| 2 | pub use searchbar::*; | ||
| 3 | mod messagebar; | ||
| 4 | pub use messagebar::*; | ||
| 5 | mod iteminfo; | ||
| 6 | pub use iteminfo::*; | ||
| 7 | mod itemlist; | ||
| 8 | pub use itemlist::*; | ||
| 9 | mod pagebutton; | ||
| 10 | pub use pagebutton::*; | ||
src/items/pagebutton.rs added +85
| @@ -0,0 +1,85 @@ | |||
| 1 | use crate::{ | ||
| 2 | config::AppearanceConfig, | ||
| 3 | global::{ | ||
| 4 | page::{MainMenuPage, Page}, | ||
| 5 | tasks::{Task, Tasks}, | ||
| 6 | }, | ||
| 7 | }; | ||
| 8 | use tui::{ | ||
| 9 | layout::Alignment, | ||
| 10 | style::Style, | ||
| 11 | widgets::{Block, Borders, Paragraph}, | ||
| 12 | }; | ||
| 13 | use tui_additions::framework::FrameworkItem; | ||
| 14 | |||
| 15 | // button that on press will go to another page instead of selecting it | ||
| 16 | #[derive(Clone, Copy)] | ||
| 17 | pub enum PageButton { | ||
| 18 | Trending, | ||
| 19 | Popular, | ||
| 20 | } | ||
| 21 | |||
| 22 | impl PageButton { | ||
| 23 | pub fn page(&self) -> Page { | ||
| 24 | match self { | ||
| 25 | Self::Trending => Page::MainMenu(MainMenuPage::Trending), | ||
| 26 | Self::Popular => Page::MainMenu(MainMenuPage::Popular), | ||
| 27 | } | ||
| 28 | } | ||
| 29 | } | ||
| 30 | |||
| 31 | impl ToString for PageButton { | ||
| 32 | fn to_string(&self) -> String { | ||
| 33 | match self { | ||
| 34 | Self::Popular => String::from("Popular"), | ||
| 35 | Self::Trending => String::from("Trending"), | ||
| 36 | } | ||
| 37 | } | ||
| 38 | } | ||
| 39 | |||
| 40 | impl FrameworkItem for PageButton { | ||
| 41 | // it is basically a paragraph (text) with borders | ||
| 42 | fn render( | ||
| 43 | &mut self, | ||
| 44 | frame: &mut tui::Frame<tui::backend::CrosstermBackend<std::io::Stdout>>, | ||
| 45 | framework: &mut tui_additions::framework::FrameworkClean, | ||
| 46 | area: tui::layout::Rect, | ||
| 47 | popup_render: bool, | ||
| 48 | info: tui_additions::framework::ItemInfo, | ||
| 49 | ) { | ||
| 50 | if popup_render { | ||
| 51 | return; | ||
| 52 | } | ||
| 53 | |||
| 54 | let appearance = framework.data.global.get::<AppearanceConfig>().unwrap(); | ||
| 55 | let same_page = &self.page() == framework.data.state.get::<Page>().unwrap(); | ||
| 56 | |||
| 57 | let block = Block::default() | ||
| 58 | .border_type(appearance.borders) | ||
| 59 | .border_style(Style::default().fg(if info.hover { | ||
| 60 | appearance.colors.outline_hover | ||
| 61 | } else if same_page { | ||
| 62 | appearance.colors.outline_secondary | ||
| 63 | } else { | ||
| 64 | appearance.colors.outline | ||
| 65 | })) | ||
| 66 | .borders(Borders::ALL); | ||
| 67 | let paragraph = Paragraph::new(self.to_string()) | ||
| 68 | .block(block) | ||
| 69 | .alignment(Alignment::Center); | ||
| 70 | |||
| 71 | frame.render_widget(paragraph, area); | ||
| 72 | } | ||
| 73 | |||
| 74 | // when selected creates a load page task, but returns false to show that it is not being selected | ||
| 75 | fn select(&mut self, framework: &mut tui_additions::framework::FrameworkClean) -> bool { | ||
| 76 | let tasks = framework.data.state.get_mut::<Tasks>().unwrap(); | ||
| 77 | tasks.priority.push(Task::LoadPage(self.page())); | ||
| 78 | |||
| 79 | false | ||
| 80 | } | ||
| 81 | |||
| 82 | fn selectable(&self) -> bool { | ||
| 83 | true | ||
| 84 | } | ||
| 85 | } | ||
src/items/searchbar.rs added +110
| @@ -0,0 +1,110 @@ | |||
| 1 | use std::error::Error; | ||
| 2 | |||
| 3 | use crate::{ | ||
| 4 | config::{AppearanceConfig, Search}, | ||
| 5 | global::{ | ||
| 6 | page::Page, | ||
| 7 | tasks::{Task, Tasks}, | ||
| 8 | }, | ||
| 9 | }; | ||
| 10 | use crossterm::event::KeyCode; | ||
| 11 | use tui::{ | ||
| 12 | layout::Alignment, | ||
| 13 | style::Style, | ||
| 14 | widgets::{Block, Borders}, | ||
| 15 | }; | ||
| 16 | use tui_additions::{framework::FrameworkItem, widgets::TextField}; | ||
| 17 | |||
| 18 | #[derive(Clone, Default)] | ||
| 19 | pub struct SearchBar { | ||
| 20 | pub text_field: TextField, | ||
| 21 | } | ||
| 22 | |||
| 23 | impl FrameworkItem for SearchBar { | ||
| 24 | // basically is a text field with borders | ||
| 25 | fn render( | ||
| 26 | &mut self, | ||
| 27 | frame: &mut tui::Frame<tui::backend::CrosstermBackend<std::io::Stdout>>, | ||
| 28 | framework: &mut tui_additions::framework::FrameworkClean, | ||
| 29 | area: tui::layout::Rect, | ||
| 30 | popup_render: bool, | ||
| 31 | info: tui_additions::framework::ItemInfo, | ||
| 32 | ) { | ||
| 33 | if popup_render { | ||
| 34 | return; | ||
| 35 | } | ||
| 36 | |||
| 37 | let appearance = framework.data.global.get::<AppearanceConfig>().unwrap(); | ||
| 38 | |||
| 39 | let block = Block::default() | ||
| 40 | .title("Search YouTube") | ||
| 41 | .title_alignment(Alignment::Center) | ||
| 42 | .borders(Borders::ALL) | ||
| 43 | .border_type(appearance.borders) | ||
| 44 | .border_style(Style::default().fg(if info.hover { | ||
| 45 | appearance.colors.outline_hover | ||
| 46 | } else if info.selected { | ||
| 47 | appearance.colors.outline_selected | ||
| 48 | } else { | ||
| 49 | appearance.colors.outline | ||
| 50 | })); | ||
| 51 | |||
| 52 | let inner = block.inner(area); | ||
| 53 | |||
| 54 | frame.render_widget(block, area); | ||
| 55 | |||
| 56 | self.text_field.set_width(inner.width); | ||
| 57 | |||
| 58 | frame.render_widget(self.text_field.clone(), inner); | ||
| 59 | } | ||
| 60 | |||
| 61 | // sets text field content to the curreny search query, thats it | ||
| 62 | // kinda pointless if it doesnt break anything gonna remove it | ||
| 63 | fn load_item( | ||
| 64 | &mut self, | ||
| 65 | framework: &mut tui_additions::framework::FrameworkClean, | ||
| 66 | _info: tui_additions::framework::ItemInfo, | ||
| 67 | ) -> Result<(), Box<dyn Error>> { | ||
| 68 | let search = framework.data.state.get::<Search>().unwrap().query.clone(); | ||
| 69 | self.text_field.content = search; | ||
| 70 | let _ = self.text_field.last(); | ||
| 71 | |||
| 72 | Ok(()) | ||
| 73 | } | ||
| 74 | |||
| 75 | fn key_event( | ||
| 76 | &mut self, | ||
| 77 | framework: &mut tui_additions::framework::FrameworkClean, | ||
| 78 | key: crossterm::event::KeyEvent, | ||
| 79 | _info: tui_additions::framework::ItemInfo, | ||
| 80 | ) -> Result<(), Box<dyn Error>> { | ||
| 81 | let updated = match key.code { | ||
| 82 | KeyCode::Backspace => self.text_field.remove(self.text_field.cursor).is_ok(), | ||
| 83 | KeyCode::Char(c) => self.text_field.push(c).is_ok(), | ||
| 84 | KeyCode::Up => self.text_field.first().is_ok(), | ||
| 85 | KeyCode::Down => self.text_field.last().is_ok(), | ||
| 86 | KeyCode::Right => self.text_field.right().is_ok(), | ||
| 87 | KeyCode::Left => self.text_field.left().is_ok(), | ||
| 88 | KeyCode::Enter => { | ||
| 89 | let mut search = framework.data.state.get::<Search>().unwrap().clone(); | ||
| 90 | search.query = self.text_field.content.clone(); | ||
| 91 | let tasks = framework.data.state.get_mut::<Tasks>().unwrap(); | ||
| 92 | tasks.priority.push(Task::LoadPage(Page::Search(search))); | ||
| 93 | false | ||
| 94 | } | ||
| 95 | _ => false, | ||
| 96 | }; | ||
| 97 | |||
| 98 | // only re-render screen if updated | ||
| 99 | if updated { | ||
| 100 | let tasks = framework.data.state.get_mut::<Tasks>().unwrap(); | ||
| 101 | tasks.priority.push(Task::RenderAll); | ||
| 102 | } | ||
| 103 | |||
| 104 | Ok(()) | ||
| 105 | } | ||
| 106 | |||
| 107 | fn selectable(&self) -> bool { | ||
| 108 | true | ||
| 109 | } | ||
| 110 | } | ||
src/lib.rs +10 −5
| @@ -1,5 +1,10 @@ | |||
| 1 | pub mod app; | 1 | pub mod config; |
| 2 | pub mod functions; | 2 | pub mod global; |
| 3 | pub mod structs; | 3 | pub mod items; |
| 4 | pub mod traits; | 4 | |
| 5 | pub mod widgets; | 5 | mod init; |
| 6 | pub use init::*; | ||
| 7 | mod run; | ||
| 8 | pub use run::*; | ||
| 9 | mod exit; | ||
| 10 | pub use exit::*; | ||
src/main.rs +20 −235
| @@ -1,22 +1,22 @@ | |||
| 1 | use crossterm::{ | 1 | use crossterm::{ |
| 2 | event::{self, DisableMouseCapture, EnableMouseCapture}, | 2 | event::{DisableMouseCapture, EnableMouseCapture}, |
| 3 | execute, | 3 | execute, |
| 4 | terminal::{disable_raw_mode, enable_raw_mode, EnterAlternateScreen, LeaveAlternateScreen}, | 4 | terminal::{disable_raw_mode, enable_raw_mode, EnterAlternateScreen, LeaveAlternateScreen}, |
| 5 | }; | 5 | }; |
| 6 | use std::{error::Error, fs, io, sync::mpsc::channel}; | 6 | use std::{error::Error, io}; |
| 7 | use tui::{ | 7 | use tui::{backend::CrosstermBackend, Terminal}; |
| 8 | backend::{Backend, CrosstermBackend}, | 8 | use tui_additions::framework::{Framework, State}; |
| 9 | Terminal, | 9 | use youtube_tui::{exit, init, run}; |
| 10 | }; | 10 | |
| 11 | use youtube_tui::{ | 11 | // stuff happening: |
| 12 | app::{app::App, config::Action}, | 12 | // 1. setup the terminal |
| 13 | structs::{Row, RowItem, State, MessageText}, | 13 | // 2. run() |
| 14 | }; | 14 | // 3. restore the terminal |
| 15 | 15 | // 4. unwrap errors | |
| 16 | fn main() -> Result<(), Box<dyn Error>> { | 16 | fn main() -> Result<(), Box<dyn Error>> { |
| 17 | init()?; | 17 | let state = State(Vec::new()); |
| 18 | 18 | let mut framework = Framework::new(state); | |
| 19 | let app = App::default(); | 19 | init(&mut framework)?; |
| 20 | 20 | ||
| 21 | enable_raw_mode()?; | 21 | enable_raw_mode()?; |
| 22 | let mut stdout = io::stdout(); | 22 | let mut stdout = io::stdout(); |
| @@ -24,235 +24,20 @@ fn main() -> Result<(), Box<dyn Error>> { | |||
| 24 | let backend = CrosstermBackend::new(stdout); | 24 | let backend = CrosstermBackend::new(stdout); |
| 25 | let mut terminal = Terminal::new(backend)?; | 25 | let mut terminal = Terminal::new(backend)?; |
| 26 | 26 | ||
| 27 | let res = run_app(&mut terminal, app); | 27 | let res = run(&mut terminal, framework); |
| 28 | 28 | ||
| 29 | disable_raw_mode()?; | ||
| 29 | execute!( | 30 | execute!( |
| 30 | terminal.backend_mut(), | 31 | terminal.backend_mut(), |
| 31 | LeaveAlternateScreen, | 32 | LeaveAlternateScreen, |
| 32 | DisableMouseCapture | 33 | DisableMouseCapture |
| 33 | )?; | 34 | )?; |
| 34 | disable_raw_mode()?; | 35 | terminal.show_cursor()?; |
| 35 | |||
| 36 | res?; | ||
| 37 | exit()?; | ||
| 38 | |||
| 39 | Ok(()) | ||
| 40 | } | ||
| 41 | |||
| 42 | fn run_app<B: Backend>(mut terminal: &mut Terminal<B>, mut app: App) -> Result<(), Box<dyn Error>> { | ||
| 43 | loop { | ||
| 44 | if app.render { | ||
| 45 | if app.term_clear { | ||
| 46 | terminal.clear()?; | ||
| 47 | app.term_clear = false; | ||
| 48 | } | ||
| 49 | let hold = ui(&mut terminal, app); | ||
| 50 | app = hold.0; | ||
| 51 | hold.1?; | ||
| 52 | } | ||
| 53 | |||
| 54 | if app.load { | ||
| 55 | app.message = MessageText::Text(app.page.message(&app.config)); | ||
| 56 | let mut watch_history = app.watch_history.clone(); | ||
| 57 | terminal.clear()?; | ||
| 58 | let hold = ui(&mut terminal, app); | ||
| 59 | app = hold.0; | ||
| 60 | hold.1?; | ||
| 61 | let mut new_state = Vec::new(); | ||
| 62 | for row in app.state.0.iter() { | ||
| 63 | let mut row_vec = Vec::new(); | ||
| 64 | for row_item in row.items.iter() { | ||
| 65 | match row_item.item.load_item(&app, &mut watch_history) { | ||
| 66 | Ok(new) => { | ||
| 67 | row_vec.push(RowItem { | ||
| 68 | item: new, | ||
| 69 | ..*row_item | ||
| 70 | }); | ||
| 71 | } | ||
| 72 | Err(e) => { | ||
| 73 | row_vec.push(RowItem { | ||
| 74 | item: row_item.item.clone(), | ||
| 75 | ..*row_item | ||
| 76 | }); | ||
| 77 | app.message = MessageText::Text(e.to_string()); | ||
| 78 | } | ||
| 79 | } | ||
| 80 | } | ||
| 81 | |||
| 82 | new_state.push(Row { | ||
| 83 | items: row_vec, | ||
| 84 | ..*row | ||
| 85 | }); | ||
| 86 | } | ||
| 87 | |||
| 88 | app.watch_history = watch_history; | ||
| 89 | app.state = State(new_state); | ||
| 90 | app.selectable = App::selectable(&app.state); | ||
| 91 | |||
| 92 | app.load = false; | ||
| 93 | terminal.clear()?; | ||
| 94 | let hold = ui(&mut terminal, app); | ||
| 95 | app = hold.0; | ||
| 96 | |||
| 97 | let selected = app.page_default(); | ||
| 98 | |||
| 99 | app.selected = selected; | ||
| 100 | app.hover = selected; | ||
| 101 | app.render = true; | ||
| 102 | } else { | ||
| 103 | match event::read()? { | ||
| 104 | event::Event::Key(key) => { | ||
| 105 | if app.selected.is_none() { | ||
| 106 | let action = match app.config.keybindings.0.get(&key) { | ||
| 107 | Some(action) => *action, | ||
| 108 | None => continue, | ||
| 109 | }; | ||
| 110 | match action { | ||
| 111 | Action::Exit => { | ||
| 112 | return Ok(()); | ||
| 113 | } | ||
| 114 | Action::Back => { | ||
| 115 | let holder = app.pop(); | ||
| 116 | app = holder.0; | ||
| 117 | if holder.1 { | ||
| 118 | terminal.clear()?; | ||
| 119 | } | ||
| 120 | app.render = true; | ||
| 121 | continue; | ||
| 122 | } | ||
| 123 | Action::ClearHistory => { | ||
| 124 | app.history = Vec::new(); | ||
| 125 | continue; | ||
| 126 | } | ||
| 127 | Action::Home => { | ||
| 128 | terminal.clear()?; | ||
| 129 | app.home(); | ||
| 130 | continue; | ||
| 131 | } | ||
| 132 | _ => {} | ||
| 133 | } | ||
| 134 | } | ||
| 135 | |||
| 136 | app = app.key_input(key); | ||
| 137 | app.render = true; | ||
| 138 | } | ||
| 139 | event::Event::Resize(_, _) => { | ||
| 140 | app.render = true; | ||
| 141 | } | ||
| 142 | _ => {} | ||
| 143 | } | ||
| 144 | } | ||
| 145 | } | ||
| 146 | } | ||
| 147 | |||
| 148 | fn ui<B: Backend>(terminal: &mut Terminal<B>, mut app: App) -> (App, Result<(), Box<dyn Error>>) { | ||
| 149 | let (send, recv) = channel(); | ||
| 150 | let res = terminal.draw(|mut frame| { | ||
| 151 | let app = app.render(&mut frame); | ||
| 152 | send.send(app).unwrap(); | ||
| 153 | }); | ||
| 154 | |||
| 155 | app = recv.recv().unwrap(); | ||
| 156 | |||
| 157 | app.message = MessageText::None; | ||
| 158 | app.render = false; | ||
| 159 | |||
| 160 | match res { | ||
| 161 | Ok(_) => (app, Ok(())), | ||
| 162 | Err(e) => (app, Err(Box::new(e))), | ||
| 163 | } | ||
| 164 | } | ||
| 165 | |||
| 166 | fn init() -> Result<(), Box<dyn Error>> { | ||
| 167 | let home_dir = home::home_dir().expect("Cannot get your home directory"); | ||
| 168 | |||
| 169 | let mut dir = home_dir.clone(); | ||
| 170 | |||
| 171 | dir.push(".cache"); | ||
| 172 | |||
| 173 | if !dir.exists() { | ||
| 174 | fs::create_dir(&dir)?; | ||
| 175 | } | ||
| 176 | 36 | ||
| 177 | dir.push("youtube-tui"); | 37 | let exit_res = exit(); |
| 178 | if dir.exists() { | ||
| 179 | fs::remove_dir_all(&dir)?; | ||
| 180 | } | ||
| 181 | 38 | ||
| 182 | fs::create_dir(&dir)?; | 39 | res?; |
| 183 | 40 | exit_res?; | |
| 184 | dir.push("thumbnails"); | ||
| 185 | |||
| 186 | if !dir.exists() { | ||
| 187 | fs::create_dir(&dir)?; | ||
| 188 | } | ||
| 189 | |||
| 190 | dir = home_dir.clone(); | ||
| 191 | |||
| 192 | dir.push(".config"); | ||
| 193 | |||
| 194 | if !dir.exists() { | ||
| 195 | fs::create_dir(&dir)?; | ||
| 196 | } | ||
| 197 | |||
| 198 | dir.push("youtube-tui"); | ||
| 199 | |||
| 200 | if !dir.exists() { | ||
| 201 | fs::create_dir(&dir)?; | ||
| 202 | } | ||
| 203 | |||
| 204 | dir = home_dir; | ||
| 205 | |||
| 206 | dir.push(".local"); | ||
| 207 | |||
| 208 | if !dir.exists() { | ||
| 209 | fs::create_dir(&dir)?; | ||
| 210 | } | ||
| 211 | |||
| 212 | dir.push("share"); | ||
| 213 | |||
| 214 | if !dir.exists() { | ||
| 215 | fs::create_dir(&dir)?; | ||
| 216 | } | ||
| 217 | |||
| 218 | dir.push("youtube-tui"); | ||
| 219 | |||
| 220 | if !dir.exists() { | ||
| 221 | fs::create_dir(&dir)?; | ||
| 222 | } | ||
| 223 | |||
| 224 | dir.push("watch_history"); | ||
| 225 | |||
| 226 | if !dir.exists() { | ||
| 227 | fs::create_dir(&dir)?; | ||
| 228 | } | ||
| 229 | |||
| 230 | dir.push("thumbnails"); | ||
| 231 | |||
| 232 | if !dir.exists() { | ||
| 233 | fs::create_dir(&dir)?; | ||
| 234 | } | ||
| 235 | |||
| 236 | dir.pop(); | ||
| 237 | |||
| 238 | dir.push("info"); | ||
| 239 | |||
| 240 | if !dir.exists() { | ||
| 241 | fs::create_dir(&dir)?; | ||
| 242 | } | ||
| 243 | |||
| 244 | Ok(()) | ||
| 245 | } | ||
| 246 | |||
| 247 | fn exit() -> Result<(), Box<dyn Error>> { | ||
| 248 | let mut dir = home::home_dir().expect("Cannot get your home directory"); | ||
| 249 | |||
| 250 | dir.push(".cache"); | ||
| 251 | dir.push("youtube-tui"); | ||
| 252 | |||
| 253 | if dir.exists() { | ||
| 254 | fs::remove_dir_all(&dir)?; | ||
| 255 | } | ||
| 256 | 41 | ||
| 257 | Ok(()) | 42 | Ok(()) |
| 258 | } | 43 | } |
src/run.rs added +115
| @@ -0,0 +1,115 @@ | |||
| 1 | use crossterm::event::{self, Event}; | ||
| 2 | use std::{error::Error, io::Stdout}; | ||
| 3 | use tui::{backend::CrosstermBackend, Terminal}; | ||
| 4 | use tui_additions::framework::{Framework, FrameworkDirection}; | ||
| 5 | |||
| 6 | use crate::{ | ||
| 7 | config::KeyBindingsConfig, | ||
| 8 | global::{ | ||
| 9 | keyaction::KeyAction, | ||
| 10 | message::Message, | ||
| 11 | page::{MainMenuPage, Page}, | ||
| 12 | tasks::{Task, Tasks}, | ||
| 13 | }, | ||
| 14 | }; | ||
| 15 | |||
| 16 | // the main event loop of the program | ||
| 17 | pub fn run( | ||
| 18 | terminal: &mut Terminal<CrosstermBackend<Stdout>>, | ||
| 19 | mut framework: Framework, | ||
| 20 | ) -> Result<(), Box<dyn Error>> { | ||
| 21 | // push the initial page load | ||
| 22 | framework | ||
| 23 | .data | ||
| 24 | .state | ||
| 25 | .get_mut::<Tasks>() | ||
| 26 | .unwrap() | ||
| 27 | .priority | ||
| 28 | .push(Task::LoadPage(Page::MainMenu(MainMenuPage::Trending))); | ||
| 29 | |||
| 30 | loop { | ||
| 31 | // repeat forever until all tasks are ran (and Tasks is cleared) | ||
| 32 | if let Some(tasks) = framework.data.state.get_mut::<Tasks>().unwrap().pop() { | ||
| 33 | tasks.run(&mut framework, terminal)?; | ||
| 34 | continue; | ||
| 35 | } | ||
| 36 | |||
| 37 | match event::read()? { | ||
| 38 | Event::Key(key) => { | ||
| 39 | // 1. get the corresponding action | ||
| 40 | // 2. check if action is deselect, if yes, deselect | ||
| 41 | // 3. check is anything is selected, if yes, run `.key_event()` with the key | ||
| 42 | // 4. if nothing is selected, do stuff like moving the cursor or exiting | ||
| 43 | |||
| 44 | let action = if let Some(keyactions) = framework | ||
| 45 | .data | ||
| 46 | .global | ||
| 47 | .get::<KeyBindingsConfig>() | ||
| 48 | .unwrap() | ||
| 49 | .0 | ||
| 50 | .get(&key.code) | ||
| 51 | { | ||
| 52 | if let Some(action) = keyactions.get(&key.modifiers.bits()) { | ||
| 53 | Some(*action) | ||
| 54 | } else { | ||
| 55 | None | ||
| 56 | } | ||
| 57 | } else { | ||
| 58 | None | ||
| 59 | }; | ||
| 60 | |||
| 61 | if action == Some(KeyAction::Deselect) { | ||
| 62 | let _ = framework.deselect(); | ||
| 63 | framework | ||
| 64 | .data | ||
| 65 | .state | ||
| 66 | .get_mut::<Tasks>() | ||
| 67 | .unwrap() | ||
| 68 | .priority | ||
| 69 | .push(Task::RenderAll); | ||
| 70 | } | ||
| 71 | |||
| 72 | if framework.is_selected() { | ||
| 73 | if let Err(e) = framework.key_input(key) { | ||
| 74 | *framework.data.global.get_mut::<Message>().unwrap() = | ||
| 75 | Message::Error(format!("{}", e)); | ||
| 76 | }; | ||
| 77 | } else if let Some(action) = action { | ||
| 78 | let mut render = true; | ||
| 79 | match action { | ||
| 80 | KeyAction::Exit => break, | ||
| 81 | KeyAction::MoveUp => framework.r#move(FrameworkDirection::Up)?, | ||
| 82 | KeyAction::MoveDown => framework.r#move(FrameworkDirection::Down)?, | ||
| 83 | KeyAction::MoveLeft => framework.r#move(FrameworkDirection::Left)?, | ||
| 84 | KeyAction::MoveRight => framework.r#move(FrameworkDirection::Right)?, | ||
| 85 | KeyAction::Select => { | ||
| 86 | let _ = framework.select(); | ||
| 87 | } | ||
| 88 | _ => render = false, | ||
| 89 | } | ||
| 90 | if render { | ||
| 91 | framework | ||
| 92 | .data | ||
| 93 | .state | ||
| 94 | .get_mut::<Tasks>() | ||
| 95 | .unwrap() | ||
| 96 | .priority | ||
| 97 | .push(Task::RenderAll); | ||
| 98 | } | ||
| 99 | } | ||
| 100 | } | ||
| 101 | // always render if there is a screen resize event | ||
| 102 | Event::Resize(_, _) => { | ||
| 103 | framework | ||
| 104 | .data | ||
| 105 | .state | ||
| 106 | .get_mut::<Tasks>() | ||
| 107 | .unwrap() | ||
| 108 | .priority | ||
| 109 | .push(Task::RenderAll); | ||
| 110 | } | ||
| 111 | _ => {} | ||
| 112 | } | ||
| 113 | } | ||
| 114 | Ok(()) | ||
| 115 | } | ||
src/structs/apphistory.rs deleted −45
| @@ -1,45 +0,0 @@ | |||
| 1 | use invidious::blocking::Client; | ||
| 2 | |||
| 3 | use crate::{app::app::App, structs::Page}; | ||
| 4 | |||
| 5 | use super::{SearchSettings, State, MessageText}; | ||
| 6 | |||
| 7 | #[derive(Clone)] | ||
| 8 | pub struct AppHistory { | ||
| 9 | pub page: Page, | ||
| 10 | pub state: State, // Item | ||
| 11 | pub selectable: Vec<Vec<(usize, usize)>>, | ||
| 12 | pub hover: Option<(usize, usize)>, // x, y | ||
| 13 | pub selected: Option<(usize, usize)>, | ||
| 14 | pub client: Client, | ||
| 15 | pub message: MessageText, | ||
| 16 | pub load: bool, | ||
| 17 | pub render: bool, | ||
| 18 | pub popup_focus: bool, | ||
| 19 | pub search_text: String, | ||
| 20 | pub search_settings: SearchSettings, | ||
| 21 | pub search_index: usize, | ||
| 22 | pub page_no: usize, | ||
| 23 | } | ||
| 24 | |||
| 25 | impl From<App> for AppHistory { | ||
| 26 | fn from(original: App) -> Self { | ||
| 27 | Self { | ||
| 28 | page: original.page, | ||
| 29 | state: original.state, | ||
| 30 | selectable: original.selectable, | ||
| 31 | hover: original.hover, | ||
| 32 | // selected: original.selected, | ||
| 33 | selected: original.selected, | ||
| 34 | client: original.client, | ||
| 35 | message: original.message, | ||
| 36 | load: original.load, | ||
| 37 | render: original.render, | ||
| 38 | popup_focus: original.popup_focus, | ||
| 39 | search_text: original.search_text, | ||
| 40 | search_settings: original.search_settings, | ||
| 41 | search_index: original.search_index, | ||
| 42 | page_no: original.page_no, | ||
| 43 | } | ||
| 44 | } | ||
| 45 | } | ||
src/structs/fullchannel.rs deleted −28
| @@ -1,28 +0,0 @@ | |||
| 1 | use invidious::structs::channel::Channel; | ||
| 2 | use serde::{Deserialize, Serialize}; | ||
| 3 | use thousands::Separable; | ||
| 4 | |||
| 5 | #[derive(Debug, Clone, Serialize, Deserialize)] | ||
| 6 | pub struct FullChannel { | ||
| 7 | pub author: String, | ||
| 8 | pub author_id: String, | ||
| 9 | pub author_url: String, | ||
| 10 | pub thumbnail: String, | ||
| 11 | pub description: String, | ||
| 12 | pub sub_count: String, | ||
| 13 | pub total_views: String, | ||
| 14 | } | ||
| 15 | |||
| 16 | impl From<Channel> for FullChannel { | ||
| 17 | fn from(original: Channel) -> Self { | ||
| 18 | Self { | ||
| 19 | author: original.author, | ||
| 20 | author_id: original.authorId, | ||
| 21 | author_url: original.authorUrl, | ||
| 22 | thumbnail: original.authorThumbnails[4].url.clone(), | ||
| 23 | description: original.description, | ||
| 24 | sub_count: original.subCount.separate_with_commas(), | ||
| 25 | total_views: original.totalViews.separate_with_commas(), | ||
| 26 | } | ||
| 27 | } | ||
| 28 | } | ||
src/structs/fullplaylist.rs deleted −46
| @@ -1,46 +0,0 @@ | |||
| 1 | use chrono::{DateTime, NaiveDateTime, Utc}; | ||
| 2 | use invidious::structs::universal::Playlist; | ||
| 3 | use serde::{Deserialize, Serialize}; | ||
| 4 | |||
| 5 | use super::MiniVideo; | ||
| 6 | |||
| 7 | #[derive(Debug, Clone, Serialize, Deserialize)] | ||
| 8 | pub struct FullPlayList { | ||
| 9 | pub title: String, | ||
| 10 | pub playlist_id: String, | ||
| 11 | pub video_count: usize, | ||
| 12 | pub views: usize, | ||
| 13 | pub updated: String, | ||
| 14 | pub thumbnail: Option<String>, | ||
| 15 | pub description: String, | ||
| 16 | pub author: String, | ||
| 17 | pub author_id: String, | ||
| 18 | pub videos: Vec<MiniVideo>, | ||
| 19 | } | ||
| 20 | |||
| 21 | impl From<Playlist> for FullPlayList { | ||
| 22 | fn from(original: Playlist) -> Self { | ||
| 23 | Self { | ||
| 24 | title: original.title, | ||
| 25 | playlist_id: original.playlistId, | ||
| 26 | video_count: original.videoCount as usize, | ||
| 27 | views: original.viewCount as usize, | ||
| 28 | updated: { | ||
| 29 | let datetime: DateTime<Utc> = DateTime::from_utc( | ||
| 30 | NaiveDateTime::from_timestamp(original.updated as i64, 0), | ||
| 31 | Utc, | ||
| 32 | ); | ||
| 33 | format!(" [{}]", datetime.format("%Y/%m/%d")) | ||
| 34 | }, | ||
| 35 | thumbnail: if original.videos.len() == 0 { | ||
| 36 | None | ||
| 37 | } else { | ||
| 38 | Some(original.videos[0].videoThumbnails[4].url.clone()) | ||
| 39 | }, | ||
| 40 | description: original.description, | ||
| 41 | author: original.author, | ||
| 42 | author_id: original.authorId, | ||
| 43 | videos: original.videos.into_iter().map(MiniVideo::from).collect(), | ||
| 44 | } | ||
| 45 | } | ||
| 46 | } | ||
src/structs/fullvideo.rs deleted −63
| @@ -1,63 +0,0 @@ | |||
| 1 | use chrono::{DateTime, NaiveDateTime, Utc}; | ||
| 2 | use invidious::structs::video::Video; | ||
| 3 | use serde::{Deserialize, Serialize}; | ||
| 4 | use thousands::Separable; | ||
| 5 | |||
| 6 | #[derive(Debug, Clone, Serialize, Deserialize)] | ||
| 7 | pub struct FullVideo { | ||
| 8 | pub title: String, | ||
| 9 | pub video_id: String, | ||
| 10 | pub video_thumbnail: String, | ||
| 11 | pub description: String, | ||
| 12 | pub views: String, | ||
| 13 | pub published: String, | ||
| 14 | pub nsfw: bool, | ||
| 15 | pub genre: String, | ||
| 16 | pub channel: String, | ||
| 17 | pub channel_id: String, | ||
| 18 | pub subcount: String, | ||
| 19 | pub length: String, | ||
| 20 | pub public: bool, | ||
| 21 | pub live: bool, | ||
| 22 | pub upcoming: bool, | ||
| 23 | pub recommendations: Vec<String>, | ||
| 24 | } | ||
| 25 | |||
| 26 | impl From<Video> for FullVideo { | ||
| 27 | fn from(original: Video) -> Self { | ||
| 28 | Self { | ||
| 29 | title: original.title, | ||
| 30 | video_id: original.videoId, | ||
| 31 | video_thumbnail: original.videoThumbnails[5].url.clone(), | ||
| 32 | description: original.description, | ||
| 33 | views: original.viewCount.separate_with_commas(), | ||
| 34 | published: format!( | ||
| 35 | "{}{}", | ||
| 36 | original.publishedText, | ||
| 37 | if Utc::now().timestamp() - original.published as i64 > 86400 { | ||
| 38 | let datetime: DateTime<Utc> = DateTime::from_utc( | ||
| 39 | NaiveDateTime::from_timestamp(original.published as i64, 0), | ||
| 40 | Utc, | ||
| 41 | ); | ||
| 42 | format!(" [{}]", datetime.format("%Y/%m/%d")) | ||
| 43 | } else { | ||
| 44 | String::new() | ||
| 45 | } | ||
| 46 | ), | ||
| 47 | nsfw: original.isFamilyFriendly, | ||
| 48 | genre: original.genre, | ||
| 49 | channel: original.author, | ||
| 50 | channel_id: original.authorId, | ||
| 51 | subcount: original.subCountText, | ||
| 52 | length: hrtime::from_sec_padded(original.lengthSeconds as u64), | ||
| 53 | public: original.isListed, | ||
| 54 | live: original.liveNow, | ||
| 55 | upcoming: original.isUpcoming, | ||
| 56 | recommendations: original | ||
| 57 | .recommendedVideos | ||
| 58 | .into_iter() | ||
| 59 | .map(|x| x.videoId) | ||
| 60 | .collect(), | ||
| 61 | } | ||
| 62 | } | ||
| 63 | } | ||
src/structs/listitem.rs deleted −84
| @@ -1,84 +0,0 @@ | |||
| 1 | use crate::structs::{FullVideo, MiniVideo}; | ||
| 2 | use serde::{Deserialize, Serialize}; | ||
| 3 | |||
| 4 | use super::{FullChannel, FullPlayList, MiniChannel, MiniPlayList}; | ||
| 5 | |||
| 6 | #[derive(Debug, Clone, Deserialize, Serialize)] | ||
| 7 | pub enum ListItem { | ||
| 8 | MiniVideo(MiniVideo), | ||
| 9 | FullVideo(FullVideo), | ||
| 10 | MiniPlayList(MiniPlayList), | ||
| 11 | FullPlayList(FullPlayList), | ||
| 12 | MiniChannel(MiniChannel), | ||
| 13 | FullChannel(FullChannel), | ||
| 14 | PageTurner(bool), // true: +1 | false: -1 | ||
| 15 | } | ||
| 16 | |||
| 17 | impl ListItem { | ||
| 18 | pub fn id(&self) -> String { | ||
| 19 | match self { | ||
| 20 | ListItem::MiniVideo(video) => video.video_id.clone(), | ||
| 21 | ListItem::FullVideo(video) => video.video_id.clone(), | ||
| 22 | ListItem::MiniPlayList(playlist) => playlist.playlist_id.clone(), | ||
| 23 | ListItem::FullPlayList(playlist) => playlist.playlist_id.clone(), | ||
| 24 | _ => { | ||
| 25 | unreachable!() | ||
| 26 | } | ||
| 27 | } | ||
| 28 | } | ||
| 29 | |||
| 30 | pub fn is_page_turner(&self) -> bool { | ||
| 31 | match self { | ||
| 32 | ListItem::PageTurner(_) => true, | ||
| 33 | _ => false, | ||
| 34 | } | ||
| 35 | } | ||
| 36 | |||
| 37 | pub fn to_string(&self) -> String { | ||
| 38 | match self { | ||
| 39 | ListItem::MiniVideo(video) => video | ||
| 40 | .title | ||
| 41 | .chars() | ||
| 42 | .into_iter() | ||
| 43 | .filter(|c| !c.is_ascii_control()) | ||
| 44 | .collect(), | ||
| 45 | ListItem::FullVideo(video) => video | ||
| 46 | .title | ||
| 47 | .chars() | ||
| 48 | .into_iter() | ||
| 49 | .filter(|c| !c.is_ascii_control()) | ||
| 50 | .collect(), | ||
| 51 | ListItem::MiniPlayList(playlist) => playlist | ||
| 52 | .title | ||
| 53 | .chars() | ||
| 54 | .into_iter() | ||
| 55 | .filter(|c| !c.is_ascii_control()) | ||
| 56 | .collect(), | ||
| 57 | ListItem::FullPlayList(playlist) => playlist | ||
| 58 | .title | ||
| 59 | .chars() | ||
| 60 | .into_iter() | ||
| 61 | .filter(|c| !c.is_ascii_control()) | ||
| 62 | .collect(), | ||
| 63 | ListItem::MiniChannel(channel) => channel | ||
| 64 | .author | ||
| 65 | .chars() | ||
| 66 | .into_iter() | ||
| 67 | .filter(|c| !c.is_ascii_control()) | ||
| 68 | .collect(), | ||
| 69 | ListItem::FullChannel(channel) => channel | ||
| 70 | .author | ||
| 71 | .chars() | ||
| 72 | .into_iter() | ||
| 73 | .filter(|c| !c.is_ascii_control()) | ||
| 74 | .collect(), | ||
| 75 | ListItem::PageTurner(turner) => { | ||
| 76 | if *turner { | ||
| 77 | String::from("Next Page") | ||
| 78 | } else { | ||
| 79 | String::from("Previous Page") | ||
| 80 | } | ||
| 81 | } | ||
| 82 | } | ||
| 83 | } | ||
| 84 | } | ||
src/structs/messagetext.rs deleted −22
| @@ -1,22 +0,0 @@ | |||
| 1 | #[derive(Clone, PartialEq, Eq)] | ||
| 2 | pub enum MessageText { | ||
| 3 | Command(String), | ||
| 4 | Text(String), | ||
| 5 | None, | ||
| 6 | } | ||
| 7 | |||
| 8 | impl ToString for MessageText { | ||
| 9 | fn to_string(&self) -> String { | ||
| 10 | match self { | ||
| 11 | Self::Command(cmd) => format!(":{}", cmd), | ||
| 12 | Self::Text(s) => s.clone(), | ||
| 13 | Self::None => String::from("All good :)"), | ||
| 14 | } | ||
| 15 | } | ||
| 16 | } | ||
| 17 | |||
| 18 | impl MessageText { | ||
| 19 | pub fn is_some(&self) -> bool{ | ||
| 20 | *self != Self::None | ||
| 21 | } | ||
| 22 | } | ||
src/structs/minichannel.rs deleted −41
| @@ -1,41 +0,0 @@ | |||
| 1 | use invidious::structs::hidden::SearchItem; | ||
| 2 | use serde::{Deserialize, Serialize}; | ||
| 3 | use thousands::Separable; | ||
| 4 | |||
| 5 | #[derive(Debug, Clone, Serialize, Deserialize)] | ||
| 6 | pub struct MiniChannel { | ||
| 7 | pub author: String, | ||
| 8 | pub author_url: String, | ||
| 9 | pub author_id: String, | ||
| 10 | pub thumbnail: String, | ||
| 11 | pub description: String, | ||
| 12 | pub sub_count: String, | ||
| 13 | pub video_count: String, | ||
| 14 | } | ||
| 15 | |||
| 16 | impl From<SearchItem> for MiniChannel { | ||
| 17 | fn from(original: SearchItem) -> Self { | ||
| 18 | match original { | ||
| 19 | SearchItem::Channel { | ||
| 20 | author, | ||
| 21 | authorId, | ||
| 22 | authorUrl, | ||
| 23 | authorThumbnails, | ||
| 24 | subCount, | ||
| 25 | videoCount, | ||
| 26 | description, | ||
| 27 | descriptionHtml: _, | ||
| 28 | } => Self { | ||
| 29 | author, | ||
| 30 | author_id: authorId, | ||
| 31 | author_url: authorUrl, | ||
| 32 | thumbnail: authorThumbnails[4].url.clone(), | ||
| 33 | description, | ||
| 34 | sub_count: subCount.separate_with_commas(), | ||
| 35 | video_count: videoCount.to_string(), | ||
| 36 | }, | ||
| 37 | |||
| 38 | _ => unreachable!(), | ||
| 39 | } | ||
| 40 | } | ||
| 41 | } | ||
src/structs/miniplaylist.rs deleted −63
| @@ -1,63 +0,0 @@ | |||
| 1 | use invidious::structs::hidden::{Playlist, SearchItem}; | ||
| 2 | use serde::{Deserialize, Serialize}; | ||
| 3 | |||
| 4 | #[derive(Debug, Clone, Deserialize, Serialize)] | ||
| 5 | pub struct MiniPlayList { | ||
| 6 | pub title: String, | ||
| 7 | pub playlist_id: String, | ||
| 8 | pub author: String, | ||
| 9 | pub author_id: String, | ||
| 10 | pub author_url: String, | ||
| 11 | pub video_count: usize, | ||
| 12 | pub thumbnail: Option<String>, | ||
| 13 | } | ||
| 14 | |||
| 15 | impl From<SearchItem> for MiniPlayList { | ||
| 16 | fn from(original: SearchItem) -> Self { | ||
| 17 | match original { | ||
| 18 | SearchItem::Playlist { | ||
| 19 | title, | ||
| 20 | playlistId, | ||
| 21 | author, | ||
| 22 | authorId, | ||
| 23 | authorUrl, | ||
| 24 | videoCount, | ||
| 25 | videos, | ||
| 26 | } => MiniPlayList { | ||
| 27 | title, | ||
| 28 | playlist_id: playlistId, | ||
| 29 | author, | ||
| 30 | author_id: authorId, | ||
| 31 | author_url: authorUrl, | ||
| 32 | video_count: videoCount as usize, | ||
| 33 | thumbnail: if videos.len() == 0 { | ||
| 34 | None | ||
| 35 | } else { | ||
| 36 | Some(videos[0].videoThumbnails[4].url.clone()) | ||
| 37 | }, | ||
| 38 | }, | ||
| 39 | |||
| 40 | _ => { | ||
| 41 | unreachable!() | ||
| 42 | } | ||
| 43 | } | ||
| 44 | } | ||
| 45 | } | ||
| 46 | |||
| 47 | impl From<Playlist> for MiniPlayList { | ||
| 48 | fn from(original: Playlist) -> Self { | ||
| 49 | Self { | ||
| 50 | title: original.title, | ||
| 51 | playlist_id: original.playlistId, | ||
| 52 | author: original.author, | ||
| 53 | author_id: original.authorId, | ||
| 54 | author_url: original.authorUrl, | ||
| 55 | video_count: original.videoCount as usize, | ||
| 56 | thumbnail: if original.videos.len() == 0 { | ||
| 57 | None | ||
| 58 | } else { | ||
| 59 | Some(original.videos[0].videoThumbnails[4].url.clone()) | ||
| 60 | }, | ||
| 61 | } | ||
| 62 | } | ||
| 63 | } | ||
src/structs/minivideo.rs deleted −167
| @@ -1,167 +0,0 @@ | |||
| 1 | use chrono::{prelude::*, Utc}; | ||
| 2 | use invidious::structs::hidden::{ | ||
| 3 | ChannelVideo, PlaylistItem, PopularItem, SearchItem, TrendingVideo, | ||
| 4 | }; | ||
| 5 | use serde::{Deserialize, Serialize}; | ||
| 6 | use thousands::Separable; | ||
| 7 | |||
| 8 | #[derive(Debug, Clone, Serialize, Deserialize)] | ||
| 9 | pub struct MiniVideo { | ||
| 10 | pub title: String, | ||
| 11 | pub video_id: String, | ||
| 12 | pub video_thumbnail: String, | ||
| 13 | pub length: String, | ||
| 14 | pub view_count: Option<String>, | ||
| 15 | pub author: String, | ||
| 16 | pub author_url: String, | ||
| 17 | pub published: Option<String>, | ||
| 18 | pub description: Option<String>, | ||
| 19 | } | ||
| 20 | |||
| 21 | impl From<TrendingVideo> for MiniVideo { | ||
| 22 | fn from(original: TrendingVideo) -> Self { | ||
| 23 | MiniVideo { | ||
| 24 | title: original.title, | ||
| 25 | video_id: original.videoId, | ||
| 26 | video_thumbnail: original.videoThumbnails[4].url.clone(), | ||
| 27 | length: hrtime::from_sec_padded(original.lengthSeconds as u64), | ||
| 28 | view_count: Some(original.viewCount.separate_with_commas()), | ||
| 29 | author: original.author, | ||
| 30 | author_url: original.authorUrl, | ||
| 31 | published: Some(format!( | ||
| 32 | "{}{}", | ||
| 33 | original.publishedText, | ||
| 34 | if Utc::now().timestamp() - original.published as i64 > 86400 { | ||
| 35 | let datetime: DateTime<Utc> = DateTime::from_utc( | ||
| 36 | NaiveDateTime::from_timestamp(original.published as i64, 0), | ||
| 37 | Utc, | ||
| 38 | ); | ||
| 39 | format!(" [{}]", datetime.format("%Y/%m/%d")) | ||
| 40 | } else { | ||
| 41 | String::new() | ||
| 42 | } | ||
| 43 | )), | ||
| 44 | description: Some(original.description), | ||
| 45 | } | ||
| 46 | } | ||
| 47 | } | ||
| 48 | |||
| 49 | impl From<PopularItem> for MiniVideo { | ||
| 50 | fn from(original: PopularItem) -> Self { | ||
| 51 | MiniVideo { | ||
| 52 | title: original.title, | ||
| 53 | video_id: original.videoId, | ||
| 54 | video_thumbnail: original.videoThumbnails[5].url.clone(), | ||
| 55 | length: hrtime::from_sec_padded(original.lengthSeconds as u64), | ||
| 56 | view_count: Some(original.viewCount.separate_with_commas()), | ||
| 57 | author: original.author, | ||
| 58 | author_url: original.authorUrl, | ||
| 59 | published: Some(format!( | ||
| 60 | "{}{}", | ||
| 61 | original.publishedText, | ||
| 62 | if Utc::now().timestamp() - original.published as i64 > 86400 { | ||
| 63 | let datetime: DateTime<Utc> = DateTime::from_utc( | ||
| 64 | NaiveDateTime::from_timestamp(original.published as i64, 0), | ||
| 65 | Utc, | ||
| 66 | ); | ||
| 67 | format!(" [{}]", datetime.format("%Y/%m/%d")) | ||
| 68 | } else { | ||
| 69 | String::new() | ||
| 70 | } | ||
| 71 | )), | ||
| 72 | description: None, | ||
| 73 | } | ||
| 74 | } | ||
| 75 | } | ||
| 76 | |||
| 77 | impl From<SearchItem> for MiniVideo { | ||
| 78 | fn from(original: SearchItem) -> Self { | ||
| 79 | match original { | ||
| 80 | SearchItem::Video { | ||
| 81 | title, | ||
| 82 | videoId, | ||
| 83 | author, | ||
| 84 | authorId: _, | ||
| 85 | authorUrl, | ||
| 86 | lengthSeconds, | ||
| 87 | videoThumbnails, | ||
| 88 | description, | ||
| 89 | descriptionHtml: _, | ||
| 90 | viewCount, | ||
| 91 | published, | ||
| 92 | publishedText, | ||
| 93 | liveNow: _, | ||
| 94 | paid: _, | ||
| 95 | premium: _, | ||
| 96 | } => MiniVideo { | ||
| 97 | title: title, | ||
| 98 | video_id: videoId, | ||
| 99 | video_thumbnail: videoThumbnails[0].url.clone(), | ||
| 100 | length: hrtime::from_sec_padded(lengthSeconds as u64), | ||
| 101 | view_count: Some(viewCount.separate_with_commas()), | ||
| 102 | author: author, | ||
| 103 | author_url: authorUrl, | ||
| 104 | published: Some(format!( | ||
| 105 | "{}{}", | ||
| 106 | publishedText, | ||
| 107 | if Utc::now().timestamp() - published as i64 > 86400 { | ||
| 108 | let datetime: DateTime<Utc> = DateTime::from_utc( | ||
| 109 | NaiveDateTime::from_timestamp(published as i64, 0), | ||
| 110 | Utc, | ||
| 111 | ); | ||
| 112 | format!(" [{}]", datetime.format("%Y/%m/%d")) | ||
| 113 | } else { | ||
| 114 | String::new() | ||
| 115 | } | ||
| 116 | )), | ||
| 117 | description: Some(description), | ||
| 118 | }, | ||
| 119 | |||
| 120 | _ => unreachable!(), | ||
| 121 | } | ||
| 122 | } | ||
| 123 | } | ||
| 124 | |||
| 125 | impl From<PlaylistItem> for MiniVideo { | ||
| 126 | fn from(original: PlaylistItem) -> Self { | ||
| 127 | MiniVideo { | ||
| 128 | title: original.title, | ||
| 129 | video_id: original.videoId, | ||
| 130 | video_thumbnail: original.videoThumbnails[4].url.clone(), | ||
| 131 | length: hrtime::from_sec_padded(original.lengthSeconds as u64), | ||
| 132 | view_count: None, | ||
| 133 | author: original.author, | ||
| 134 | author_url: original.authorUrl, | ||
| 135 | published: None, | ||
| 136 | description: None, | ||
| 137 | } | ||
| 138 | } | ||
| 139 | } | ||
| 140 | |||
| 141 | impl From<ChannelVideo> for MiniVideo { | ||
| 142 | fn from(original: ChannelVideo) -> Self { | ||
| 143 | MiniVideo { | ||
| 144 | title: original.title, | ||
| 145 | video_id: original.videoId, | ||
| 146 | video_thumbnail: original.videoThumbnails[4].url.clone(), | ||
| 147 | length: hrtime::from_sec_padded(original.lengthSeconds as u64), | ||
| 148 | view_count: Some(original.viewCount.separate_with_commas()), | ||
| 149 | author: original.author, | ||
| 150 | author_url: original.authorUrl, | ||
| 151 | published: Some(format!( | ||
| 152 | "{}{}", | ||
| 153 | original.publishedText, | ||
| 154 | if Utc::now().timestamp() - original.published as i64 > 86400 { | ||
| 155 | let datetime: DateTime<Utc> = DateTime::from_utc( | ||
| 156 | NaiveDateTime::from_timestamp(original.published as i64, 0), | ||
| 157 | Utc, | ||
| 158 | ); | ||
| 159 | format!(" [{}]", datetime.format("%Y/%m/%d")) | ||
| 160 | } else { | ||
| 161 | String::new() | ||
| 162 | } | ||
| 163 | )), | ||
| 164 | description: None, | ||
| 165 | } | ||
| 166 | } | ||
| 167 | } | ||
src/structs/mod.rs deleted −38
| @@ -1,38 +0,0 @@ | |||
| 1 | mod apphistory; | ||
| 2 | pub use apphistory::*; | ||
| 3 | |||
| 4 | mod page; | ||
| 5 | pub use page::*; | ||
| 6 | |||
| 7 | mod states; | ||
| 8 | pub use states::*; | ||
| 9 | |||
| 10 | mod listitem; | ||
| 11 | pub use listitem::*; | ||
| 12 | |||
| 13 | mod minivideo; | ||
| 14 | pub use minivideo::*; | ||
| 15 | |||
| 16 | mod fullvideo; | ||
| 17 | pub use fullvideo::*; | ||
| 18 | |||
| 19 | mod watchhistory; | ||
| 20 | pub use watchhistory::*; | ||
| 21 | |||
| 22 | mod search_settings; | ||
| 23 | pub use search_settings::*; | ||
| 24 | |||
| 25 | mod miniplaylist; | ||
| 26 | pub use miniplaylist::*; | ||
| 27 | |||
| 28 | mod fullplaylist; | ||
| 29 | pub use fullplaylist::*; | ||
| 30 | |||
| 31 | mod minichannel; | ||
| 32 | pub use minichannel::*; | ||
| 33 | |||
| 34 | mod fullchannel; | ||
| 35 | pub use fullchannel::*; | ||
| 36 | |||
| 37 | mod messagetext; | ||
| 38 | pub use messagetext::*; | ||
src/structs/page.rs deleted −38
| @@ -1,38 +0,0 @@ | |||
| 1 | use crate::app::{ | ||
| 2 | config::Config, | ||
| 3 | pages::{channel::ChannelPage, item_info::DisplayItem, main_menu::MainMenuSelector}, | ||
| 4 | }; | ||
| 5 | |||
| 6 | #[derive(Debug, PartialEq, Clone)] | ||
| 7 | pub enum Page { | ||
| 8 | MainMenu(MainMenuSelector), | ||
| 9 | ItemDisplay(DisplayItem), | ||
| 10 | Channel(ChannelPage, String), | ||
| 11 | Search, | ||
| 12 | } | ||
| 13 | |||
| 14 | impl Default for Page { | ||
| 15 | fn default() -> Self { | ||
| 16 | Self::MainMenu(MainMenuSelector::default()) | ||
| 17 | } | ||
| 18 | } | ||
| 19 | |||
| 20 | impl Page { | ||
| 21 | pub fn message(&self, config: &Config) -> String { | ||
| 22 | match self { | ||
| 23 | Self::MainMenu(_) => config.layouts.main_menu.message.clone(), | ||
| 24 | Self::ItemDisplay(_) => config.layouts.item_info.message.clone(), | ||
| 25 | Self::Channel(_, _) => config.layouts.channel.message.clone(), | ||
| 26 | Self::Search => config.layouts.search.message.clone(), | ||
| 27 | } | ||
| 28 | } | ||
| 29 | |||
| 30 | pub fn min(&self, config: &Config) -> (u16, u16) { | ||
| 31 | match self { | ||
| 32 | Self::MainMenu(_) => config.layouts.main_menu.min, | ||
| 33 | Self::ItemDisplay(_) => config.layouts.item_info.min, | ||
| 34 | Self::Channel(_, _) => config.layouts.channel.min, | ||
| 35 | Self::Search => config.layouts.search.min, | ||
| 36 | } | ||
| 37 | } | ||
| 38 | } | ||
src/structs/search_settings.rs deleted −395
| @@ -1,395 +0,0 @@ | |||
| 1 | use crossterm::event::KeyEvent; | ||
| 2 | |||
| 3 | use crate::{ | ||
| 4 | app::config::{Action, Config}, | ||
| 5 | widgets::text_list::TextList, | ||
| 6 | }; | ||
| 7 | |||
| 8 | #[derive(Debug, Clone)] | ||
| 9 | pub struct SearchSettings { | ||
| 10 | pub sort_by: SearchSettingsSortBy, | ||
| 11 | pub date: Option<SearchSettingsDate>, | ||
| 12 | pub duartion: Option<SearchSettingsDuration>, | ||
| 13 | pub r#type: Option<SearchSettingsType>, | ||
| 14 | |||
| 15 | pub row: bool, // left: true, right: false | ||
| 16 | |||
| 17 | pub text_list: TextList, | ||
| 18 | pub select_text_list: TextList, | ||
| 19 | } | ||
| 20 | |||
| 21 | impl Default for SearchSettings { | ||
| 22 | fn default() -> Self { | ||
| 23 | let mut text_list = TextList::default(); | ||
| 24 | text_list.items = vec![ | ||
| 25 | String::from("Sort by"), | ||
| 26 | String::from("Date"), | ||
| 27 | String::from("Duration"), | ||
| 28 | String::from("Type"), | ||
| 29 | String::from("Reset All"), | ||
| 30 | ]; | ||
| 31 | |||
| 32 | let mut out = SearchSettings { | ||
| 33 | sort_by: SearchSettingsSortBy::Relevance, | ||
| 34 | date: None, | ||
| 35 | duartion: None, | ||
| 36 | r#type: None, | ||
| 37 | |||
| 38 | row: true, | ||
| 39 | |||
| 40 | text_list, | ||
| 41 | select_text_list: TextList::default(), | ||
| 42 | }; | ||
| 43 | |||
| 44 | out.update_left(); | ||
| 45 | |||
| 46 | out | ||
| 47 | } | ||
| 48 | } | ||
| 49 | |||
| 50 | impl SearchSettings { | ||
| 51 | pub fn to_vec(self) -> Vec<String> { | ||
| 52 | let mut vec = vec![self.sort_by.as_url_string()]; | ||
| 53 | |||
| 54 | if let Some(date) = self.date { | ||
| 55 | vec.push(date.as_url_string()); | ||
| 56 | } | ||
| 57 | |||
| 58 | if let Some(duration) = self.duartion { | ||
| 59 | vec.push(duration.as_url_string()); | ||
| 60 | } | ||
| 61 | |||
| 62 | if let Some(r#type) = self.r#type { | ||
| 63 | vec.push(r#type.as_url_string()); | ||
| 64 | } | ||
| 65 | |||
| 66 | vec | ||
| 67 | } | ||
| 68 | |||
| 69 | pub fn key_input(&mut self, key: KeyEvent, config: &Config) { | ||
| 70 | let action = match config.keybindings.0.get(&key) { | ||
| 71 | Some(action) => *action, | ||
| 72 | None => return, | ||
| 73 | }; | ||
| 74 | |||
| 75 | match action { | ||
| 76 | Action::Up => { | ||
| 77 | if self.row { | ||
| 78 | self.text_list.up(); | ||
| 79 | self.update_left() | ||
| 80 | } else { | ||
| 81 | self.select_text_list.up(); | ||
| 82 | |||
| 83 | match self.text_list.selected { | ||
| 84 | 0 => { | ||
| 85 | self.sort_by = | ||
| 86 | SearchSettingsSortBy::index_to_value(self.select_text_list.selected) | ||
| 87 | } | ||
| 88 | 1 => { | ||
| 89 | self.date = | ||
| 90 | SearchSettingsDate::index_to_value(self.select_text_list.selected) | ||
| 91 | } | ||
| 92 | 2 => { | ||
| 93 | self.duartion = SearchSettingsDuration::index_to_value( | ||
| 94 | self.select_text_list.selected, | ||
| 95 | ) | ||
| 96 | } | ||
| 97 | 3 => { | ||
| 98 | self.r#type = | ||
| 99 | SearchSettingsType::index_to_value(self.select_text_list.selected) | ||
| 100 | } | ||
| 101 | _ => {} | ||
| 102 | } | ||
| 103 | } | ||
| 104 | } | ||
| 105 | Action::Down => { | ||
| 106 | if self.row { | ||
| 107 | self.text_list.down(); | ||
| 108 | self.update_left() | ||
| 109 | } else { | ||
| 110 | self.select_text_list.down(); | ||
| 111 | |||
| 112 | match self.text_list.selected { | ||
| 113 | 0 => { | ||
| 114 | self.sort_by = | ||
| 115 | SearchSettingsSortBy::index_to_value(self.select_text_list.selected) | ||
| 116 | } | ||
| 117 | 1 => { | ||
| 118 | self.date = | ||
| 119 | SearchSettingsDate::index_to_value(self.select_text_list.selected) | ||
| 120 | } | ||
| 121 | 2 => { | ||
| 122 | self.duartion = SearchSettingsDuration::index_to_value( | ||
| 123 | self.select_text_list.selected, | ||
| 124 | ) | ||
| 125 | } | ||
| 126 | 3 => { | ||
| 127 | self.r#type = | ||
| 128 | SearchSettingsType::index_to_value(self.select_text_list.selected) | ||
| 129 | } | ||
| 130 | _ => {} | ||
| 131 | } | ||
| 132 | } | ||
| 133 | } | ||
| 134 | Action::Left => { | ||
| 135 | self.row = true; | ||
| 136 | } | ||
| 137 | Action::Right => { | ||
| 138 | self.row = false; | ||
| 139 | } | ||
| 140 | Action::Select => { | ||
| 141 | if self.text_list.selected == 4 && !self.row { | ||
| 142 | *self = Self::default(); | ||
| 143 | self.text_list.selected = 4; | ||
| 144 | self.update_left(); | ||
| 145 | } else { | ||
| 146 | self.row = !self.row; | ||
| 147 | } | ||
| 148 | } | ||
| 149 | _ => {} | ||
| 150 | } | ||
| 151 | } | ||
| 152 | |||
| 153 | pub fn update_left(&mut self) { | ||
| 154 | match self.text_list.selected { | ||
| 155 | 0 => { | ||
| 156 | self.select_text_list.items = SearchSettingsSortBy::as_vec(); | ||
| 157 | self.select_text_list.selected = SearchSettingsSortBy::value_to_index(self.sort_by); | ||
| 158 | } | ||
| 159 | 1 => { | ||
| 160 | self.select_text_list.items = SearchSettingsDate::as_vec(); | ||
| 161 | self.select_text_list.selected = SearchSettingsDate::value_to_index(self.date); | ||
| 162 | } | ||
| 163 | 2 => { | ||
| 164 | self.select_text_list.items = SearchSettingsDuration::as_vec(); | ||
| 165 | self.select_text_list.selected = | ||
| 166 | SearchSettingsDuration::value_to_index(self.duartion); | ||
| 167 | } | ||
| 168 | 3 => { | ||
| 169 | self.select_text_list.items = SearchSettingsType::as_vec(); | ||
| 170 | self.select_text_list.selected = SearchSettingsType::value_to_index(self.r#type); | ||
| 171 | } | ||
| 172 | 4 => { | ||
| 173 | self.select_text_list.items = vec![String::from("Reset All")]; | ||
| 174 | self.select_text_list.selected = 0; | ||
| 175 | } | ||
| 176 | _ => {} | ||
| 177 | } | ||
| 178 | } | ||
| 179 | } | ||
| 180 | |||
| 181 | pub trait AsUrlString { | ||
| 182 | fn as_url_string(&self) -> String; | ||
| 183 | } | ||
| 184 | |||
| 185 | #[derive(Debug, Clone, Copy)] | ||
| 186 | pub enum SearchSettingsSortBy { | ||
| 187 | Relevance, | ||
| 188 | Rating, | ||
| 189 | Date, | ||
| 190 | ViewCount, | ||
| 191 | } | ||
| 192 | |||
| 193 | impl AsUrlString for SearchSettingsSortBy { | ||
| 194 | fn as_url_string(&self) -> String { | ||
| 195 | format!( | ||
| 196 | "sort={}", | ||
| 197 | match self { | ||
| 198 | SearchSettingsSortBy::Relevance => String::from("relevance"), | ||
| 199 | SearchSettingsSortBy::Rating => String::from("rating"), | ||
| 200 | SearchSettingsSortBy::Date => String::from("date"), | ||
| 201 | SearchSettingsSortBy::ViewCount => String::from("views"), | ||
| 202 | } | ||
| 203 | ) | ||
| 204 | } | ||
| 205 | } | ||
| 206 | |||
| 207 | impl SearchSettingsSortBy { | ||
| 208 | pub fn as_vec() -> Vec<String> { | ||
| 209 | vec![ | ||
| 210 | String::from("Relevance"), | ||
| 211 | String::from("Rating"), | ||
| 212 | String::from("Date"), | ||
| 213 | String::from("View Count"), | ||
| 214 | ] | ||
| 215 | } | ||
| 216 | |||
| 217 | pub fn index_to_value(index: usize) -> SearchSettingsSortBy { | ||
| 218 | match index { | ||
| 219 | 0 => SearchSettingsSortBy::Relevance, | ||
| 220 | 1 => SearchSettingsSortBy::Rating, | ||
| 221 | 2 => SearchSettingsSortBy::Date, | ||
| 222 | 3 => SearchSettingsSortBy::ViewCount, | ||
| 223 | _ => unreachable!(), | ||
| 224 | } | ||
| 225 | } | ||
| 226 | |||
| 227 | pub fn value_to_index(value: SearchSettingsSortBy) -> usize { | ||
| 228 | match value { | ||
| 229 | SearchSettingsSortBy::Relevance => 0, | ||
| 230 | SearchSettingsSortBy::Rating => 1, | ||
| 231 | SearchSettingsSortBy::Date => 2, | ||
| 232 | SearchSettingsSortBy::ViewCount => 3, | ||
| 233 | } | ||
| 234 | } | ||
| 235 | } | ||
| 236 | |||
| 237 | #[derive(Debug, Clone, Copy)] | ||
| 238 | pub enum SearchSettingsDate { | ||
| 239 | Hour, | ||
| 240 | Day, | ||
| 241 | Week, | ||
| 242 | Month, | ||
| 243 | Year, | ||
| 244 | } | ||
| 245 | |||
| 246 | impl AsUrlString for SearchSettingsDate { | ||
| 247 | fn as_url_string(&self) -> String { | ||
| 248 | format!( | ||
| 249 | "date={}", | ||
| 250 | match self { | ||
| 251 | SearchSettingsDate::Hour => String::from("hour"), | ||
| 252 | SearchSettingsDate::Day => String::from("today"), | ||
| 253 | SearchSettingsDate::Week => String::from("week"), | ||
| 254 | SearchSettingsDate::Month => String::from("month"), | ||
| 255 | SearchSettingsDate::Year => String::from("year"), | ||
| 256 | } | ||
| 257 | ) | ||
| 258 | } | ||
| 259 | } | ||
| 260 | |||
| 261 | impl SearchSettingsDate { | ||
| 262 | pub fn as_vec() -> Vec<String> { | ||
| 263 | vec![ | ||
| 264 | String::from("No Filter"), | ||
| 265 | String::from("Hour"), | ||
| 266 | String::from("Day"), | ||
| 267 | String::from("Week"), | ||
| 268 | String::from("Month"), | ||
| 269 | String::from("Year"), | ||
| 270 | ] | ||
| 271 | } | ||
| 272 | |||
| 273 | pub fn index_to_value(index: usize) -> Option<SearchSettingsDate> { | ||
| 274 | match index { | ||
| 275 | 0 => None, | ||
| 276 | 1 => Some(SearchSettingsDate::Hour), | ||
| 277 | 2 => Some(SearchSettingsDate::Day), | ||
| 278 | 3 => Some(SearchSettingsDate::Week), | ||
| 279 | 4 => Some(SearchSettingsDate::Month), | ||
| 280 | 5 => Some(SearchSettingsDate::Year), | ||
| 281 | _ => unreachable!(), | ||
| 282 | } | ||
| 283 | } | ||
| 284 | |||
| 285 | pub fn value_to_index(value: Option<SearchSettingsDate>) -> usize { | ||
| 286 | match value { | ||
| 287 | None => 0, | ||
| 288 | Some(SearchSettingsDate::Hour) => 1, | ||
| 289 | Some(SearchSettingsDate::Day) => 2, | ||
| 290 | Some(SearchSettingsDate::Week) => 3, | ||
| 291 | Some(SearchSettingsDate::Month) => 4, | ||
| 292 | Some(SearchSettingsDate::Year) => 5, | ||
| 293 | } | ||
| 294 | } | ||
| 295 | } | ||
| 296 | |||
| 297 | #[derive(Debug, Clone, Copy)] | ||
| 298 | pub enum SearchSettingsDuration { | ||
| 299 | Short, | ||
| 300 | Long, | ||
| 301 | } | ||
| 302 | |||
| 303 | impl AsUrlString for SearchSettingsDuration { | ||
| 304 | fn as_url_string(&self) -> String { | ||
| 305 | format!( | ||
| 306 | "duration={}", | ||
| 307 | match self { | ||
| 308 | SearchSettingsDuration::Short => String::from("short"), | ||
| 309 | SearchSettingsDuration::Long => String::from("long"), | ||
| 310 | } | ||
| 311 | ) | ||
| 312 | } | ||
| 313 | } | ||
| 314 | |||
| 315 | impl SearchSettingsDuration { | ||
| 316 | pub fn as_vec() -> Vec<String> { | ||
| 317 | vec![ | ||
| 318 | String::from("No Filter"), | ||
| 319 | String::from("Short"), | ||
| 320 | String::from("Long"), | ||
| 321 | ] | ||
| 322 | } | ||
| 323 | |||
| 324 | pub fn index_to_value(index: usize) -> Option<SearchSettingsDuration> { | ||
| 325 | match index { | ||
| 326 | 0 => None, | ||
| 327 | 1 => Some(SearchSettingsDuration::Short), | ||
| 328 | 2 => Some(SearchSettingsDuration::Long), | ||
| 329 | _ => unreachable!(), | ||
| 330 | } | ||
| 331 | } | ||
| 332 | |||
| 333 | pub fn value_to_index(value: Option<SearchSettingsDuration>) -> usize { | ||
| 334 | match value { | ||
| 335 | None => 0, | ||
| 336 | Some(SearchSettingsDuration::Short) => 1, | ||
| 337 | Some(SearchSettingsDuration::Long) => 2, | ||
| 338 | } | ||
| 339 | } | ||
| 340 | } | ||
| 341 | |||
| 342 | #[derive(Debug, Clone, Copy)] | ||
| 343 | pub enum SearchSettingsType { | ||
| 344 | Video, | ||
| 345 | Channel, | ||
| 346 | Playlist, | ||
| 347 | All, | ||
| 348 | } | ||
| 349 | |||
| 350 | impl AsUrlString for SearchSettingsType { | ||
| 351 | fn as_url_string(&self) -> String { | ||
| 352 | format!( | ||
| 353 | "type={}", | ||
| 354 | match self { | ||
| 355 | SearchSettingsType::Video => String::from("video"), | ||
| 356 | SearchSettingsType::Channel => String::from("channel"), | ||
| 357 | SearchSettingsType::Playlist => String::from("playlist"), | ||
| 358 | SearchSettingsType::All => String::from("all"), | ||
| 359 | } | ||
| 360 | ) | ||
| 361 | } | ||
| 362 | } | ||
| 363 | |||
| 364 | impl SearchSettingsType { | ||
| 365 | pub fn as_vec() -> Vec<String> { | ||
| 366 | vec![ | ||
| 367 | String::from("No Filter"), | ||
| 368 | String::from("Video"), | ||
| 369 | String::from("Channel"), | ||
| 370 | String::from("Playlist"), | ||
| 371 | String::from("All"), | ||
| 372 | ] | ||
| 373 | } | ||
| 374 | |||
| 375 | pub fn index_to_value(index: usize) -> Option<SearchSettingsType> { | ||
| 376 | match index { | ||
| 377 | 0 => None, | ||
| 378 | 1 => Some(SearchSettingsType::Video), | ||
| 379 | 2 => Some(SearchSettingsType::Channel), | ||
| 380 | 3 => Some(SearchSettingsType::Playlist), | ||
| 381 | 4 => Some(SearchSettingsType::All), | ||
| 382 | _ => unreachable!(), | ||
| 383 | } | ||
| 384 | } | ||
| 385 | |||
| 386 | pub fn value_to_index(value: Option<SearchSettingsType>) -> usize { | ||
| 387 | match value { | ||
| 388 | None => 0, | ||
| 389 | Some(SearchSettingsType::Video) => 1, | ||
| 390 | Some(SearchSettingsType::Channel) => 2, | ||
| 391 | Some(SearchSettingsType::Playlist) => 3, | ||
| 392 | Some(SearchSettingsType::All) => 4, | ||
| 393 | } | ||
| 394 | } | ||
| 395 | } | ||
src/structs/states.rs deleted −130
| @@ -1,130 +0,0 @@ | |||
| 1 | use crossterm::event::KeyEvent; | ||
| 2 | use std::error::Error; | ||
| 3 | use tui::{ | ||
| 4 | backend::Backend, | ||
| 5 | layout::{Constraint, Rect}, | ||
| 6 | Frame, | ||
| 7 | }; | ||
| 8 | |||
| 9 | use crate::{ | ||
| 10 | app::{ | ||
| 11 | app::{App, AppNoState}, | ||
| 12 | pages::{ | ||
| 13 | channel::ChannelItem, global::GlobalItem, item_info::ItemInfoItem, | ||
| 14 | main_menu::MainMenuItem, search::SearchItem, | ||
| 15 | }, | ||
| 16 | }, | ||
| 17 | traits::ItemTrait, | ||
| 18 | }; | ||
| 19 | |||
| 20 | use super::WatchHistory; | ||
| 21 | |||
| 22 | #[derive(Clone)] | ||
| 23 | pub struct State(pub Vec<Row>); | ||
| 24 | |||
| 25 | impl State { | ||
| 26 | pub fn reset(&mut self) { | ||
| 27 | for row in self.0.iter_mut() { | ||
| 28 | for rowitem in row.items.iter_mut() { | ||
| 29 | rowitem.item.reset(); | ||
| 30 | } | ||
| 31 | } | ||
| 32 | } | ||
| 33 | } | ||
| 34 | |||
| 35 | #[derive(Clone)] | ||
| 36 | pub enum Item { | ||
| 37 | Global(GlobalItem), | ||
| 38 | MainMenu(MainMenuItem), | ||
| 39 | ItemInfo(ItemInfoItem), | ||
| 40 | Search(SearchItem), | ||
| 41 | Channel(ChannelItem), | ||
| 42 | } | ||
| 43 | |||
| 44 | impl Item { | ||
| 45 | pub fn key_input(&mut self, key: KeyEvent, app: App) -> (bool, App) { | ||
| 46 | match self { | ||
| 47 | Item::Global(item) => item.key_input(key, app), | ||
| 48 | Item::MainMenu(item) => item.key_input(key, app), | ||
| 49 | Item::ItemInfo(item) => item.key_input(key, app), | ||
| 50 | Item::Search(item) => item.key_input(key, app), | ||
| 51 | Item::Channel(item) => item.key_input(key, app), | ||
| 52 | } | ||
| 53 | } | ||
| 54 | |||
| 55 | pub fn reset(&mut self) { | ||
| 56 | match self { | ||
| 57 | Item::Global(item) => item.reset(), | ||
| 58 | Item::MainMenu(item) => item.reset(), | ||
| 59 | Item::ItemInfo(item) => item.reset(), | ||
| 60 | Item::Search(item) => item.reset(), | ||
| 61 | Item::Channel(item) => item.reset(), | ||
| 62 | }; | ||
| 63 | } | ||
| 64 | |||
| 65 | pub fn render_item<B: Backend>( | ||
| 66 | &mut self, | ||
| 67 | frame: &mut Frame<B>, | ||
| 68 | rect: Rect, | ||
| 69 | app: AppNoState, | ||
| 70 | selected: bool, | ||
| 71 | hover: bool, | ||
| 72 | popup_focus: bool, | ||
| 73 | popup_render: bool, | ||
| 74 | ) -> (bool, AppNoState) { | ||
| 75 | match self { | ||
| 76 | Item::Global(item) => { | ||
| 77 | item.render_item(frame, rect, app, selected, hover, popup_focus, popup_render) | ||
| 78 | } | ||
| 79 | Item::MainMenu(item) => { | ||
| 80 | item.render_item(frame, rect, app, selected, hover, popup_focus, popup_render) | ||
| 81 | } | ||
| 82 | Item::ItemInfo(item) => { | ||
| 83 | item.render_item(frame, rect, app, selected, hover, popup_focus, popup_render) | ||
| 84 | } | ||
| 85 | Item::Search(item) => { | ||
| 86 | item.render_item(frame, rect, app, selected, hover, popup_focus, popup_render) | ||
| 87 | } | ||
| 88 | Item::Channel(item) => { | ||
| 89 | item.render_item(frame, rect, app, selected, hover, popup_focus, popup_render) | ||
| 90 | } | ||
| 91 | } | ||
| 92 | } | ||
| 93 | |||
| 94 | pub fn select(&mut self, app: App) -> (App, bool) { | ||
| 95 | match self { | ||
| 96 | Item::Global(item) => item.select(app), | ||
| 97 | Item::MainMenu(item) => item.select(app), | ||
| 98 | Item::ItemInfo(item) => item.select(app), | ||
| 99 | Item::Search(item) => item.select(app), | ||
| 100 | Item::Channel(item) => item.select(app), | ||
| 101 | } | ||
| 102 | } | ||
| 103 | |||
| 104 | pub fn load_item( | ||
| 105 | &self, | ||
| 106 | app: &App, | ||
| 107 | watchhistory: &mut WatchHistory, | ||
| 108 | ) -> Result<Self, Box<dyn Error>> { | ||
| 109 | match self { | ||
| 110 | Item::Global(item) => item.load_item(app, watchhistory), | ||
| 111 | Item::MainMenu(item) => item.load_item(app, watchhistory), | ||
| 112 | Item::ItemInfo(item) => item.load_item(app, watchhistory), | ||
| 113 | Item::Search(item) => item.load_item(app, watchhistory), | ||
| 114 | Item::Channel(item) => item.load_item(app, watchhistory), | ||
| 115 | } | ||
| 116 | } | ||
| 117 | } | ||
| 118 | |||
| 119 | #[derive(Clone)] | ||
| 120 | pub struct Row { | ||
| 121 | pub items: Vec<RowItem>, | ||
| 122 | pub centered: bool, | ||
| 123 | pub height: Constraint, | ||
| 124 | } | ||
| 125 | |||
| 126 | #[derive(Clone)] | ||
| 127 | pub struct RowItem { | ||
| 128 | pub item: Item, | ||
| 129 | pub constraint: Constraint, | ||
| 130 | } | ||
src/structs/watchhistory.rs deleted −114
| @@ -1,114 +0,0 @@ | |||
| 1 | use std::{collections::LinkedList, fs}; | ||
| 2 | |||
| 3 | use serde::{Deserialize, Serialize}; | ||
| 4 | |||
| 5 | use crate::app::config::Config; | ||
| 6 | |||
| 7 | use super::ListItem; | ||
| 8 | |||
| 9 | #[derive(Debug, Clone, Serialize, Deserialize)] | ||
| 10 | pub struct WatchHistory(pub LinkedList<ListItem>); | ||
| 11 | |||
| 12 | impl Default for WatchHistory { | ||
| 13 | fn default() -> Self { | ||
| 14 | WatchHistory(LinkedList::new()) | ||
| 15 | } | ||
| 16 | } | ||
| 17 | |||
| 18 | impl WatchHistory { | ||
| 19 | pub fn load() -> Self { | ||
| 20 | let mut dir = home::home_dir().expect("Cannot get your home directory"); | ||
| 21 | dir = dir.join(".local/share/youtube-tui/watch_history/watch_history.json"); | ||
| 22 | |||
| 23 | if !dir.exists() { | ||
| 24 | let out = Self::default(); | ||
| 25 | |||
| 26 | fs::write(dir, serde_json::to_string(&out).unwrap()) | ||
| 27 | .expect("Cannot write watch history"); | ||
| 28 | |||
| 29 | return out; | ||
| 30 | } | ||
| 31 | |||
| 32 | let contents = fs::read_to_string(dir).expect("Cannot read watch history file"); | ||
| 33 | |||
| 34 | serde_json::from_str(&contents).expect("Cannot parse watch history file") | ||
| 35 | } | ||
| 36 | |||
| 37 | pub fn push(&mut self, item: String, listitem: ListItem, config: &Config) { | ||
| 38 | if let Some(v) = self.0.front() { | ||
| 39 | if *v.id() == item { | ||
| 40 | return; | ||
| 41 | } | ||
| 42 | } | ||
| 43 | |||
| 44 | let home_dir = home::home_dir().expect("Cannot get your home directory"); | ||
| 45 | |||
| 46 | let mut original_dir = home_dir.join(".cache/youtube-tui/thumbnails"); | ||
| 47 | |||
| 48 | match &listitem { | ||
| 49 | ListItem::FullVideo(video) => { | ||
| 50 | let mut save_file = home_dir.join(".local/share/youtube-tui/watch_history/info"); | ||
| 51 | save_file.push(format!("{}.json", video.video_id)); | ||
| 52 | fs::write(save_file, serde_json::to_string(&listitem).unwrap()).unwrap(); | ||
| 53 | |||
| 54 | let file_name = format!("{}.png", video.video_id); | ||
| 55 | original_dir.push(file_name.clone()); | ||
| 56 | |||
| 57 | if original_dir.exists() { | ||
| 58 | let mut new_dir = | ||
| 59 | home_dir.join(".local/share/youtube-tui/watch_history/thumbnails"); | ||
| 60 | new_dir.push(file_name); | ||
| 61 | |||
| 62 | if !new_dir.exists() { | ||
| 63 | fs::copy(original_dir, new_dir).expect("Cannot copy thumbnail"); | ||
| 64 | } | ||
| 65 | } | ||
| 66 | } | ||
| 67 | |||
| 68 | ListItem::FullPlayList(playlist) => { | ||
| 69 | let mut save_file = home_dir.join(".local/share/youtube-tui/watch_history/info"); | ||
| 70 | save_file.push(format!("{}.json", playlist.playlist_id)); | ||
| 71 | fs::write(save_file, serde_json::to_string(&listitem).unwrap()).unwrap(); | ||
| 72 | |||
| 73 | let file_name = format!("{}.png", playlist.playlist_id); | ||
| 74 | original_dir.push(file_name.clone()); | ||
| 75 | |||
| 76 | if original_dir.exists() { | ||
| 77 | let mut new_dir = | ||
| 78 | home_dir.join(".local/share/youtube-tui/watch_history/thumbnails"); | ||
| 79 | new_dir.push(file_name); | ||
| 80 | |||
| 81 | if !new_dir.exists() { | ||
| 82 | fs::copy(original_dir, new_dir).expect("Cannot copy thumbnail"); | ||
| 83 | } | ||
| 84 | } | ||
| 85 | } | ||
| 86 | _ => {} | ||
| 87 | } | ||
| 88 | |||
| 89 | self.0.push_front(listitem); | ||
| 90 | |||
| 91 | if self.0.len() > config.main.max_watch_history { | ||
| 92 | let back = self.0.pop_back(); | ||
| 93 | if let Some(item) = back { | ||
| 94 | let id = item.id(); | ||
| 95 | let _ = fs::remove_file( | ||
| 96 | home_dir | ||
| 97 | .join(".local/share/youtube-tui/watch_history/info") | ||
| 98 | .join(format!("{}.json", id.clone())), | ||
| 99 | ); | ||
| 100 | let _ = fs::remove_file( | ||
| 101 | home_dir | ||
| 102 | .join(".local/share/youtube-tui/watch_history/thumbnails") | ||
| 103 | .join(format!("{}.png", id)), | ||
| 104 | ); | ||
| 105 | } | ||
| 106 | } | ||
| 107 | |||
| 108 | fs::write( | ||
| 109 | home_dir.join(".local/share/youtube-tui/watch_history/watch_history.json"), | ||
| 110 | serde_json::to_string(&self).unwrap(), | ||
| 111 | ) | ||
| 112 | .expect("Cannot write watch history"); | ||
| 113 | } | ||
| 114 | } | ||
src/traits/config.rs deleted −46
| @@ -1,46 +0,0 @@ | |||
| 1 | use serde::{de::DeserializeOwned, Serialize}; | ||
| 2 | use std::{ | ||
| 3 | error::Error, | ||
| 4 | fs::{self, rename}, | ||
| 5 | io::Write, | ||
| 6 | }; | ||
| 7 | |||
| 8 | pub trait ConfigItem<'a> { | ||
| 9 | type Struct: Serialize + DeserializeOwned + Clone + Default; | ||
| 10 | const FILE_NAME: &'static str; | ||
| 11 | |||
| 12 | fn load() -> Result<Self::Struct, Box<dyn Error>> | ||
| 13 | where | ||
| 14 | Self: Sized, | ||
| 15 | { | ||
| 16 | let mut config_path = home::home_dir().expect("Cannot get your home directory"); | ||
| 17 | let mut config = Self::Struct::default(); | ||
| 18 | config_path.push(".config"); | ||
| 19 | config_path.push("youtube-tui"); | ||
| 20 | config_path.push(Self::FILE_NAME); | ||
| 21 | |||
| 22 | if config_path.exists() { | ||
| 23 | let content = fs::read_to_string(config_path.as_os_str())?; | ||
| 24 | match serde_yaml::from_str(&content) { | ||
| 25 | Ok(config_from_str) => config = config_from_str, | ||
| 26 | Err(_) => { | ||
| 27 | let mut new_path = config_path.clone(); | ||
| 28 | new_path.pop(); | ||
| 29 | new_path.push(format!("{}.old", Self::FILE_NAME)); | ||
| 30 | |||
| 31 | rename(&config_path, &new_path)?; | ||
| 32 | } | ||
| 33 | } | ||
| 34 | } | ||
| 35 | |||
| 36 | let mut file = fs::OpenOptions::new() | ||
| 37 | .write(true) | ||
| 38 | .truncate(true) | ||
| 39 | .create(true) | ||
| 40 | .open(config_path.as_os_str())?; | ||
| 41 | |||
| 42 | write!(file, "{}", serde_yaml::to_string(&config)?)?; | ||
| 43 | |||
| 44 | Ok(config) | ||
| 45 | } | ||
| 46 | } | ||
src/traits/item.rs deleted −30
| @@ -1,30 +0,0 @@ | |||
| 1 | use std::error::Error; | ||
| 2 | |||
| 3 | use crate::{ | ||
| 4 | app::app::{App, AppNoState}, | ||
| 5 | structs::{Item, WatchHistory}, | ||
| 6 | }; | ||
| 7 | use crossterm::event::KeyEvent; | ||
| 8 | use tui::{backend::Backend, layout::Rect, Frame}; | ||
| 9 | |||
| 10 | pub trait ItemTrait { | ||
| 11 | fn key_input(&mut self, key: KeyEvent, app: App) -> (bool, App); | ||
| 12 | fn render_item<B: Backend>( | ||
| 13 | &mut self, | ||
| 14 | frame: &mut Frame<B>, | ||
| 15 | rect: Rect, | ||
| 16 | app: AppNoState, | ||
| 17 | selected: bool, | ||
| 18 | hover: bool, | ||
| 19 | popup_focus: bool, | ||
| 20 | popup_render: bool, | ||
| 21 | ) -> (bool, AppNoState); | ||
| 22 | fn select(&mut self, app: App) -> (App, bool); | ||
| 23 | fn selectable(&self) -> bool; | ||
| 24 | fn load_item( | ||
| 25 | &self, | ||
| 26 | app: &App, | ||
| 27 | watch_history: &mut WatchHistory, | ||
| 28 | ) -> Result<Item, Box<dyn Error>>; | ||
| 29 | fn reset(&mut self) {} | ||
| 30 | } | ||
src/traits/mod.rs deleted −8
| @@ -1,8 +0,0 @@ | |||
| 1 | mod item; | ||
| 2 | pub use item::*; | ||
| 3 | |||
| 4 | mod page; | ||
| 5 | pub use page::*; | ||
| 6 | |||
| 7 | mod config; | ||
| 8 | pub use config::*; | ||
src/traits/page.rs deleted −5
| @@ -1,5 +0,0 @@ | |||
| 1 | use crate::app::config::LayoutConfig; | ||
| 2 | |||
| 3 | pub trait PageTrait { | ||
| 4 | fn default() -> LayoutConfig; | ||
| 5 | } | ||
src/widgets/horizontal_split.rs deleted −168
| @@ -1,168 +0,0 @@ | |||
| 1 | use tui::{ | ||
| 2 | buffer::Buffer, | ||
| 3 | layout::Rect, | ||
| 4 | style::Style, | ||
| 5 | symbols::line::{ | ||
| 6 | HORIZONTAL, HORIZONTAL_DOWN, HORIZONTAL_UP, ROUNDED_BOTTOM_LEFT, ROUNDED_BOTTOM_RIGHT, | ||
| 7 | ROUNDED_TOP_LEFT, ROUNDED_TOP_RIGHT, VERTICAL, | ||
| 8 | }, | ||
| 9 | widgets::Widget, | ||
| 10 | }; | ||
| 11 | |||
| 12 | #[derive(Debug, Clone)] | ||
| 13 | pub struct HorizontalSplit { | ||
| 14 | pub percentages: Vec<usize>, | ||
| 15 | pub border_style: Style, | ||
| 16 | } | ||
| 17 | |||
| 18 | impl Widget for HorizontalSplit { | ||
| 19 | fn render(self, rect: Rect, buffer: &mut Buffer) { | ||
| 20 | let mut width_left = rect.width as usize; | ||
| 21 | |||
| 22 | let widths = self | ||
| 23 | .percentages | ||
| 24 | .iter() | ||
| 25 | .enumerate() | ||
| 26 | .map(|(i, p)| { | ||
| 27 | if i == self.percentages.len() - 1 { | ||
| 28 | return width_left; | ||
| 29 | } | ||
| 30 | let width = p * rect.width as usize / 100; | ||
| 31 | width_left -= width; | ||
| 32 | width | ||
| 33 | }) | ||
| 34 | .collect::<Vec<_>>(); | ||
| 35 | |||
| 36 | let mut top = String::new(); | ||
| 37 | let mut mid = String::new(); | ||
| 38 | let mut bottom = String::new(); | ||
| 39 | |||
| 40 | buffer.set_style(Rect { height: 1, ..rect }, self.border_style); | ||
| 41 | buffer.set_style( | ||
| 42 | Rect { | ||
| 43 | height: 1, | ||
| 44 | y: rect.y + rect.height - 1, | ||
| 45 | ..rect | ||
| 46 | }, | ||
| 47 | self.border_style, | ||
| 48 | ); | ||
| 49 | |||
| 50 | buffer.set_style( | ||
| 51 | Rect { | ||
| 52 | x: rect.x + rect.width - 1, | ||
| 53 | y: rect.y + 1, | ||
| 54 | width: 1, | ||
| 55 | height: rect.height - 2, | ||
| 56 | }, | ||
| 57 | self.border_style, | ||
| 58 | ); | ||
| 59 | |||
| 60 | let mut x = rect.x; | ||
| 61 | |||
| 62 | for (index, width) in widths.iter().enumerate() { | ||
| 63 | buffer.set_style( | ||
| 64 | Rect { | ||
| 65 | x, | ||
| 66 | y: rect.y + 1, | ||
| 67 | width: 1, | ||
| 68 | height: rect.height - 2, | ||
| 69 | }, | ||
| 70 | self.border_style, | ||
| 71 | ); | ||
| 72 | |||
| 73 | x += *width as u16; | ||
| 74 | |||
| 75 | if index == 0 { | ||
| 76 | top.push_str(ROUNDED_TOP_LEFT); | ||
| 77 | bottom.push_str(ROUNDED_BOTTOM_LEFT); | ||
| 78 | } else { | ||
| 79 | top.push_str(HORIZONTAL_DOWN); | ||
| 80 | bottom.push_str(HORIZONTAL_UP); | ||
| 81 | } | ||
| 82 | |||
| 83 | mid.push_str(VERTICAL); | ||
| 84 | |||
| 85 | if index == widths.len() - 1 { | ||
| 86 | top.push_str(&HORIZONTAL.repeat(*width - 2)); | ||
| 87 | mid.push_str(&" ".repeat(*width - 2)); | ||
| 88 | bottom.push_str(&HORIZONTAL.repeat(*width - 2)); | ||
| 89 | |||
| 90 | top.push_str(ROUNDED_TOP_RIGHT); | ||
| 91 | mid.push_str(VERTICAL); | ||
| 92 | bottom.push_str(ROUNDED_BOTTOM_RIGHT); | ||
| 93 | } else { | ||
| 94 | top.push_str(&HORIZONTAL.repeat(*width - 1)); | ||
| 95 | mid.push_str(&" ".repeat(*width - 1)); | ||
| 96 | bottom.push_str(&HORIZONTAL.repeat(*width - 1)); | ||
| 97 | } | ||
| 98 | } | ||
| 99 | |||
| 100 | buffer.set_string(rect.x, rect.y, &top, Style::default()); | ||
| 101 | |||
| 102 | for y in rect.y + 1..rect.y + rect.height - 1 { | ||
| 103 | buffer.set_string(rect.x, y, &mid, Style::default()); | ||
| 104 | } | ||
| 105 | |||
| 106 | buffer.set_string(rect.x, rect.y + rect.height - 1, &bottom, Style::default()); | ||
| 107 | } | ||
| 108 | } | ||
| 109 | |||
| 110 | impl Default for HorizontalSplit { | ||
| 111 | fn default() -> Self { | ||
| 112 | HorizontalSplit { | ||
| 113 | percentages: vec![50, 50], | ||
| 114 | border_style: Style::default(), | ||
| 115 | } | ||
| 116 | } | ||
| 117 | } | ||
| 118 | |||
| 119 | impl HorizontalSplit { | ||
| 120 | pub fn inner(&self, rect: Rect) -> Vec<Rect> { | ||
| 121 | let mut width_left = rect.width as usize; | ||
| 122 | |||
| 123 | let widths = self | ||
| 124 | .percentages | ||
| 125 | .iter() | ||
| 126 | .enumerate() | ||
| 127 | .map(|(i, p)| { | ||
| 128 | if i == self.percentages.len() - 1 { | ||
| 129 | return width_left; | ||
| 130 | } | ||
| 131 | let width = p * rect.width as usize / 100; | ||
| 132 | width_left -= width; | ||
| 133 | width | ||
| 134 | }) | ||
| 135 | .collect::<Vec<_>>(); | ||
| 136 | |||
| 137 | let mut x = rect.x as usize + 1; | ||
| 138 | |||
| 139 | widths | ||
| 140 | .iter() | ||
| 141 | .enumerate() | ||
| 142 | .map(|(i, width)| { | ||
| 143 | let cell_rect = Rect { | ||
| 144 | x: x as u16, | ||
| 145 | y: rect.y + 1, | ||
| 146 | width: *width as u16 - if i == widths.len() - 1 { 2 } else { 1 }, | ||
| 147 | height: rect.height - 2, | ||
| 148 | }; | ||
| 149 | x += width; | ||
| 150 | cell_rect | ||
| 151 | }) | ||
| 152 | .collect::<Vec<_>>() | ||
| 153 | } | ||
| 154 | |||
| 155 | pub fn percentages(self, percentages: Vec<usize>) -> Self { | ||
| 156 | Self { | ||
| 157 | percentages, | ||
| 158 | ..self | ||
| 159 | } | ||
| 160 | } | ||
| 161 | |||
| 162 | pub fn border_style(self, border_style: Style) -> Self { | ||
| 163 | Self { | ||
| 164 | border_style, | ||
| 165 | ..self | ||
| 166 | } | ||
| 167 | } | ||
| 168 | } | ||
src/widgets/item_display.rs deleted −522
| @@ -1,522 +0,0 @@ | |||
| 1 | use tui::{ | ||
| 2 | buffer::Buffer, | ||
| 3 | layout::{Alignment, Rect}, | ||
| 4 | style::{Color, Style}, | ||
| 5 | widgets::{Paragraph, Widget, Wrap}, | ||
| 6 | }; | ||
| 7 | use viuer::{print_from_file, Config}; | ||
| 8 | |||
| 9 | use crate::structs::ListItem; | ||
| 10 | |||
| 11 | #[derive(Clone)] | ||
| 12 | pub struct ItemDisplay { | ||
| 13 | pub item: ListItem, | ||
| 14 | pub render_image: bool, | ||
| 15 | } | ||
| 16 | |||
| 17 | impl Widget for ItemDisplay { | ||
| 18 | fn render(self, area: Rect, buf: &mut Buffer) { | ||
| 19 | match self.item { | ||
| 20 | ListItem::MiniChannel(channel) => { | ||
| 21 | let mut path = home::home_dir().expect("Cannot get your home directory"); | ||
| 22 | path.push(".cache"); | ||
| 23 | path.push("youtube-tui"); | ||
| 24 | path.push("thumbnails"); | ||
| 25 | path.push(format!("{}.png", channel.author_id)); | ||
| 26 | |||
| 27 | let exists = path.exists(); | ||
| 28 | let mut image_transform = area; | ||
| 29 | if exists { | ||
| 30 | if image_transform.width * 2 > image_transform.height { | ||
| 31 | image_transform.width = image_transform.height / 2; | ||
| 32 | } | ||
| 33 | image_transform.height = image_transform.width / 2; | ||
| 34 | // image_transform.width = image_transform.height * 2; | ||
| 35 | |||
| 36 | let conf = Config { | ||
| 37 | width: Some(image_transform.width as u32), | ||
| 38 | height: Some(image_transform.height as u32), | ||
| 39 | x: image_transform.x, | ||
| 40 | y: image_transform.y as i16, | ||
| 41 | ..Default::default() | ||
| 42 | }; | ||
| 43 | |||
| 44 | if self.render_image { | ||
| 45 | let _ = print_from_file(path.as_os_str(), &conf); | ||
| 46 | } | ||
| 47 | } | ||
| 48 | |||
| 49 | let mut y = if exists { | ||
| 50 | image_transform.y + image_transform.height | ||
| 51 | } else { | ||
| 52 | area.y | ||
| 53 | }; | ||
| 54 | |||
| 55 | let mut to_print = Vec::new(); | ||
| 56 | to_print.push((String::from("[Channel]"), Style::default().fg(Color::Gray))); | ||
| 57 | to_print.push((channel.author, Style::default().fg(Color::LightBlue))); | ||
| 58 | to_print.push(( | ||
| 59 | format!("Subscribers: {}", channel.sub_count), | ||
| 60 | Style::default().fg(Color::LightYellow), | ||
| 61 | )); | ||
| 62 | to_print.push(( | ||
| 63 | format!("Video Count: {}", channel.video_count), | ||
| 64 | Style::default().fg(Color::LightCyan), | ||
| 65 | )); | ||
| 66 | |||
| 67 | to_print.push(( | ||
| 68 | String::from("Description: "), | ||
| 69 | Style::default().fg(Color::Gray), | ||
| 70 | )); | ||
| 71 | |||
| 72 | for (mut item, style) in to_print { | ||
| 73 | if y > area.height + area.y - 1 { | ||
| 74 | return; | ||
| 75 | } | ||
| 76 | |||
| 77 | if item.len() > area.width as usize { | ||
| 78 | item = format!("{}...", &item[..area.width as usize - 3]); | ||
| 79 | } | ||
| 80 | buf.set_string(area.x, y, item, style); | ||
| 81 | y += 1; | ||
| 82 | } | ||
| 83 | |||
| 84 | if y < area.height + area.y { | ||
| 85 | let rect = Rect { | ||
| 86 | x: area.x, | ||
| 87 | y, | ||
| 88 | width: area.width, | ||
| 89 | height: area.height + area.y - y, | ||
| 90 | }; | ||
| 91 | |||
| 92 | let paragraph = Paragraph::new(channel.description.clone()) | ||
| 93 | .wrap(Wrap { trim: true }) | ||
| 94 | .alignment(Alignment::Left) | ||
| 95 | .style(Style::default().fg(Color::Gray)); | ||
| 96 | |||
| 97 | paragraph.render(rect, buf); | ||
| 98 | } | ||
| 99 | } | ||
| 100 | ListItem::FullChannel(channel) => { | ||
| 101 | let mut path = home::home_dir().expect("Cannot get your home directory"); | ||
| 102 | path.push(".cache"); | ||
| 103 | path.push("youtube-tui"); | ||
| 104 | path.push("thumbnails"); | ||
| 105 | path.push(format!("{}.png", channel.author_id)); | ||
| 106 | |||
| 107 | let exists = path.exists(); | ||
| 108 | let mut image_transform = area; | ||
| 109 | if exists { | ||
| 110 | image_transform.height = image_transform.width * 9 / 64; | ||
| 111 | image_transform.width = image_transform.height * 2; | ||
| 112 | |||
| 113 | let conf = Config { | ||
| 114 | width: Some(image_transform.width as u32), | ||
| 115 | height: Some(image_transform.height as u32), | ||
| 116 | x: image_transform.x, | ||
| 117 | y: image_transform.y as i16, | ||
| 118 | ..Default::default() | ||
| 119 | }; | ||
| 120 | if self.render_image { | ||
| 121 | let _ = print_from_file(path.as_os_str(), &conf); | ||
| 122 | } | ||
| 123 | } | ||
| 124 | |||
| 125 | let mut y = if exists { | ||
| 126 | image_transform.y + image_transform.height | ||
| 127 | } else { | ||
| 128 | area.y | ||
| 129 | }; | ||
| 130 | |||
| 131 | let mut to_print = Vec::new(); | ||
| 132 | to_print.push((String::from("[Channel]"), Style::default().fg(Color::Gray))); | ||
| 133 | to_print.push((channel.author, Style::default().fg(Color::LightBlue))); | ||
| 134 | to_print.push(( | ||
| 135 | format!("Subscribers: {}", channel.sub_count), | ||
| 136 | Style::default().fg(Color::LightYellow), | ||
| 137 | )); | ||
| 138 | |||
| 139 | to_print.push(( | ||
| 140 | String::from("Description: "), | ||
| 141 | Style::default().fg(Color::Gray), | ||
| 142 | )); | ||
| 143 | |||
| 144 | to_print.push(( | ||
| 145 | format!("Total Views: {}", channel.total_views), | ||
| 146 | Style::default().fg(Color::LightCyan), | ||
| 147 | )); | ||
| 148 | |||
| 149 | to_print.push(( | ||
| 150 | String::from("Description: "), | ||
| 151 | Style::default().fg(Color::Gray), | ||
| 152 | )); | ||
| 153 | |||
| 154 | for (mut item, style) in to_print { | ||
| 155 | if y > area.height + area.y - 1 { | ||
| 156 | return; | ||
| 157 | } | ||
| 158 | |||
| 159 | if item.len() > area.width as usize { | ||
| 160 | item = format!("{}...", &item[..area.width as usize - 3]); | ||
| 161 | } | ||
| 162 | buf.set_string(area.x, y, item, style); | ||
| 163 | y += 1; | ||
| 164 | } | ||
| 165 | |||
| 166 | if y < area.height + area.y { | ||
| 167 | let rect = Rect { | ||
| 168 | x: area.x, | ||
| 169 | y, | ||
| 170 | width: area.width, | ||
| 171 | height: area.height + area.y - y, | ||
| 172 | }; | ||
| 173 | |||
| 174 | let paragraph = Paragraph::new(channel.description.clone()) | ||
| 175 | .wrap(Wrap { trim: true }) | ||
| 176 | .alignment(Alignment::Left) | ||
| 177 | .style(Style::default().fg(Color::Gray)); | ||
| 178 | |||
| 179 | paragraph.render(rect, buf); | ||
| 180 | } | ||
| 181 | } | ||
| 182 | ListItem::MiniVideo(video) => { | ||
| 183 | let mut path = home::home_dir().expect("Cannot get your home directory"); | ||
| 184 | path.push(".cache"); | ||
| 185 | path.push("youtube-tui"); | ||
| 186 | path.push("thumbnails"); | ||
| 187 | path.push(format!("{}.png", video.video_id)); | ||
| 188 | let exists = path.exists(); | ||
| 189 | let mut image_transform = area; | ||
| 190 | if exists { | ||
| 191 | if image_transform.width * 9 > image_transform.height * 2 * 16 { | ||
| 192 | image_transform.width = image_transform.height * 2 * 16 / 9; | ||
| 193 | } else { | ||
| 194 | image_transform.height = image_transform.width * 9 / 32; | ||
| 195 | } | ||
| 196 | |||
| 197 | let conf = Config { | ||
| 198 | width: Some(image_transform.width as u32), | ||
| 199 | height: Some(image_transform.height as u32), | ||
| 200 | x: image_transform.x, | ||
| 201 | y: image_transform.y as i16, | ||
| 202 | ..Default::default() | ||
| 203 | }; | ||
| 204 | if self.render_image{ | ||
| 205 | let _ = print_from_file(path.as_os_str(), &conf); | ||
| 206 | } | ||
| 207 | } | ||
| 208 | |||
| 209 | let mut y = if exists { | ||
| 210 | image_transform.y + image_transform.height | ||
| 211 | } else { | ||
| 212 | area.y | ||
| 213 | }; | ||
| 214 | |||
| 215 | let mut to_print = Vec::new(); | ||
| 216 | to_print.push((String::from("[Video]"), Style::default().fg(Color::Gray))); | ||
| 217 | to_print.push((video.title, Style::default().fg(Color::LightBlue))); | ||
| 218 | to_print.push(( | ||
| 219 | format!("Uploaded by {}", video.author), | ||
| 220 | Style::default().fg(Color::LightGreen), | ||
| 221 | )); | ||
| 222 | if let Some(s) = video.view_count { | ||
| 223 | to_print.push(( | ||
| 224 | format!("Views: {}", s), | ||
| 225 | Style::default().fg(Color::LightYellow), | ||
| 226 | )); | ||
| 227 | } | ||
| 228 | to_print.push(( | ||
| 229 | format!("Length: {}", video.length), | ||
| 230 | Style::default().fg(Color::LightCyan), | ||
| 231 | )); | ||
| 232 | if let Some(s) = video.published { | ||
| 233 | to_print.push(( | ||
| 234 | format!("Published: {}", s), | ||
| 235 | Style::default().fg(Color::LightMagenta), | ||
| 236 | )); | ||
| 237 | } | ||
| 238 | |||
| 239 | for (mut item, style) in to_print { | ||
| 240 | if y > area.height + area.y - 1 { | ||
| 241 | return; | ||
| 242 | } | ||
| 243 | |||
| 244 | if item.len() > area.width as usize { | ||
| 245 | if item.len() > area.width as usize - 2 { | ||
| 246 | for _ in area.width as usize - 3..item.len() { | ||
| 247 | item.pop(); | ||
| 248 | } | ||
| 249 | |||
| 250 | item.push('…'); | ||
| 251 | } | ||
| 252 | } | ||
| 253 | buf.set_string(area.x, y, item, style); | ||
| 254 | y += 1; | ||
| 255 | } | ||
| 256 | } | ||
| 257 | |||
| 258 | ListItem::FullVideo(video) => { | ||
| 259 | let mut path = home::home_dir().expect("Cannot get your home directory"); | ||
| 260 | path.push(".cache"); | ||
| 261 | path.push("youtube-tui"); | ||
| 262 | path.push("thumbnails"); | ||
| 263 | path.push(format!("{}.png", video.video_id)); | ||
| 264 | let exists = path.exists(); | ||
| 265 | let mut image_transform = area; | ||
| 266 | if exists { | ||
| 267 | if image_transform.width * 9 > image_transform.height * 2 * 16 { | ||
| 268 | image_transform.width = image_transform.height * 2 * 16 / 9; | ||
| 269 | } else { | ||
| 270 | image_transform.height = image_transform.width * 9 / 32; | ||
| 271 | } | ||
| 272 | |||
| 273 | let conf = Config { | ||
| 274 | width: Some(image_transform.width as u32), | ||
| 275 | height: Some(image_transform.height as u32), | ||
| 276 | x: image_transform.x, | ||
| 277 | y: image_transform.y as i16, | ||
| 278 | ..Default::default() | ||
| 279 | }; | ||
| 280 | if self.render_image { | ||
| 281 | let _ = print_from_file(path.as_os_str(), &conf); | ||
| 282 | } | ||
| 283 | } | ||
| 284 | |||
| 285 | let mut y = if exists { | ||
| 286 | image_transform.y + image_transform.height | ||
| 287 | } else { | ||
| 288 | area.y | ||
| 289 | }; | ||
| 290 | |||
| 291 | let mut to_print = Vec::new(); | ||
| 292 | let mut tags = Vec::new(); | ||
| 293 | |||
| 294 | if !video.nsfw { | ||
| 295 | tags.push("Family Friendly"); | ||
| 296 | } | ||
| 297 | |||
| 298 | if !video.public { | ||
| 299 | tags.push("Unlisted") | ||
| 300 | } | ||
| 301 | |||
| 302 | if video.upcoming { | ||
| 303 | tags.push("Upcoming") | ||
| 304 | } | ||
| 305 | if video.live { | ||
| 306 | tags.push("Live") | ||
| 307 | } | ||
| 308 | |||
| 309 | tags.push("Video"); | ||
| 310 | |||
| 311 | to_print.push(( | ||
| 312 | format!(" [{}]", tags.join(" ")), | ||
| 313 | Style::default().fg(Color::Gray), | ||
| 314 | )); | ||
| 315 | to_print.push((video.title, Style::default().fg(Color::LightBlue))); | ||
| 316 | to_print.push(( | ||
| 317 | format!("Uploaded by {}", video.channel), | ||
| 318 | Style::default().fg(Color::LightGreen), | ||
| 319 | )); | ||
| 320 | to_print.push(( | ||
| 321 | format!("Views: {}", video.views), | ||
| 322 | Style::default().fg(Color::LightYellow), | ||
| 323 | )); | ||
| 324 | to_print.push(( | ||
| 325 | format!("Length: {}", video.length), | ||
| 326 | Style::default().fg(Color::LightCyan), | ||
| 327 | )); | ||
| 328 | to_print.push(( | ||
| 329 | format!("Genre: {}", video.genre), | ||
| 330 | Style::default().fg(Color::LightYellow), | ||
| 331 | )); | ||
| 332 | to_print.push(( | ||
| 333 | format!("Published {}", video.published), | ||
| 334 | Style::default().fg(Color::LightMagenta), | ||
| 335 | )); | ||
| 336 | |||
| 337 | to_print.push(( | ||
| 338 | String::from("Description: "), | ||
| 339 | Style::default().fg(Color::Gray), | ||
| 340 | )); | ||
| 341 | |||
| 342 | for (mut item, style) in to_print { | ||
| 343 | if y > area.height + area.y - 1 { | ||
| 344 | return; | ||
| 345 | } | ||
| 346 | |||
| 347 | if item.len() > area.width as usize { | ||
| 348 | // item = format!("{}...", &item[..area.width as usize - 3]); | ||
| 349 | item = format!("{}...", &item.get(..area.width as usize - 3).unwrap_or_default()); | ||
| 350 | } | ||
| 351 | buf.set_string(area.x, y, item, style); | ||
| 352 | y += 1; | ||
| 353 | } | ||
| 354 | |||
| 355 | if y < area.height + area.y { | ||
| 356 | let rect = Rect { | ||
| 357 | x: area.x, | ||
| 358 | y, | ||
| 359 | width: area.width, | ||
| 360 | height: area.height + area.y - y, | ||
| 361 | }; | ||
| 362 | |||
| 363 | let paragraph = Paragraph::new(video.description.clone()) | ||
| 364 | .wrap(Wrap { trim: true }) | ||
| 365 | .alignment(Alignment::Left) | ||
| 366 | .style(Style::default().fg(Color::Gray)); | ||
| 367 | |||
| 368 | paragraph.render(rect, buf); | ||
| 369 | } | ||
| 370 | } | ||
| 371 | |||
| 372 | ListItem::MiniPlayList(playlist) => { | ||
| 373 | let mut path = home::home_dir().expect("Cannot get your home directory"); | ||
| 374 | path.push(".cache"); | ||
| 375 | path.push("youtube-tui"); | ||
| 376 | path.push("thumbnails"); | ||
| 377 | path.push(format!("{}.png", playlist.playlist_id)); | ||
| 378 | let exists = path.exists(); | ||
| 379 | let mut image_transform = area; | ||
| 380 | if exists { | ||
| 381 | if image_transform.width * 9 > image_transform.height * 2 * 16 { | ||
| 382 | image_transform.width = image_transform.height * 2 * 16 / 9; | ||
| 383 | } else { | ||
| 384 | image_transform.height = image_transform.width * 9 / 32; | ||
| 385 | } | ||
| 386 | |||
| 387 | let conf = Config { | ||
| 388 | width: Some(image_transform.width as u32), | ||
| 389 | height: Some(image_transform.height as u32), | ||
| 390 | x: image_transform.x, | ||
| 391 | y: image_transform.y as i16, | ||
| 392 | ..Default::default() | ||
| 393 | }; | ||
| 394 | |||
| 395 | if self.render_image{ | ||
| 396 | let _ = print_from_file(path.as_os_str(), &conf); | ||
| 397 | } | ||
| 398 | } | ||
| 399 | |||
| 400 | let mut y = if exists { | ||
| 401 | image_transform.y + image_transform.height | ||
| 402 | } else { | ||
| 403 | area.y | ||
| 404 | }; | ||
| 405 | |||
| 406 | let mut to_print = Vec::new(); | ||
| 407 | to_print.push((String::from("[PlayList]"), Style::default().fg(Color::Gray))); | ||
| 408 | to_print.push((playlist.title, Style::default().fg(Color::LightBlue))); | ||
| 409 | to_print.push(( | ||
| 410 | format!("Created by {}", playlist.author), | ||
| 411 | Style::default().fg(Color::LightGreen), | ||
| 412 | )); | ||
| 413 | to_print.push(( | ||
| 414 | format!("Video Count: {}", playlist.video_count), | ||
| 415 | Style::default().fg(Color::LightCyan), | ||
| 416 | )); | ||
| 417 | |||
| 418 | for (mut item, style) in to_print { | ||
| 419 | if y > area.height + area.y - 1 { | ||
| 420 | return; | ||
| 421 | } | ||
| 422 | |||
| 423 | if item.len() > area.width as usize { | ||
| 424 | if item.len() > area.width as usize - 2 { | ||
| 425 | for _ in area.width as usize - 3..item.len() { | ||
| 426 | item.pop(); | ||
| 427 | } | ||
| 428 | |||
| 429 | item.push('…'); | ||
| 430 | } | ||
| 431 | } | ||
| 432 | buf.set_string(area.x, y, item, style); | ||
| 433 | y += 1; | ||
| 434 | } | ||
| 435 | } | ||
| 436 | |||
| 437 | ListItem::FullPlayList(playlist) => { | ||
| 438 | let mut path = home::home_dir().expect("Cannot get your home directory"); | ||
| 439 | path.push(".cache"); | ||
| 440 | path.push("youtube-tui"); | ||
| 441 | path.push("thumbnails"); | ||
| 442 | path.push(format!("{}.png", playlist.playlist_id)); | ||
| 443 | let exists = path.exists(); | ||
| 444 | let mut image_transform = area; | ||
| 445 | if exists { | ||
| 446 | if image_transform.width * 9 > image_transform.height * 2 * 16 { | ||
| 447 | image_transform.width = image_transform.height * 2 * 16 / 9; | ||
| 448 | } else { | ||
| 449 | image_transform.height = image_transform.width * 9 / 32; | ||
| 450 | } | ||
| 451 | |||
| 452 | let conf = Config { | ||
| 453 | width: Some(image_transform.width as u32), | ||
| 454 | height: Some(image_transform.height as u32), | ||
| 455 | x: image_transform.x, | ||
| 456 | y: image_transform.y as i16, | ||
| 457 | ..Default::default() | ||
| 458 | }; | ||
| 459 | |||
| 460 | if self.render_image{ | ||
| 461 | let _ = print_from_file(path.as_os_str(), &conf); | ||
| 462 | } | ||
| 463 | } | ||
| 464 | |||
| 465 | let mut y = if exists { | ||
| 466 | image_transform.y + image_transform.height | ||
| 467 | } else { | ||
| 468 | area.y | ||
| 469 | }; | ||
| 470 | |||
| 471 | let mut to_print = Vec::new(); | ||
| 472 | to_print.push((String::from("[PlayList]"), Style::default().fg(Color::Gray))); | ||
| 473 | to_print.push((playlist.title, Style::default().fg(Color::LightBlue))); | ||
| 474 | to_print.push(( | ||
| 475 | format!("Created by {}", playlist.author), | ||
| 476 | Style::default().fg(Color::LightGreen), | ||
| 477 | )); | ||
| 478 | to_print.push(( | ||
| 479 | format!("Video Count: {}", playlist.video_count), | ||
| 480 | Style::default().fg(Color::LightCyan), | ||
| 481 | )); | ||
| 482 | to_print.push(( | ||
| 483 | format!("Views: {}", playlist.views), | ||
| 484 | Style::default().fg(Color::LightYellow), | ||
| 485 | )); | ||
| 486 | |||
| 487 | for (mut item, style) in to_print { | ||
| 488 | if y > area.height + area.y - 1 { | ||
| 489 | return; | ||
| 490 | } | ||
| 491 | |||
| 492 | if item.len() > area.width as usize { | ||
| 493 | if item.len() > area.width as usize - 2 { | ||
| 494 | for _ in area.width as usize - 3..item.len() { | ||
| 495 | item.pop(); | ||
| 496 | } | ||
| 497 | |||
| 498 | item.push('…'); | ||
| 499 | } | ||
| 500 | } | ||
| 501 | |||
| 502 | buf.set_string(area.x, y, item, style); | ||
| 503 | |||
| 504 | y += 1; | ||
| 505 | } | ||
| 506 | } | ||
| 507 | |||
| 508 | ListItem::PageTurner(b) => { | ||
| 509 | let paragraph = Paragraph::new(if b { | ||
| 510 | "Press enter to go to the next page" | ||
| 511 | } else { | ||
| 512 | "Press enter to go to the previous page" | ||
| 513 | }) | ||
| 514 | .style(Style::default().bg(Color::DarkGray)) | ||
| 515 | .wrap(Wrap { trim: true }) | ||
| 516 | .alignment(Alignment::Center); | ||
| 517 | |||
| 518 | paragraph.render(area, buf); | ||
| 519 | } | ||
| 520 | } | ||
| 521 | } | ||
| 522 | } | ||
src/widgets/mod.rs deleted −3
| @@ -1,3 +0,0 @@ | |||
| 1 | pub mod horizontal_split; | ||
| 2 | pub mod item_display; | ||
| 3 | pub mod text_list; | ||
src/widgets/text_list.rs deleted −188
| @@ -1,188 +0,0 @@ | |||
| 1 | use tui::{ | ||
| 2 | buffer::Buffer, | ||
| 3 | layout::Rect, | ||
| 4 | style::{Color, Style}, | ||
| 5 | symbols::line::{ | ||
| 6 | HORIZONTAL, ROUNDED_BOTTOM_LEFT, ROUNDED_BOTTOM_RIGHT, ROUNDED_TOP_LEFT, ROUNDED_TOP_RIGHT, | ||
| 7 | VERTICAL, | ||
| 8 | }, | ||
| 9 | widgets::Widget, | ||
| 10 | }; | ||
| 11 | |||
| 12 | #[derive(Debug, Clone)] | ||
| 13 | pub struct TextList { | ||
| 14 | pub items: Vec<String>, | ||
| 15 | pub selected: usize, | ||
| 16 | pub scroll: usize, | ||
| 17 | pub area: Option<Rect>, | ||
| 18 | pub style: Style, | ||
| 19 | pub selected_style: Style, | ||
| 20 | } | ||
| 21 | |||
| 22 | impl Widget for TextList { | ||
| 23 | fn render(self, area: Rect, buf: &mut Buffer) { | ||
| 24 | if self.items.len() == 0 || area.height < 3 { | ||
| 25 | return; | ||
| 26 | } | ||
| 27 | |||
| 28 | let width_minus_2 = (area.width - 2) as usize; | ||
| 29 | let width_minus_5 = (area.width - 5) as usize; | ||
| 30 | let mut y = area.y; | ||
| 31 | |||
| 32 | buf.set_style(area, self.style); | ||
| 33 | |||
| 34 | for (i, mut item) in self | ||
| 35 | .items | ||
| 36 | .into_iter() | ||
| 37 | .enumerate() | ||
| 38 | .skip(self.scroll) | ||
| 39 | .take(area.height as usize - 2) | ||
| 40 | { | ||
| 41 | let mut len = item.chars().count(); | ||
| 42 | if len > width_minus_2 { | ||
| 43 | for _ in width_minus_5..len { | ||
| 44 | item.pop(); | ||
| 45 | } | ||
| 46 | |||
| 47 | item.push_str("..."); | ||
| 48 | } | ||
| 49 | |||
| 50 | len = item.chars().count(); | ||
| 51 | |||
| 52 | if i == self.selected { | ||
| 53 | let horizontal = HORIZONTAL.to_string().repeat(width_minus_2); | ||
| 54 | |||
| 55 | let lines = format!( | ||
| 56 | "{}{}{}\n{}{}{}{}\n{}{}{}", | ||
| 57 | ROUNDED_TOP_LEFT, | ||
| 58 | horizontal, | ||
| 59 | ROUNDED_TOP_RIGHT, | ||
| 60 | VERTICAL, | ||
| 61 | item, | ||
| 62 | " ".repeat(area.width as usize - 2 - len), | ||
| 63 | VERTICAL, | ||
| 64 | ROUNDED_BOTTOM_LEFT, | ||
| 65 | horizontal, | ||
| 66 | ROUNDED_BOTTOM_RIGHT, | ||
| 67 | ); | ||
| 68 | |||
| 69 | let mut rect = Rect { | ||
| 70 | x: area.x, | ||
| 71 | y: y, | ||
| 72 | width: area.width, | ||
| 73 | height: 1, | ||
| 74 | }; | ||
| 75 | buf.set_style(rect, self.selected_style); | ||
| 76 | |||
| 77 | rect = Rect { | ||
| 78 | x: area.x, | ||
| 79 | y: y + 1, | ||
| 80 | width: 1, | ||
| 81 | height: 1, | ||
| 82 | }; | ||
| 83 | buf.set_style(rect, self.selected_style); | ||
| 84 | |||
| 85 | rect = Rect { | ||
| 86 | x: area.x + area.width - 1, | ||
| 87 | y: y + 1, | ||
| 88 | width: 1, | ||
| 89 | height: 1, | ||
| 90 | }; | ||
| 91 | buf.set_style(rect, self.selected_style); | ||
| 92 | |||
| 93 | rect = Rect { | ||
| 94 | x: area.x, | ||
| 95 | y: y + 2, | ||
| 96 | width: area.width, | ||
| 97 | height: 1, | ||
| 98 | }; | ||
| 99 | buf.set_style(rect, self.selected_style); | ||
| 100 | |||
| 101 | for line in lines.lines() { | ||
| 102 | buf.set_string(area.x, y, line, Style::default()); | ||
| 103 | |||
| 104 | y += 1; | ||
| 105 | } | ||
| 106 | } else { | ||
| 107 | buf.set_string(area.x + 1, y, item, Style::default()); | ||
| 108 | |||
| 109 | y += 1; | ||
| 110 | } | ||
| 111 | } | ||
| 112 | } | ||
| 113 | } | ||
| 114 | |||
| 115 | impl Default for TextList { | ||
| 116 | fn default() -> Self { | ||
| 117 | Self { | ||
| 118 | items: Vec::new(), | ||
| 119 | selected: 0, | ||
| 120 | scroll: 0, | ||
| 121 | area: None, | ||
| 122 | style: Style::default(), | ||
| 123 | selected_style: Style::default().fg(Color::Yellow), | ||
| 124 | } | ||
| 125 | } | ||
| 126 | } | ||
| 127 | |||
| 128 | impl TextList { | ||
| 129 | pub fn area(&mut self, area: Rect) { | ||
| 130 | self.area = Some(area); | ||
| 131 | self.update_scroll(); | ||
| 132 | } | ||
| 133 | |||
| 134 | pub fn items(&mut self, items: Vec<String>) { | ||
| 135 | self.items = items; | ||
| 136 | } | ||
| 137 | |||
| 138 | pub fn down(&mut self) { | ||
| 139 | if self.items.len() == 0 { | ||
| 140 | return; | ||
| 141 | } | ||
| 142 | |||
| 143 | if self.selected < self.items.len() - 1 { | ||
| 144 | self.selected += 1; | ||
| 145 | } | ||
| 146 | self.update_scroll() | ||
| 147 | } | ||
| 148 | |||
| 149 | pub fn up(&mut self) { | ||
| 150 | if self.items.len() == 0 { | ||
| 151 | return; | ||
| 152 | } | ||
| 153 | if self.selected > 0 { | ||
| 154 | self.selected -= 1; | ||
| 155 | } | ||
| 156 | self.update_scroll(); | ||
| 157 | } | ||
| 158 | |||
| 159 | pub fn first(&mut self) { | ||
| 160 | self.selected = 0; | ||
| 161 | self.update_scroll(); | ||
| 162 | } | ||
| 163 | |||
| 164 | pub fn last(&mut self) { | ||
| 165 | self.selected = self.items.len() - 1; | ||
| 166 | self.update_scroll(); | ||
| 167 | } | ||
| 168 | |||
| 169 | pub fn update_scroll(&mut self) { | ||
| 170 | if self.selected < self.scroll { | ||
| 171 | self.scroll = self.selected; | ||
| 172 | } | ||
| 173 | |||
| 174 | if let Some(area) = self.area { | ||
| 175 | if self.selected > self.scroll + area.height as usize - 3 { | ||
| 176 | self.scroll = self.selected + 3 - area.height as usize; | ||
| 177 | } | ||
| 178 | } | ||
| 179 | } | ||
| 180 | |||
| 181 | pub fn style(&mut self, style: Style) { | ||
| 182 | self.style = style; | ||
| 183 | } | ||
| 184 | |||
| 185 | pub fn selected_style(&mut self, style: Style) { | ||
| 186 | self.selected_style = style; | ||
| 187 | } | ||
| 188 | } | ||