From e2776996ef8fe670802f8c6ad253401c48b8a755 Mon Sep 17 00:00:00 2001 From: emilis Date: Fri, 27 Jan 2023 12:35:24 +0000 Subject: [PATCH] added padding_pct --- Cargo.lock | 684 +++++++++++----------------------------- kkdisp/src/component.rs | 9 +- kkdisp/src/lib.rs | 27 +- kkdisp/src/token.rs | 138 +++++++- kkdisp/src/view.rs | 8 +- kkx/Cargo.toml | 4 +- kkx/src/login.rs | 107 ++++--- kkx/src/main.rs | 2 +- 8 files changed, 419 insertions(+), 560 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 7705c3c..c52cd1f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -57,41 +57,20 @@ dependencies = [ "event-listener", ] -[[package]] -name = "async-tls" -version = "0.10.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d85a97c4a0ecce878efd3f945f119c78a646d8975340bca0398f9bb05c30cc52" -dependencies = [ - "futures-core", - "futures-io", - "rustls", - "webpki", - "webpki-roots", -] - [[package]] name = "async-tungstenite" -version = "0.10.0" +version = "0.18.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "39eca8dd578b18e557361e50ca767df55c5e62f690a5e53868c3c7a8123145b7" +checksum = "4b750efd83b7e716a015eed5ebb583cda83c52d9b24a8f0125e5c48c3313c9f8" dependencies = [ - "async-tls", "futures-io", "futures-util", "log", - "pin-project", - "tokio 0.3.7", + "pin-project-lite", + "tokio", + "tokio-rustls", "tungstenite", -] - -[[package]] -name = "autocfg" -version = "0.1.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0dde43e75fd43e8a1bf86103336bc699aa8d17ad1be60c76c0bdfd4828e19b78" -dependencies = [ - "autocfg 1.1.0", + "webpki-roots", ] [[package]] @@ -102,9 +81,9 @@ checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" [[package]] name = "base64" -version = "0.12.3" +version = "0.13.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3441f0f7b02788e948e47f457ca01f1d7e6d92c693bc132c22b087d3141c03ff" +checksum = "9e1b586273c5702936fe7b7d6896644d8be71e6314cfe09d3167c95f712589e8" [[package]] name = "bitflags" @@ -114,9 +93,9 @@ checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" [[package]] name = "block-buffer" -version = "0.9.0" +version = "0.10.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4152116fd6e9dadb291ae18fc1ec3575ed6d84c29642d97890f4b4a3417297e4" +checksum = "69cce20737498f97b993470a6e536b8523f0af7892a4f928cceb1ac5e52ebe7e" dependencies = [ "generic-array", ] @@ -133,18 +112,18 @@ version = "1.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "14c189c53d098945499cdfa7ecc63567cf3886b3332b312a5b4585d8d3a6a610" -[[package]] -name = "bytes" -version = "0.5.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0e4cec68f03f32e44924783795810fa50a7035d8c8ebe78580ad7e6c703fba38" - [[package]] name = "bytes" version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dfb24e866b15a1af2a1b663f10c6b6b8f397a84aadb828f12e5b289ec23a3a3c" +[[package]] +name = "castaway" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a2698f953def977c68f935bb0dfa959375ad4638570e969e2f1e9f433cbf1af6" + [[package]] name = "cc" version = "1.0.78" @@ -173,15 +152,6 @@ dependencies = [ "winapi", ] -[[package]] -name = "cloudabi" -version = "0.0.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ddfc5b9aa5d4507acaf872de71051dfd0e309860e88966e1051e462a077aac4f" -dependencies = [ - "bitflags", -] - [[package]] name = "codespan-reporting" version = "0.11.1" @@ -194,15 +164,18 @@ dependencies = [ [[package]] name = "common-multipart-rfc7578" -version = "0.2.0-rc" +version = "0.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7471b7b1588b2cda44e0cdf3fd3da5706c1b46224dbf486c3daceb6655ec191c" +checksum = "5baee326bc603965b0f26583e1ecd7c111c41b49bd92a344897476a352798869" dependencies = [ - "bytes 0.5.6", - "futures", + "bytes", + "futures-core", + "futures-util", "http", "mime", - "rand 0.5.6", + "mime_guess", + "rand", + "thiserror", ] [[package]] @@ -238,6 +211,16 @@ dependencies = [ "cfg-if", ] +[[package]] +name = "crypto-common" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1bfb12502f3fc46cca1bb51ac28df9d618d813cdc3d2f25b9fe775a34af26bb3" +dependencies = [ + "generic-array", + "typenum", +] + [[package]] name = "curl" version = "0.4.44" @@ -290,10 +273,10 @@ dependencies = [ "cc", "codespan-reporting", "once_cell", - "proc-macro2 1.0.50", - "quote 1.0.23", + "proc-macro2", + "quote", "scratch", - "syn 1.0.107", + "syn", ] [[package]] @@ -308,9 +291,9 @@ version = "1.0.87" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "65e07508b90551e610910fa648a1878991d367064997a596135b86df30daf07e" dependencies = [ - "proc-macro2 1.0.50", - "quote 1.0.23", - "syn 1.0.107", + "proc-macro2", + "quote", + "syn", ] [[package]] @@ -319,18 +302,19 @@ version = "2.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fcc3dd5e9e9c0b295d6e1e4d811fb6f157d5ffd784b8d202fc62eac8035a770b" dependencies = [ - "proc-macro2 1.0.50", - "quote 1.0.23", - "syn 1.0.107", + "proc-macro2", + "quote", + "syn", ] [[package]] name = "digest" -version = "0.9.0" +version = "0.10.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d3dd60d1080a57a05ab032377049e0591415d2b31afd7028356dbf3cc6dcb066" +checksum = "8168378f4e5023e7218c89c891c0fd8ecdb5e5e4f18cb78f38cf245dd021e76f" dependencies = [ - "generic-array", + "block-buffer", + "crypto-common", ] [[package]] @@ -357,17 +341,6 @@ dependencies = [ "instant", ] -[[package]] -name = "flume" -version = "0.9.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1bebadab126f8120d410b677ed95eee4ba6eb7c6dd8e34a5ec88a08050e26132" -dependencies = [ - "futures-core", - "futures-sink", - "spinning_top", -] - [[package]] name = "fnv" version = "1.0.7" @@ -383,12 +356,6 @@ dependencies = [ "percent-encoding", ] -[[package]] -name = "fuchsia-cprng" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a06f77d526c1a601b7c4cdd98f54b5eaabffc14d5f2f0296febdc7f357c6d3ba" - [[package]] name = "futures" version = "0.3.25" @@ -458,9 +425,9 @@ version = "0.3.25" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bdfb8ce053d86b91919aad980c220b1fb8401a9394410e1c289ed7e66b61835d" dependencies = [ - "proc-macro2 1.0.50", - "quote 1.0.23", - "syn 1.0.107", + "proc-macro2", + "quote", + "syn", ] [[package]] @@ -509,17 +476,6 @@ dependencies = [ "version_check", ] -[[package]] -name = "getrandom" -version = "0.1.16" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8fc3cb4d91f53b50155bdcfd23f6a4c39ae1969c2ae85982b135750cccaf5fce" -dependencies = [ - "cfg-if", - "libc", - "wasi 0.9.0+wasi-snapshot-preview1", -] - [[package]] name = "getrandom" version = "0.2.8" @@ -533,12 +489,9 @@ dependencies = [ [[package]] name = "heck" -version = "0.3.3" +version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6d621efb26863f0e9924c6ac577e8275e5e6b77455db64ffa6c65c904e9e132c" -dependencies = [ - "unicode-segmentation", -] +checksum = "2540771e65fc8cb83cd6e8a237f70c319bd5c29f78ed1084ba5d50eeac86f7f9" [[package]] name = "hermit-abi" @@ -555,7 +508,7 @@ version = "0.2.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "75f43d41e26995c17e71ee126451dd3941010b0514a81a9d11f3b341debc2399" dependencies = [ - "bytes 1.3.0", + "bytes", "fnv", "itoa", ] @@ -600,15 +553,6 @@ dependencies = [ "unicode-normalization", ] -[[package]] -name = "input_buffer" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "19a8a95243d5a0398cae618ec29477c6e3cb631152be5c19481f80bc71559754" -dependencies = [ - "bytes 0.5.6", -] - [[package]] name = "instant" version = "0.1.12" @@ -620,21 +564,23 @@ dependencies = [ [[package]] name = "isahc" -version = "0.9.14" +version = "1.7.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e2948a0ce43e2c2ef11d7edf6816508998d99e13badd1150be0914205df9388a" +checksum = "334e04b4d781f436dc315cb1e7515bd96826426345d498149e4bde36b67f8ee9" dependencies = [ - "bytes 0.5.6", + "async-channel", + "castaway", "crossbeam-utils", "curl", "curl-sys", "encoding_rs", - "flume", + "event-listener", "futures-lite", "http", "log", "mime", "once_cell", + "polling", "slab", "sluice", "tracing", @@ -672,17 +618,12 @@ name = "kkx" version = "0.1.0" dependencies = [ "anyhow", + "futures", "kkdisp", "misskey", - "tokio 1.24.2", + "tokio", ] -[[package]] -name = "lazy_static" -version = "1.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" - [[package]] name = "libc" version = "0.2.139" @@ -726,7 +667,7 @@ version = "0.4.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "435011366fe56583b16cf956f9df0095b405b82d76425bc8981c0e22e60ec4df" dependencies = [ - "autocfg 1.1.0", + "autocfg", "scopeguard", ] @@ -761,19 +702,6 @@ dependencies = [ "unicase", ] -[[package]] -name = "mio" -version = "0.7.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8067b404fe97c70829f082dec8bcf4f71225d7eaea1d8645349cb76fa06205cc" -dependencies = [ - "libc", - "log", - "miow", - "ntapi", - "winapi", -] - [[package]] name = "mio" version = "0.8.5" @@ -786,20 +714,10 @@ dependencies = [ "windows-sys", ] -[[package]] -name = "miow" -version = "0.3.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b9f1c5b025cda876f66ef43a113f91ebc9f4ccef34843000e0adf6ebbab84e21" -dependencies = [ - "winapi", -] - [[package]] name = "misskey" version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "17e862440df20f3589eb571508176912e06eaca65d6d3edeb14a16b06b17e9f6" +source = "git+https://github.com/coord-e/misskey-rs?branch=develop#e2fb363058829288da0b5a1238e90fb9c7f1a233" dependencies = [ "misskey-api", "misskey-core", @@ -811,13 +729,12 @@ dependencies = [ [[package]] name = "misskey-api" version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4e485eaa858c5a18ae34159d53d9d637c592cd1e91a33736c2df9a93d9f5918e" +source = "git+https://github.com/coord-e/misskey-rs?branch=develop#e2fb363058829288da0b5a1238e90fb9c7f1a233" dependencies = [ "chrono", "mime", "misskey-core", - "rand_core 0.2.2", + "rustversion", "serde", "serde_json", "strum_macros", @@ -830,8 +747,7 @@ dependencies = [ [[package]] name = "misskey-core" version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c4c702e69d3cd5d64cd38d75e62609c89aa3780524b2a4667e45879278cb41af" +source = "git+https://github.com/coord-e/misskey-rs?branch=develop#e2fb363058829288da0b5a1238e90fb9c7f1a233" dependencies = [ "futures-core", "futures-sink", @@ -843,16 +759,15 @@ dependencies = [ [[package]] name = "misskey-http" version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c2af7f2e155120f0bcb6fdf0432dab95e3ffdfddd5cf6bab0080e0fc0c36da3c" +source = "git+https://github.com/coord-e/misskey-rs?branch=develop#e2fb363058829288da0b5a1238e90fb9c7f1a233" dependencies = [ "async-dup", "common-multipart-rfc7578", - "futures", + "futures-util", "isahc", "mime", "misskey-core", - "rustc_version", + "openssl-sys", "serde", "serde_json", "thiserror", @@ -862,8 +777,7 @@ dependencies = [ [[package]] name = "misskey-util" version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0015066edfb1aa294eb4b6a45f9cae1da77f7406b664b1f571f1a1abe9df503e" +source = "git+https://github.com/coord-e/misskey-rs?branch=develop#e2fb363058829288da0b5a1238e90fb9c7f1a233" dependencies = [ "chrono", "derivative", @@ -881,39 +795,30 @@ dependencies = [ [[package]] name = "misskey-websocket" version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "06e3afe06a836a1bbc57ab7102c8d44153275c58fa230a8654cec5b2d9ca5c74" +source = "git+https://github.com/coord-e/misskey-rs?branch=develop#e2fb363058829288da0b5a1238e90fb9c7f1a233" dependencies = [ "async-rwlock", "async-tungstenite", "chrono", - "futures", + "futures-channel", + "futures-util", "log", "misskey-core", "serde", "serde_json", "thiserror", - "tokio 0.3.7", + "tokio", "url", "uuid", ] -[[package]] -name = "ntapi" -version = "0.3.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c28774a7fd2fbb4f0babd8237ce554b73af68021b5f695a3cebd6c59bac0980f" -dependencies = [ - "winapi", -] - [[package]] name = "num-integer" version = "0.1.45" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "225d3389fb3509a24c93f5c29eb6bde2586b98d9f016636dff58d7c6f7569cd9" dependencies = [ - "autocfg 1.1.0", + "autocfg", "num-traits", ] @@ -923,7 +828,7 @@ version = "0.2.15" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "578ede34cf02f8924ab9447f50c28075b4d3e5b269972345e7e0372b38c6cdcd" dependencies = [ - "autocfg 1.1.0", + "autocfg", ] [[package]] @@ -948,12 +853,6 @@ version = "1.17.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6f61fba1741ea2b3d6a1e3178721804bb716a68a6aeba1149b5d52e3d464ea66" -[[package]] -name = "opaque-debug" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "624a8340c38c1b80fd549087862da4ba43e08858af025b236e509b6649fc13d5" - [[package]] name = "openssl-probe" version = "0.1.5" @@ -966,7 +865,7 @@ version = "0.9.80" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "23bbbf7854cd45b83958ebe919f0e8e516793727652e27fda10a8384cfc790b7" dependencies = [ - "autocfg 1.1.0", + "autocfg", "cc", "libc", "pkg-config", @@ -1029,9 +928,9 @@ version = "1.0.12" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "069bdb1e05adc7a8990dce9cc75370895fbe4e3d58b9b73bf1aee56359344a55" dependencies = [ - "proc-macro2 1.0.50", - "quote 1.0.23", - "syn 1.0.107", + "proc-macro2", + "quote", + "syn", ] [[package]] @@ -1052,21 +951,26 @@ version = "0.3.26" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6ac9a59f73473f1b8d852421e59e64809f025994837ef743615c6d0c5b305160" +[[package]] +name = "polling" +version = "2.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "22122d5ec4f9fe1b3916419b76be1e80bcb93f618d071d2edf841b137b2a2bd6" +dependencies = [ + "autocfg", + "cfg-if", + "libc", + "log", + "wepoll-ffi", + "windows-sys", +] + [[package]] name = "ppv-lite86" version = "0.2.17" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de" -[[package]] -name = "proc-macro2" -version = "0.4.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cf3d2011ab5c909338f7887f4fc896d35932e29146c12c8d01da6b22a80ba759" -dependencies = [ - "unicode-xid", -] - [[package]] name = "proc-macro2" version = "1.0.50" @@ -1076,201 +980,43 @@ dependencies = [ "unicode-ident", ] -[[package]] -name = "quote" -version = "0.6.13" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6ce23b6b870e8f94f81fb0a363d65d86675884b34a09043c81e5562f11c1f8e1" -dependencies = [ - "proc-macro2 0.4.30", -] - [[package]] name = "quote" version = "1.0.23" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8856d8364d252a14d474036ea1358d63c9e6965c8e5c1885c18f73d70bff9c7b" dependencies = [ - "proc-macro2 1.0.50", + "proc-macro2", ] [[package]] name = "rand" -version = "0.5.6" +version = "0.8.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c618c47cd3ebd209790115ab837de41425723956ad3ce2e6a7f09890947cacb9" +checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" dependencies = [ - "cloudabi", - "fuchsia-cprng", "libc", - "rand_core 0.3.1", - "winapi", -] - -[[package]] -name = "rand" -version = "0.6.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6d71dacdc3c88c1fde3885a3be3fbab9f35724e6ce99467f7d9c5026132184ca" -dependencies = [ - "autocfg 0.1.8", - "libc", - "rand_chacha 0.1.1", - "rand_core 0.4.2", - "rand_hc 0.1.0", - "rand_isaac", - "rand_jitter", - "rand_os", - "rand_pcg", - "rand_xorshift", - "winapi", -] - -[[package]] -name = "rand" -version = "0.7.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6a6b1679d49b24bbfe0c803429aa1874472f50d9b363131f0e89fc356b544d03" -dependencies = [ - "getrandom 0.1.16", - "libc", - "rand_chacha 0.2.2", - "rand_core 0.5.1", - "rand_hc 0.2.0", + "rand_chacha", + "rand_core", ] [[package]] name = "rand_chacha" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "556d3a1ca6600bfcbab7c7c91ccb085ac7fbbcd70e008a98742e7847f4f7bcef" -dependencies = [ - "autocfg 0.1.8", - "rand_core 0.3.1", -] - -[[package]] -name = "rand_chacha" -version = "0.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f4c8ed856279c9737206bf725bf36935d8666ead7aa69b52be55af369d193402" -dependencies = [ - "ppv-lite86", - "rand_core 0.5.1", -] - -[[package]] -name = "rand_core" -version = "0.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1961a422c4d189dfb50ffa9320bf1f2a9bd54ecb92792fb9477f99a1045f3372" -dependencies = [ - "rand_core 0.3.1", -] - -[[package]] -name = "rand_core" version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7a6fdeb83b075e8266dcc8762c22776f6877a63111121f5f8c7411e5be7eed4b" +checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" dependencies = [ - "rand_core 0.4.2", + "ppv-lite86", + "rand_core", ] [[package]] name = "rand_core" -version = "0.4.2" +version = "0.6.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c33a3c44ca05fa6f1807d8e6743f3824e8509beca625669633be0acbdf509dc" - -[[package]] -name = "rand_core" -version = "0.5.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "90bde5296fc891b0cef12a6d03ddccc162ce7b2aff54160af9338f8d40df6d19" +checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" dependencies = [ - "getrandom 0.1.16", -] - -[[package]] -name = "rand_hc" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7b40677c7be09ae76218dc623efbf7b18e34bced3f38883af07bb75630a21bc4" -dependencies = [ - "rand_core 0.3.1", -] - -[[package]] -name = "rand_hc" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ca3129af7b92a17112d59ad498c6f81eaf463253766b90396d39ea7a39d6613c" -dependencies = [ - "rand_core 0.5.1", -] - -[[package]] -name = "rand_isaac" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ded997c9d5f13925be2a6fd7e66bf1872597f759fd9dd93513dd7e92e5a5ee08" -dependencies = [ - "rand_core 0.3.1", -] - -[[package]] -name = "rand_jitter" -version = "0.1.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1166d5c91dc97b88d1decc3285bb0a99ed84b05cfd0bc2341bdf2d43fc41e39b" -dependencies = [ - "libc", - "rand_core 0.4.2", - "winapi", -] - -[[package]] -name = "rand_os" -version = "0.1.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7b75f676a1e053fc562eafbb47838d67c84801e38fc1ba459e8f180deabd5071" -dependencies = [ - "cloudabi", - "fuchsia-cprng", - "libc", - "rand_core 0.4.2", - "rdrand", - "wasm-bindgen", - "winapi", -] - -[[package]] -name = "rand_pcg" -version = "0.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "abf9b09b01790cfe0364f52bf32995ea3c39f4d2dd011eac241d2914146d0b44" -dependencies = [ - "autocfg 0.1.8", - "rand_core 0.4.2", -] - -[[package]] -name = "rand_xorshift" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cbf7e9e623549b0e21f6e97cf8ecf247c1a8fd2e8a992ae265314300b2455d5c" -dependencies = [ - "rand_core 0.3.1", -] - -[[package]] -name = "rdrand" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "678054eb77286b51581ba43620cc911abf02758c91f93f479767aed0f90458b2" -dependencies = [ - "rand_core 0.3.1", + "getrandom", ] [[package]] @@ -1306,28 +1052,24 @@ dependencies = [ "winapi", ] -[[package]] -name = "rustc_version" -version = "0.2.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "138e3e0acb6c9fb258b19b67cb8abd63c00679d2851805ea151465464fe9030a" -dependencies = [ - "semver", -] - [[package]] name = "rustls" -version = "0.18.1" +version = "0.20.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5d1126dcf58e93cee7d098dbda643b5f92ed724f1f6a63007c1116eed6700c81" +checksum = "fff78fc74d175294f4e83b28343315ffcfb114b156f0185e9741cb5570f50e2f" dependencies = [ - "base64", "log", "ring", "sct", "webpki", ] +[[package]] +name = "rustversion" +version = "1.0.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5583e89e108996506031660fe09baa5011b9dd0341b89029313006d1fb508d70" + [[package]] name = "ryu" version = "1.0.12" @@ -1357,29 +1099,14 @@ checksum = "ddccb15bcce173023b3fedd9436f882a0739b8dfb45e4f6b6002bee5929f61b2" [[package]] name = "sct" -version = "0.6.1" +version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b362b83898e0e69f38515b82ee15aa80636befe47c3b6d3d89a911e78fc228ce" +checksum = "d53dcdb7c9f8158937a7981b48accfd39a43af418591a5d008c7b22b5e1b7ca4" dependencies = [ "ring", "untrusted", ] -[[package]] -name = "semver" -version = "0.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1d7eb9ef2c18661902cc47e535f9bc51b78acd254da71d375c2f6720d9a40403" -dependencies = [ - "semver-parser", -] - -[[package]] -name = "semver-parser" -version = "0.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "388a1df253eca08550bef6c72392cfe7c30914bf41df5269b68cbd6ff8f570a3" - [[package]] name = "serde" version = "1.0.152" @@ -1395,9 +1122,9 @@ version = "1.0.152" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "af487d118eecd09402d70a5d72551860e788df87b464af30e5ea6a38c75c541e" dependencies = [ - "proc-macro2 1.0.50", - "quote 1.0.23", - "syn 1.0.107", + "proc-macro2", + "quote", + "syn", ] [[package]] @@ -1413,15 +1140,13 @@ dependencies = [ [[package]] name = "sha-1" -version = "0.9.8" +version = "0.10.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "99cd6713db3cf16b6c84e06321e049a9b9f699826e16096d23bbcc44d15d51a6" +checksum = "f5058ada175748e33390e40e872bd0fe59a19f265d0158daa551c5a88a76009c" dependencies = [ - "block-buffer", "cfg-if", "cpufeatures", "digest", - "opaque-debug", ] [[package]] @@ -1448,7 +1173,7 @@ version = "0.4.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4614a76b2a8be0058caa9dbbaf66d988527d86d003c11a94fbd335d7661edcef" dependencies = [ - "autocfg 1.1.0", + "autocfg", ] [[package]] @@ -1484,36 +1209,17 @@ version = "0.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6e63cff320ae2c57904679ba7cb63280a3dc4613885beafb148ee7bf9aa9042d" -[[package]] -name = "spinning_top" -version = "0.2.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "75adad84ee84b521fb2cca2d4fd0f1dab1d8d026bda3c5bea4ca63b5f9f9293c" -dependencies = [ - "lock_api", -] - [[package]] name = "strum_macros" -version = "0.12.0" +version = "0.24.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ab9f505ab77221df59d4b5e2b918fdfb43c5f5121987c122c3ba2a3ae4997ced" +checksum = "1e385be0d24f186b4ce2f9982191e7101bb737312ad61c1f2f984f34bcf85d59" dependencies = [ "heck", - "proc-macro2 0.4.30", - "quote 0.6.13", - "syn 0.15.44", -] - -[[package]] -name = "syn" -version = "0.15.44" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9ca4b3b69a77cbe1ffc9e198781b7acb0c7365a883670e8f1c1bc66fba79a5c5" -dependencies = [ - "proc-macro2 0.4.30", - "quote 0.6.13", - "unicode-xid", + "proc-macro2", + "quote", + "rustversion", + "syn", ] [[package]] @@ -1522,8 +1228,8 @@ version = "1.0.107" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1f4064b5b16e03ae50984a5a8ed5d4f8803e6bc1fd170a3cda91a1be4b18e3f5" dependencies = [ - "proc-macro2 1.0.50", - "quote 1.0.23", + "proc-macro2", + "quote", "unicode-ident", ] @@ -1562,9 +1268,9 @@ version = "1.0.38" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1fb327af4685e4d03fa8cbcf1716380da910eeb2bb8be417e7f9fd3fb164f36f" dependencies = [ - "proc-macro2 1.0.50", - "quote 1.0.23", - "syn 1.0.107", + "proc-macro2", + "quote", + "syn", ] [[package]] @@ -1593,30 +1299,17 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cda74da7e1a664f795bb1f8a87ec406fb89a02522cf6e50620d016add6dbbf5c" -[[package]] -name = "tokio" -version = "0.3.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "46409491c9375a693ce7032101970a54f8a2010efb77e13f70788f0d84489e39" -dependencies = [ - "autocfg 1.1.0", - "libc", - "mio 0.7.14", - "pin-project-lite", - "slab", -] - [[package]] name = "tokio" version = "1.24.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "597a12a59981d9e3c38d216785b0c37399f6e415e8d0712047620f189371b0bb" dependencies = [ - "autocfg 1.1.0", - "bytes 1.3.0", + "autocfg", + "bytes", "libc", "memchr", - "mio 0.8.5", + "mio", "num_cpus", "parking_lot", "pin-project-lite", @@ -1632,9 +1325,20 @@ version = "1.8.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d266c00fde287f55d3f1c3e96c500c362a2b8c695076ec180f27918820bc6df8" dependencies = [ - "proc-macro2 1.0.50", - "quote 1.0.23", - "syn 1.0.107", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "tokio-rustls" +version = "0.23.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c43ee83903113e03984cb9e5cebe6c04a5116269e900e3ddba8f068a62adda59" +dependencies = [ + "rustls", + "tokio", + "webpki", ] [[package]] @@ -1656,9 +1360,9 @@ version = "0.1.23" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4017f8f45139870ca7e672686113917c71c7a6e02d4924eda67186083c03081a" dependencies = [ - "proc-macro2 1.0.50", - "quote 1.0.23", - "syn 1.0.107", + "proc-macro2", + "quote", + "syn", ] [[package]] @@ -1682,32 +1386,34 @@ dependencies = [ [[package]] name = "tungstenite" -version = "0.11.1" +version = "0.17.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f0308d80d86700c5878b9ef6321f020f29b1bb9d5ff3cab25e75e23f3a492a23" +checksum = "e27992fd6a8c29ee7eef28fc78349aa244134e10ad447ce3b9f0ac0ed0fa4ce0" dependencies = [ "base64", "byteorder", - "bytes 0.5.6", + "bytes", "http", "httparse", - "input_buffer", "log", - "rand 0.7.3", + "rand", + "rustls", "sha-1", + "thiserror", "url", "utf-8", + "webpki", ] [[package]] name = "typed-builder" -version = "0.6.0" +version = "0.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "85fc4459191c621a53ef6c6ca5642e6e0e5ccc61f3e5b8ad6b6ab5317f0200fb" +checksum = "47a126a40dbff39e8320900cd61b8de053a2706e1f782cd27145792feb8fd41e" dependencies = [ - "proc-macro2 1.0.50", - "quote 1.0.23", - "syn 1.0.107", + "proc-macro2", + "quote", + "syn", ] [[package]] @@ -1718,13 +1424,12 @@ checksum = "497961ef93d974e23eb6f433eb5fe1b7930b659f06d12dec6fc44a8f554c0bba" [[package]] name = "ulid" -version = "0.4.1" +version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b7e95a59b292ca0cf9b45be2e52294d1ca6cb24eb11b08ef4376f73f1a00c549" +checksum = "220b18413e1fe5e85a5580b22f44241f82404a66c792c9f3c9eda74c52d9a22e" dependencies = [ "chrono", - "lazy_static", - "rand 0.6.5", + "rand", "serde", ] @@ -1758,24 +1463,12 @@ dependencies = [ "tinyvec", ] -[[package]] -name = "unicode-segmentation" -version = "1.10.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0fdbf052a0783de01e944a6ce7a8cb939e295b1e7be835a1112c3b9a7f047a5a" - [[package]] name = "unicode-width" version = "0.1.10" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c0edd1e5b14653f783770bce4a4dabb4a5108a5370a5f5d8cfe8710c361f6c8b" -[[package]] -name = "unicode-xid" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fc72304796d0818e357ead4e000d19c9c174ab23dc11093ac919054d20a6a7fc" - [[package]] name = "untrusted" version = "0.7.1" @@ -1802,11 +1495,11 @@ checksum = "09cc8ee72d2a9becf2f2febe0205bbed8fc6615b7cb429ad062dc7b7ddd036a9" [[package]] name = "uuid" -version = "0.8.2" +version = "1.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bc5cf98d8186244414c848017f0e2676b3fcb46807f6668a97dfe67359a3c4b7" +checksum = "422ee0de9031b5b948b97a8fc04e3aa35230001a722ddd27943e0be31564ce4c" dependencies = [ - "getrandom 0.2.8", + "getrandom", "serde", ] @@ -1828,12 +1521,6 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9d5b2c62b4012a3e1eca5a7e077d13b3bf498c4073e33ccd58626607748ceeca" -[[package]] -name = "wasi" -version = "0.9.0+wasi-snapshot-preview1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cccddf32554fecc6acb585f82a32a72e28b48f8c4c1883ddfeeeaa96f7d8e519" - [[package]] name = "wasi" version = "0.10.0+wasi-snapshot-preview1" @@ -1865,9 +1552,9 @@ dependencies = [ "bumpalo", "log", "once_cell", - "proc-macro2 1.0.50", - "quote 1.0.23", - "syn 1.0.107", + "proc-macro2", + "quote", + "syn", "wasm-bindgen-shared", ] @@ -1877,7 +1564,7 @@ version = "0.2.83" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "052be0f94026e6cbc75cdefc9bae13fd6052cdcaf532fa6c45e7ae33a1e6c810" dependencies = [ - "quote 1.0.23", + "quote", "wasm-bindgen-macro-support", ] @@ -1887,9 +1574,9 @@ version = "0.2.83" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "07bc0c051dc5f23e307b13285f9d75df86bfdf816c5721e573dec1f9b8aa193c" dependencies = [ - "proc-macro2 1.0.50", - "quote 1.0.23", - "syn 1.0.107", + "proc-macro2", + "quote", + "syn", "wasm-bindgen-backend", "wasm-bindgen-shared", ] @@ -1912,9 +1599,9 @@ dependencies = [ [[package]] name = "webpki" -version = "0.21.4" +version = "0.22.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b8e38c0608262c46d4a56202ebabdeb094cef7e560ca7a226c6bf055188aa4ea" +checksum = "f095d78192e208183081cc07bc5515ef55216397af48b873e5edcd72637fa1bd" dependencies = [ "ring", "untrusted", @@ -1922,13 +1609,22 @@ dependencies = [ [[package]] name = "webpki-roots" -version = "0.20.0" +version = "0.22.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0f20dea7535251981a9670857150d571846545088359b28e4951d350bdaf179f" +checksum = "b6c71e40d7d2c34a5106301fb632274ca37242cd0c9d3e64dbece371a40a2d87" dependencies = [ "webpki", ] +[[package]] +name = "wepoll-ffi" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d743fdedc5c64377b5fc2bc036b01c7fd642205a0d96356034ae3404d49eb7fb" +dependencies = [ + "cc", +] + [[package]] name = "winapi" version = "0.3.9" diff --git a/kkdisp/src/component.rs b/kkdisp/src/component.rs index d765a29..8957cca 100644 --- a/kkdisp/src/component.rs +++ b/kkdisp/src/component.rs @@ -17,11 +17,12 @@ pub enum Component { } impl Component { - fn debug(&self) -> String { + #[cfg(test)] + pub fn debug(&self) -> String { match self { Component::NextLine => "NextLine".to_string(), Component::X(x) => format!("X({})", x), - Component::String(s) => format!("\"{}\"", s), + Component::String(s) => format!("\"{}\"({})", s, s.len()), Component::Fg(c) => format!("FG({:#?})", c) .replace('\n', "") .replace(' ', ""), @@ -564,7 +565,7 @@ mod tests { "Scrollable widget: no scrolling", Instruction::start() .fixed(10, vec![scrolling_widget]), - (0..10) + (90..100) .into_iter() .map(|num| { vec![ @@ -587,7 +588,7 @@ mod tests { ( "Scrollable widget: scrolled by 3", Instruction::start().fixed(10, vec![scrolled_by_3]), - (0..10) + (87..97) .into_iter() .map(|num| { vec![ diff --git a/kkdisp/src/lib.rs b/kkdisp/src/lib.rs index 7392c7b..a6b6fca 100644 --- a/kkdisp/src/lib.rs +++ b/kkdisp/src/lib.rs @@ -166,10 +166,14 @@ impl PlanState { action: Action, scr: &mut Screen, ) -> Result { + let term_size = termion::terminal_size()?; let mut new = match action { - Action::ReplaceAll(layers) => { - Self::from_plans(layers, self.base_colorset)? - } + Action::ReplaceAll(layers) => Self::new( + layers, + self.base_colorset, + term_size, + self.last_render, + ), Action::ReplaceLayer(layer, index) => { if index >= self.plans.len() { return Err(anyhow::anyhow!( @@ -184,12 +188,22 @@ impl PlanState { Action::PushLayer(layer) => { let mut layers = self.plans; layers.push(layer); - Self::from_plans(layers, self.base_colorset)? + Self::new( + layers, + self.base_colorset, + term_size, + self.last_render, + ) } Action::PopLayer => { let mut layers = self.plans; layers.pop(); - Self::from_plans(layers, self.base_colorset)? + Self::new( + layers, + self.base_colorset, + term_size, + self.last_render, + ) } Action::Nothing => return Ok(self), }; @@ -215,6 +229,9 @@ where let mut plans = PlanState::from_plans(view.init()?, base_colorset)?; plans.render(&mut screen)?; + // FIXME: current loop means that pasting a string with len >1 + // results in only the first character being rendered, until + // something else triggers a render loop { if let Some(msg) = view.query() { plans = plans.act_on( diff --git a/kkdisp/src/token.rs b/kkdisp/src/token.rs index 685222f..437229f 100644 --- a/kkdisp/src/token.rs +++ b/kkdisp/src/token.rs @@ -5,6 +5,7 @@ pub enum Token { Centered(Box), Limited(Box, usize), CharPad(Box, char, usize), + PadPercent(Box, u8), Fg(Box, Color), Bg(Box, Color), Link(Box, String), @@ -51,18 +52,41 @@ impl Token { Self::CharPad(Box::new(self), ' ', pad_to) } - pub fn str_len(&self) -> usize { + pub fn pad_percent(self, pct: u8) -> Self { + #[cfg(debug_assertions)] + if pct > 100 { + panic!("pad_percent with >100% width: {}", pct); + } + Self::PadPercent(Box::new(self), 100.min(pct)) + } + + // Returns (str_count, str_len_total) + pub fn str_len(&self, total_width: usize) -> (usize, usize) { match self { - Token::String(t, s) => s.len() + t.str_len(), - Token::Fg(t, _) => t.str_len(), - Token::Bg(t, _) => t.str_len(), - Token::Link(t, _) => t.str_len(), - Token::Centered(t) => t.str_len(), - Token::Limited(t, lim) => (*lim).min(t.str_len()), - Token::CharPad(t, _, pad_to) => { - (*pad_to).max(t.str_len()) + Token::String(t, s) => { + let (count, len) = t.str_len(total_width); + (count + 1, len + s.len()) + } + Token::Fg(t, _) => t.str_len(total_width), + Token::Bg(t, _) => t.str_len(total_width), + Token::Link(t, _) => t.str_len(total_width), + Token::Centered(t) => t.str_len(total_width), + Token::Limited(t, lim) => { + let (count, len) = t.str_len(total_width); + (count, (*lim).min(len)) + } + Token::CharPad(t, _, pad_to) => { + let (count, len) = t.str_len(total_width); + (count, (*pad_to).max(len)) + } + Token::End => (0, 0), + Token::PadPercent(t, pct) => { + let (count, len) = t.str_len(total_width); + ( + count, + ((*pct as usize * total_width) / 100).max(len), + ) } - Token::End => 0, } } @@ -78,6 +102,7 @@ impl Token { Token::Link(next, _) => next.has_centered(), Token::String(next, _) => next.has_centered(), Token::End => false, + Token::PadPercent(next, _) => next.has_centered(), } } @@ -113,13 +138,13 @@ impl Token { .chain(t.with_width(width)) .collect(), Token::Link(t, name) => { - vec![Component::Link(name, t.str_len())] + vec![Component::Link(name, t.str_len(width).1)] .into_iter() .chain(t.with_width(width)) .collect() } Token::Centered(cnt) => { - let mut str_len = cnt.str_len(); + let mut str_len = cnt.str_len(width).1; let components = if str_len > width { str_len = width; cnt.limited(width).with_width(width) @@ -170,6 +195,43 @@ impl Token { .chain(t.with_width(width)) .collect(), Token::End => vec![], + Token::PadPercent(next, pct) => { + // FIXME: I feel like this'll be a problem + // at some point but I cba to deal with it rn + let (str_cnt, str_len) = next.str_len(width); + let actual_pad = (pct as usize * width) / 100; + let mut str_idx = 0; + next.with_width(width) + .into_iter() + .map(|comp| { + if let Component::String(s) = comp { + str_idx += 1; + if str_idx != str_cnt { + // Continue as this isn't the end + Component::String(s) + } else if str_len >= actual_pad { + // FIXME: this is probably THE BAD + Component::String({ + let mut s = s; + s.truncate( + actual_pad + - (str_len - s.len()), + ); + s + }) + } else { + Component::String(format!( + "{}{}", + s, + " ".repeat(actual_pad - str_len) + )) + } + } else { + comp + } + }) + .collect() + } } } } @@ -180,7 +242,7 @@ mod tests { #[test] fn test_token_gen() { - const WIDTH: usize = 20; + const WIDTH: usize = 100; vec![ ( "string -> string", @@ -281,6 +343,48 @@ mod tests { Component::String("learn more".into()), ], ), + ( + "padding percentage", + Token::text("this gets longer").pad_percent(100), + vec![Component::String( + "this gets longer".to_string() + + &" " + .repeat(WIDTH - "this gets longer".len()), + )], + ), + ( + "pad percent with centering", + Token::text("all to the middle") + .pad_percent(60) + .centered(), + vec![ + Component::X((WIDTH - (WIDTH * 60) / 100) / 2), + Component::String( + "all to the middle".to_string() + + &" ".repeat( + ((WIDTH * 60) / 100) + - "all to the middle".len(), + ), + ), + ], + ), + ( + "two strings, padded pct", + Token::text("two") + .bg(Color::BLUE) + .string("one") + .pad_percent(80) + .centered(), + vec![ + Component::X((WIDTH - ((WIDTH * 80) / 100)) / 2), + Component::String("one".into()), + Component::Bg(Color::BLUE), + Component::String( + "two".to_string() + + &" ".repeat(((WIDTH * 80) / 100) - 6), + ), + ], + ), ] .into_iter() .for_each(|(name, token, expected)| { @@ -298,12 +402,12 @@ mod tests { assert!( exp == *act, "<{}>: component at index {} mismatch. - expected:\n{:#?} - actual:\n{:#?}", + expected:\n{} + actual:\n{}", &name, i, - exp, - act, + exp.debug(), + act.debug(), ); } }) diff --git a/kkdisp/src/view.rs b/kkdisp/src/view.rs index d0d1605..36a3037 100644 --- a/kkdisp/src/view.rs +++ b/kkdisp/src/view.rs @@ -21,7 +21,11 @@ impl From for Key { termion::event::Key::Delete => Self::Delete, termion::event::Key::Insert => Self::Insert, termion::event::Key::F(f) => Self::F(f), - termion::event::Key::Char(c) => Self::Char(c), + termion::event::Key::Char(c) => match c { + '\n' => Self::Return, + '\t' => Self::Tab, + _ => Self::Char(c), + }, termion::event::Key::Alt(c) => Self::Alt(c), termion::event::Key::Ctrl(c) => Self::Ctrl(c), termion::event::Key::Null => Self::Null, @@ -51,4 +55,6 @@ pub enum Key { Ctrl(char), Null, Esc, + Return, + Tab, } diff --git a/kkx/Cargo.toml b/kkx/Cargo.toml index 933610c..ae35965 100644 --- a/kkx/Cargo.toml +++ b/kkx/Cargo.toml @@ -8,11 +8,13 @@ edition = "2021" [dependencies] anyhow = "1.0.68" kkdisp = { version = "0.1.0", path = "../kkdisp" } +futures = "0.3.25" [dependencies.tokio] version = "1.24.2" features = ["full"] [dependencies.misskey] -version = "*" +git = "https://github.com/coord-e/misskey-rs" +branch = "develop" features = ["websocket-client"] diff --git a/kkx/src/login.rs b/kkx/src/login.rs index 2041d3c..1b73650 100644 --- a/kkx/src/login.rs +++ b/kkx/src/login.rs @@ -1,3 +1,4 @@ +use futures::stream::TryStreamExt; use kkdisp::{ component::{Plan, Widget}, theme::Color, @@ -5,6 +6,8 @@ use kkdisp::{ view::{Event, Key}, Action, }; +use misskey::{StreamingClientExt, WebSocketClient}; +use tokio::sync::mpsc::{self, Receiver, Sender}; use crate::Message; pub enum LoginFocus { @@ -27,15 +30,7 @@ pub struct LoginPrompt { token: String, error: Option, focus: LoginFocus, -} - -impl From<&LoginPrompt> for Plan { - fn from(value: &LoginPrompt) -> Self { - Plan::start() - .fill(vec![]) - .fixed(8, vec![Widget::new(100, value.tokens())]) - .fill(vec![]) - } + client: Option, } impl LoginPrompt { @@ -45,9 +40,17 @@ impl LoginPrompt { token: String::new(), error: None, focus: LoginFocus::Hostname, + client: None, } } + pub fn plan(&self) -> Plan { + Plan::start() + .fill(vec![]) + .fixed(8, vec![Widget::new(100, self.tokens())]) + .fill(vec![]) + } + fn backspace(&mut self) { match self.focus { LoginFocus::Hostname => { @@ -59,11 +62,26 @@ impl LoginPrompt { LoginFocus::OK => {} } } - - pub fn attempt(&self) -> Result<(), anyhow::Error> { + pub fn query(&mut self) -> Option<()> { todo!() } + pub fn attempt(&mut self) { + let hostname = self.hostname.clone(); + if hostname.len() == 0 { + self.error = Some("empty hostname".into()); + self.focus = LoginFocus::Hostname; + return; + } + let token = self.token.clone(); + if token.len() == 0 { + self.error = Some("empty token".into()); + self.focus = LoginFocus::Token; + return; + } + todo!(); + } + pub fn update( &mut self, event: Event, @@ -71,13 +89,29 @@ impl LoginPrompt { match event { Event::Link(lnk) => { if lnk == "ok" { - todo!() + self.attempt(); + Ok(Action::ReplaceAll(vec![self.plan()])) + } else if lnk == "token" { + self.focus = LoginFocus::Token; + Ok(Action::ReplaceAll(vec![self.plan()])) + } else if lnk == "hostname" { + self.focus = LoginFocus::Hostname; + Ok(Action::ReplaceAll(vec![self.plan()])) } else { Ok(Action::Nothing) } } Event::Input(input) => { match input { + Key::Return => match self.focus { + LoginFocus::Hostname => { + self.focus = LoginFocus::Token; + } + LoginFocus::Token => { + self.focus = LoginFocus::OK; + } + LoginFocus::OK => self.attempt(), + }, Key::Backspace => self.backspace(), Key::Up => { self.focus = match self.focus { @@ -93,24 +127,11 @@ impl LoginPrompt { LoginFocus::OK => LoginFocus::Hostname, }; } - Key::Char(c) => { - if c == '\n' { - if self.focus.ok() { - self.attempt()?; - } - } else if c == '\t' { - } else { - match self.focus { - LoginFocus::Hostname => { - self.hostname.push(c) - } - LoginFocus::Token => { - self.token.push(c) - } - LoginFocus::OK => {} - } - } - } + Key::Char(c) => match self.focus { + LoginFocus::Hostname => self.hostname.push(c), + LoginFocus::Token => self.token.push(c), + LoginFocus::OK => {} + }, Key::Ctrl(c) => { if c == 'u' || c == 'U' { match self.focus { @@ -131,16 +152,17 @@ impl LoginPrompt { return Ok(Action::Nothing); } }; - Ok(Action::ReplaceAll(vec![(&*self).into()])) + Ok(Action::ReplaceAll(vec![self.plan()])) } Event::Message(_) => todo!(), } } fn tokens(&self) -> Vec { - let mut hostname = - Token::text(self.hostname.clone()).padded(10); - let mut token = Token::text(self.token.clone()).padded(10); + const HOSTNAME_PROMPT: &str = "hostname: "; + const TOKEN_PROMPT: &str = "token: "; + let mut hostname = Token::text(self.hostname.clone()); + let mut token = Token::text(self.token.clone()); let mut ok = Token::text("[ok]"); match self.focus { LoginFocus::Hostname => { @@ -156,11 +178,22 @@ impl LoginPrompt { .centered(), Token::End, match &self.error { - Some(e) => Token::text(e).fg(Color::RED), + Some(e) => Token::text(e) + .fg(Color::RED) + .pad_percent(80) + .centered(), None => Token::End, }, - hostname.string("hostname: ").centered(), - token.string("token: ").centered(), + hostname + .string(HOSTNAME_PROMPT) + .link("hostname") + .pad_percent(80) + .centered(), + token + .string(TOKEN_PROMPT) + .link("token") + .pad_percent(80) + .centered(), ok.link("ok").centered(), ] } diff --git a/kkx/src/main.rs b/kkx/src/main.rs index 1be6ab7..f7065e1 100644 --- a/kkx/src/main.rs +++ b/kkx/src/main.rs @@ -24,7 +24,7 @@ pub enum Page { impl Page { fn init(&self) -> Result { match self { - Page::Login(log) => Ok(vec![log.into()]), + Page::Login(log) => Ok(vec![log.plan()]), } } }