From 5f47ff501f531ac00183e032fd6ef1f1e40d870a Mon Sep 17 00:00:00 2001 From: x86y Date: Thu, 28 Mar 2024 11:58:40 +0400 Subject: [PATCH] begin k integration --- Cargo.lock | 197 +++++++++++++++++++++++++++++----- Cargo.toml | 23 ++-- src/views/panes/calculator.rs | 37 ++++--- 3 files changed, 199 insertions(+), 58 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index b090e76..b4b35b0 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -46,6 +46,15 @@ dependencies = [ "zerocopy", ] +[[package]] +name = "aho-corasick" +version = "1.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e60d3430d3a69478ad0993f19238d2df97c507009a52b3c10addcd7f6bcb916" +dependencies = [ + "memchr", +] + [[package]] name = "aliasable" version = "0.1.3" @@ -138,18 +147,19 @@ dependencies = [ [[package]] name = "async-tungstenite" -version = "0.23.0" +version = "0.25.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a1e9efbe14612da0a19fb983059a0b621e9cf6225d7018ecab4f9988215540dc" +checksum = "ef0f8d64ef9351752fbe5462f242c625d9c4910d2bc3f7ec44c43857ca123f5d" dependencies = [ "futures-io", "futures-util", "log", "pin-project-lite", + "rustls-pki-types", "tokio", - "tokio-rustls 0.24.1", - "tungstenite 0.20.1", - "webpki-roots 0.25.4", + "tokio-rustls 0.25.0", + "tungstenite", + "webpki-roots 0.26.1", ] [[package]] @@ -208,6 +218,29 @@ dependencies = [ "url", ] +[[package]] +name = "bindgen" +version = "0.65.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cfdf7b466f9a4903edc73f95d6d2bcd5baf8ae620638762244d3f60143643cc5" +dependencies = [ + "bitflags 1.3.2", + "cexpr", + "clang-sys", + "lazy_static", + "lazycell", + "log", + "peeking_take_while", + "prettyplease", + "proc-macro2", + "quote", + "regex", + "rustc-hash", + "shlex", + "syn 2.0.53", + "which", +] + [[package]] name = "bit-set" version = "0.5.3" @@ -361,6 +394,15 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6d43a04d8753f35258c91f8ec639f792891f748a1edbd759cf1dcea3382ad83c" +[[package]] +name = "cexpr" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6fac387a98bb7c37292057cffc56d62ecb629900026402633ae9160df93a8766" +dependencies = [ + "nom 7.1.3", +] + [[package]] name = "cfg-if" version = "1.0.0" @@ -394,6 +436,17 @@ dependencies = [ "windows-targets 0.52.4", ] +[[package]] +name = "clang-sys" +version = "1.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "67523a3b4be3ce1989d607a828d036249522dd9c1c8de7f4dd2dae43a37369d1" +dependencies = [ + "glob", + "libc", + "libloading 0.8.3", +] + [[package]] name = "clipboard-win" version = "5.3.0" @@ -791,6 +844,7 @@ dependencies = [ "iced", "iced_futures", "meval", + "ngnk", "serde", "serde_json", "tokio", @@ -1150,6 +1204,12 @@ version = "0.25.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "151665d9be52f9bb40fc7966565d39666f2d1e69233571b71b87791c7e0528b3" +[[package]] +name = "glob" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d2fabcfbdc87f4758337ca535fb41a6d701b65693ce38287d856d1674551ec9b" + [[package]] name = "glow" version = "0.13.1" @@ -1323,6 +1383,15 @@ version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dfa686283ad6dd069f105e5ab091b04c62850d3e4cf5d67debad1933f55023df" +[[package]] +name = "home" +version = "0.5.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e3d1354bf6b7235cb4a0576c2619fd4ed18183f689b12b006a0ee7329eeff9a5" +dependencies = [ + "windows-sys 0.52.0", +] + [[package]] name = "http" version = "0.2.12" @@ -1790,6 +1859,12 @@ version = "1.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" +[[package]] +name = "lazycell" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "830d08ce1d1d941e6b30645f1a0eb5643013d835ce3779a5fc208261dbe10f55" + [[package]] name = "lebe" version = "0.5.2" @@ -1942,7 +2017,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f79496a5651c8d57cd033c5add8ca7ee4e3d5f7587a4777484640d9cb60392d9" dependencies = [ "fnv", - "nom", + "nom 1.2.4", ] [[package]] @@ -1951,6 +2026,12 @@ version = "0.3.17" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6877bb514081ee2a7ff5ef9de3281f14a4dd4bceac4c09388074a6b5df8a139a" +[[package]] +name = "minimal-lexical" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a" + [[package]] name = "miniz_oxide" version = "0.7.2" @@ -2028,12 +2109,31 @@ dependencies = [ "jni-sys", ] +[[package]] +name = "ngnk" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ad2596587b5eb936642ff49304d4a6b32b9a9be93e6a82faf7a11ae763edea30" +dependencies = [ + "bindgen", +] + [[package]] name = "nom" version = "1.2.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a5b8c256fd9471521bcb84c3cdba98921497f1a331cbc15b8030fc63b82050ce" +[[package]] +name = "nom" +version = "7.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d273983c5a657a70a3e8f2a01329822f3b8c8172b73826411a55751e404a0a4a" +dependencies = [ + "memchr", + "minimal-lexical", +] + [[package]] name = "num-traits" version = "0.2.18" @@ -2270,6 +2370,12 @@ version = "1.0.14" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "de3145af08024dea9fa9914f381a17b8fc6034dfb00f3a84013f7ff43f29ed4c" +[[package]] +name = "peeking_take_while" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "19b17cddbe7ec3f8bc800887bab5e717348c95ea2ca0b1bf0837fb964dc67099" + [[package]] name = "percent-encoding" version = "2.3.1" @@ -2381,6 +2487,16 @@ version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e8cf8e6a8aa66ce33f63993ffc4ea4271eb5b0530a9002db8455ea6050c77bfa" +[[package]] +name = "prettyplease" +version = "0.2.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8d3928fb5db768cb86f891ff014f0144589297e3c6a1aba6ed7cecfdace270c7" +dependencies = [ + "proc-macro2", + "syn 2.0.53", +] + [[package]] name = "proc-macro-crate" version = "3.1.0" @@ -2566,6 +2682,35 @@ dependencies = [ "thiserror", ] +[[package]] +name = "regex" +version = "1.10.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c117dbdfde9c8308975b6a18d71f3f385c89461f7b3fb054288ecf2a2058ba4c" +dependencies = [ + "aho-corasick", + "memchr", + "regex-automata", + "regex-syntax", +] + +[[package]] +name = "regex-automata" +version = "0.4.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "86b83b8b9847f9bf95ef68afb0b8e6cdb80f498442f5179a29fad448fcc1eaea" +dependencies = [ + "aho-corasick", + "memchr", + "regex-syntax", +] + +[[package]] +name = "regex-syntax" +version = "0.8.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "adad44e29e4c806119491a7f06f03de4d1af22c3a680dd47f1e6e179439d1f56" + [[package]] name = "renderdoc-sys" version = "1.1.0" @@ -2921,6 +3066,12 @@ dependencies = [ "digest", ] +[[package]] +name = "shlex" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64" + [[package]] name = "signal-hook-registry" version = "1.4.1" @@ -3341,7 +3492,7 @@ dependencies = [ "rustls-pki-types", "tokio", "tokio-rustls 0.25.0", - "tungstenite 0.21.0", + "tungstenite", "webpki-roots 0.26.1", ] @@ -3431,26 +3582,6 @@ version = "0.20.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "17f77d76d837a7830fe1d4f12b7b4ba4192c1888001c7164257e4bc6d21d96b4" -[[package]] -name = "tungstenite" -version = "0.20.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9e3dac10fd62eaf6617d3a904ae222845979aec67c615d1c842b4002c7666fb9" -dependencies = [ - "byteorder", - "bytes", - "data-encoding", - "http 0.2.12", - "httparse", - "log", - "rand", - "rustls 0.21.10", - "sha1", - "thiserror", - "url", - "utf-8", -] - [[package]] name = "tungstenite" version = "0.21.0" @@ -4006,6 +4137,18 @@ dependencies = [ "web-sys", ] +[[package]] +name = "which" +version = "4.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87ba24419a2078cd2b0f2ede2691b6c66d8e47836da3b6db8265ebad47afbfc7" +dependencies = [ + "either", + "home", + "once_cell", + "rustix", +] + [[package]] name = "widestring" version = "1.0.2" diff --git a/Cargo.toml b/Cargo.toml index efbe1ec..5054121 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -3,6 +3,10 @@ name = "dynasty" version = "0.1.0" edition = "2021" description = "Desktop terminal for cryptocurrency exchanges" +[package.metadata.bundle] +name = "Dynasty" +identifier = "io.github.me.dynasty" +icon = ["assets/dynasty.icns"] [dependencies] binance-rs-async = { version = "1.3.2", default_features = false, features = ["rustls-tls", "wallet_api"] } @@ -13,23 +17,14 @@ iced_futures = "0.12.0" meval = "0.2.0" serde = { version = "1.0.197", features = ["derive"] } serde_json = "1.0.114" +async-tungstenite = { version = "0.25", features = ["tokio-rustls-webpki-roots"]} +tokio = { version = "1.32.0", default-features = false, features=["sync"]} +ngnk = { version = "*", optional = true } -[dependencies.async-tungstenite] -version = "0.23" -features = ["tokio-rustls-webpki-roots"] - -[dependencies.tokio] -version = "1.32.0" -default-features = false -features = ["sync"] +[features] +k = ["dep:ngnk"] [target.'cfg(not(target_arch = "wasm32"))'.dependencies] directories-next = "2.0" - [target.'cfg(target_arch = "wasm32")'.dependencies] web-sys = { version = "0.3", features = ["Window", "Storage"] } - -[package.metadata.bundle] -name = "Dynasty" -identifier = "io.github.me.dynasty" -icon = ["assets/dynasty.icns"] diff --git a/src/views/panes/calculator.rs b/src/views/panes/calculator.rs index 6f3b427..b25f1dc 100644 --- a/src/views/panes/calculator.rs +++ b/src/views/panes/calculator.rs @@ -7,7 +7,24 @@ use iced::{ }, Element, Font, Length, }; -use meval::{Context, Expr}; +use meval::Context; + +#[cfg(not(feature = "k"))] +fn e(line: &str, ctx: &Context) -> String { + use meval::Expr; + format!( + "{}", + line.parse::() + .unwrap() + .eval_with_context(ctx) + .unwrap_or_default() + ) +} +#[cfg(feature = "k")] +fn e(line: &str, _ctx: &Context) -> String { + use ngnk::K0; + K0(line.to_string(), vec![]).to_string() +} pub fn calculator_view<'a>( content: &'a Content, @@ -19,14 +36,7 @@ pub fn calculator_view<'a>( column![ text_editor::TextEditor::new(content) .height(Length::Fill) - .on_action(Message::CalcAction), // .style(|_theme, _status| text_editor::Appearance { - // border: iced::Border { - // width: 0.0, - // radius: 0.0.into(), - // color: Default::default() - // }, - // background: iced::Background::Color(Color::from_rgb(0.07, 0.07, 0.07)), - // }) + .on_action(Message::CalcAction), container( button(text("\u{F4F5}").font(Font::with_name("bootstrap-icons"))) .style(iced::theme::Button::Custom(Box::new(GreenBtn {}))) @@ -42,14 +52,7 @@ pub fn calculator_view<'a>( content .text() .lines() - .map(|line| { - text( - line.parse::() - .unwrap() - .eval_with_context(ctx) - .unwrap_or_default(), - ) - }) + .map(|line| { text(e(line, ctx)) }) .map(Element::from) ), Space::new(Length::Fill, Length::Fill),