From 7c63f80d5ce59eb5034b6d747df042530538223d Mon Sep 17 00:00:00 2001 From: Brady Fomegne Date: Sat, 16 Sep 2023 13:09:32 +0100 Subject: [PATCH] feat: migration to clafrica v0.4.0 (#28) --- .gitignore | 3 + CHANGELOG.md | 5 +- Cargo.lock | 324 +++++++++++++++++++++++++++++++++-------- Cargo.toml | 7 +- data/blank_sample.toml | 0 data/sample.toml | 7 +- data/sample2.toml | 3 - data/suggestions.toml | 8 - rust-toolchain | 2 +- src/config.rs | 59 +------- src/lib.rs | 171 ++++++++++++---------- src/rstk_ext.rs | 10 +- 12 files changed, 376 insertions(+), 223 deletions(-) create mode 100644 data/blank_sample.toml delete mode 100644 data/sample2.toml delete mode 100644 data/suggestions.toml diff --git a/.gitignore b/.gitignore index c633913..d9cb0a2 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,7 @@ /target /tmp +*.swp +*.swo *~ *.swp +*.swn diff --git a/CHANGELOG.md b/CHANGELOG.md index b891611..89569d4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,9 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] -### Added +## [0.3.0] - 2023-09-16 -- Implement suggestions [(#20)](https://github.com/pythonbrad/clafrica-wish/pull/20) +### Changed +- Migration to clafrica V0.4.0 ## [0.2.1] - 2023-05-17 diff --git a/Cargo.lock b/Cargo.lock index 09d7ae2..8f97096 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2,43 +2,74 @@ # It is not intended for manual editing. version = 3 +[[package]] +name = "ahash" +version = "0.8.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2c99f64d1e06488f620f932677e24bc6e2897582980441ae90a671415bd7ec2f" +dependencies = [ + "cfg-if", + "const-random", + "getrandom", + "once_cell", + "version_check", +] + +[[package]] +name = "autocfg" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" + [[package]] name = "bitflags" version = "1.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" +[[package]] +name = "bitflags" +version = "2.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b4682ae6287fcf752ecaabbfcc7b6f9b72aa33933dc23a554d853aea8eea8635" + [[package]] name = "block" version = "0.1.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0d8c1fef690941d3e7788d328517591fecc684c084084702d6ff1641e993699a" +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + [[package]] name = "clafrica" -version = "0.3.1" +version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f69a329a18cdfe91040922c8f4258587f0c3950bbee35c13336a35f524429d7a" +checksum = "49a823888052ff2a15d2ffc0cee317307af912907d73cb26756bd125f513d310" dependencies = [ "clafrica-lib", "enigo", "rdev", + "rhai", "serde", "toml", ] [[package]] name = "clafrica-lib" -version = "0.3.0" +version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c949efb0e63ccfea4389cc246db0c8d15d27f9dc692339872eae039770a12f0" +checksum = "19ae5757ba7efe52b214cad71bd940f6b0f14f35735232b03a55ff33654fd21c" [[package]] name = "clafrica-wish" -version = "0.2.1" +version = "0.3.0" dependencies = [ "clafrica", - "enigo", "rstk", "serde", "toml", @@ -50,15 +81,37 @@ version = "0.22.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "667fdc068627a2816b9ff831201dd9864249d6ee8d190b9532357f1fc0f61ea7" dependencies = [ - "bitflags", + "bitflags 1.3.2", "block", "core-foundation 0.9.3", "core-graphics 0.21.0", - "foreign-types", + "foreign-types 0.3.2", "libc", "objc", ] +[[package]] +name = "const-random" +version = "0.1.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "368a7a772ead6ce7e1de82bfb04c485f3db8ec744f72925af5735e29a22cc18e" +dependencies = [ + "const-random-macro", + "proc-macro-hack", +] + +[[package]] +name = "const-random-macro" +version = "0.1.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9d7d6ab3c3a2282db210df5f02c4dab6e0a7057af0fb7ebd4070f30fe05c0ddb" +dependencies = [ + "getrandom", + "once_cell", + "proc-macro-hack", + "tiny-keccak", +] + [[package]] name = "core-foundation" version = "0.7.0" @@ -97,9 +150,9 @@ version = "0.19.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b3889374e6ea6ab25dba90bb5d96202f61108058361f6dc72e8b03e6f8bbe923" dependencies = [ - "bitflags", + "bitflags 1.3.2", "core-foundation 0.7.0", - "foreign-types", + "foreign-types 0.3.2", "libc", ] @@ -109,22 +162,22 @@ version = "0.21.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "52a67c4378cf203eace8fb6567847eb641fd6ff933c1145a115c6ee820ebb978" dependencies = [ - "bitflags", + "bitflags 1.3.2", "core-foundation 0.9.3", - "foreign-types", + "foreign-types 0.3.2", "libc", ] [[package]] name = "core-graphics" -version = "0.22.3" +version = "0.23.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2581bbab3b8ffc6fcbd550bf46c355135d16e9ff2a6ea032ad6b9bf1d7efe4fb" +checksum = "970a29baf4110c26fedbc7f82107d42c23f7e88e404c4577ed73fe99ff85a212" dependencies = [ - "bitflags", + "bitflags 1.3.2", "core-foundation 0.9.3", "core-graphics-types", - "foreign-types", + "foreign-types 0.5.0", "libc", ] @@ -134,18 +187,24 @@ version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2bb142d41022986c1d8ff29103a1411c8a3dfad3552f87a4f8dc50d61d4f4e33" dependencies = [ - "bitflags", + "bitflags 1.3.2", "core-foundation 0.9.3", "libc", ] +[[package]] +name = "crunchy" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7a81dae078cea95a014a339291cec439d2f232ebe854a9d672b796c6afafa9b7" + [[package]] name = "enigo" -version = "0.1.2" +version = "0.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "464c869256b1d6c1db151ab7a164fe0a5a6d340095460f92d7e8fba78ab47dc0" +checksum = "802e4b2ae123615659085369b453cba87c5562e46ed8050a909fee18a9bc3157" dependencies = [ - "core-graphics 0.22.3", + "core-graphics 0.23.1", "libc", "objc", "pkg-config", @@ -164,7 +223,28 @@ version = "0.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f6f339eb8adc052cd2ca78910fda869aefa38d22d5cb648e6485e4d3fc06f3b1" dependencies = [ - "foreign-types-shared", + "foreign-types-shared 0.1.1", +] + +[[package]] +name = "foreign-types" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d737d9aa519fb7b749cbc3b962edcf310a8dd1f4b67c91c4f83975dbdd17d965" +dependencies = [ + "foreign-types-macros", + "foreign-types-shared 0.3.1", +] + +[[package]] +name = "foreign-types-macros" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1a5c6c585bc94aaf2c7b51dd4c2ba22680844aba4c687be581871a6f518c5742" +dependencies = [ + "proc-macro2", + "quote", + "syn", ] [[package]] @@ -173,6 +253,23 @@ version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b" +[[package]] +name = "foreign-types-shared" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "aa9a19cbb55df58761df49b23516a86d432839add4af60fc256da840f66ed35b" + +[[package]] +name = "getrandom" +version = "0.2.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "be4136b2a15dd319360be1c07d9933517ccf0be8f16bf62a3bee4f0d618df427" +dependencies = [ + "cfg-if", + "libc", + "wasi", +] + [[package]] name = "hashbrown" version = "0.14.0" @@ -189,6 +286,15 @@ dependencies = [ "hashbrown", ] +[[package]] +name = "instant" +version = "0.1.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7a5bbe824c507c5da5956355e86a746d82e0e1464f65d862cc5e71da70e94b2c" +dependencies = [ + "cfg-if", +] + [[package]] name = "lazy_static" version = "1.4.0" @@ -197,9 +303,9 @@ checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" [[package]] name = "libc" -version = "0.2.147" +version = "0.2.148" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b4668fb0ea861c1df094127ac5f1da3409a82116a4ba74fca2e58ef927159bb3" +checksum = "9cdc71e17332e86d2e1d38c1f99edcb6288ee11b815fb1a4b049eaa2114d369b" [[package]] name = "malloc_buf" @@ -212,9 +318,18 @@ dependencies = [ [[package]] name = "memchr" -version = "2.5.0" +version = "2.6.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d" +checksum = "8f232d6ef707e1956a43342693d2a31e72989554d58299d7a88738cc95b0d35c" + +[[package]] +name = "num-traits" +version = "0.2.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f30b0abd723be7e2ffca1272140fac1a2f084c77ec3e123c192b66af1ee9e6c2" +dependencies = [ + "autocfg", +] [[package]] name = "objc" @@ -237,20 +352,26 @@ version = "0.3.27" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "26072860ba924cbfa98ea39c8c19b4dd6a4a25423dbdf219c1eca91aa0cf6964" +[[package]] +name = "proc-macro-hack" +version = "0.5.20+deprecated" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc375e1527247fe1a97d8b7156678dfe7c1af2fc075c9a4db3690ecd2a148068" + [[package]] name = "proc-macro2" -version = "1.0.66" +version = "1.0.67" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "18fb31db3f9bddb2ea821cde30a9f70117e3f119938b5ee630b7403aa6e2ead9" +checksum = "3d433d9f1a3e8c1263d9456598b16fec66f4acc9a74dacffd35c7bb09b3a1328" dependencies = [ "unicode-ident", ] [[package]] name = "quote" -version = "1.0.32" +version = "1.0.33" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "50f3b39ccfb720540debaa0164757101c08ecb8d326b15358ce76a62c7e85965" +checksum = "5267fca4496028628a95160fc423a33e8b2e6af8a5302579e322e4b520293cae" dependencies = [ "proc-macro2", ] @@ -271,6 +392,33 @@ dependencies = [ "x11", ] +[[package]] +name = "rhai" +version = "1.16.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "637a4f79f65571b1fd1a0ebbae05bbbf58a01faf612abbc3eea15cda34f0b87a" +dependencies = [ + "ahash", + "bitflags 2.4.0", + "instant", + "num-traits", + "once_cell", + "rhai_codegen", + "smallvec", + "smartstring", +] + +[[package]] +name = "rhai_codegen" +version = "1.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "853977598f084a492323fe2f7896b4100a86284ee8473612de60021ea341310f" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "rstk" version = "0.1.0" @@ -282,18 +430,18 @@ dependencies = [ [[package]] name = "serde" -version = "1.0.183" +version = "1.0.188" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "32ac8da02677876d532745a130fc9d8e6edfa81a269b107c5b00829b91d8eb3c" +checksum = "cf9e0fcba69a370eed61bcf2b728575f726b50b55cba78064753d708ddc7549e" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.183" +version = "1.0.188" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "aafe972d60b0b9bee71a91b92fee2d4fb3c9d7e8f6b179aa99f27203d99a4816" +checksum = "4eca7ac642d82aa35b60049a6eccb4be6be75e599bd2e9adb5f875a737654af2" dependencies = [ "proc-macro2", "quote", @@ -309,22 +457,54 @@ dependencies = [ "serde", ] +[[package]] +name = "smallvec" +version = "1.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "62bb4feee49fdd9f707ef802e22365a35de4b7b299de4763d44bfea899442ff9" + +[[package]] +name = "smartstring" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3fb72c633efbaa2dd666986505016c32c3044395ceaf881518399d2f4127ee29" +dependencies = [ + "autocfg", + "static_assertions", + "version_check", +] + +[[package]] +name = "static_assertions" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f" + [[package]] name = "syn" -version = "2.0.28" +version = "2.0.35" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "04361975b3f5e348b2189d8dc55bc942f278b2d482a6a0365de5bdd62d351567" +checksum = "59bf04c28bee9043ed9ea1e41afc0552288d3aba9c6efdd78903b802926f4879" dependencies = [ "proc-macro2", "quote", "unicode-ident", ] +[[package]] +name = "tiny-keccak" +version = "2.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2c9d3793400a45f954c52e73d068316d76b6f4e36977e3fcebb13a2721e80237" +dependencies = [ + "crunchy", +] + [[package]] name = "toml" -version = "0.7.6" +version = "0.7.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c17e963a819c331dcacd7ab957d80bc2b9a9c1e71c804826d2f283dd65306542" +checksum = "dd79e69d3b627db300ff956027cc6c3798cef26d22526befdfcd12feeb6d2257" dependencies = [ "serde", "serde_spanned", @@ -343,9 +523,9 @@ dependencies = [ [[package]] name = "toml_edit" -version = "0.19.14" +version = "0.19.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f8123f27e969974a3dfba720fdb560be359f57b44302d280ba72e76a74480e8a" +checksum = "1b5bb770da30e5cbfde35a2d7b9b8a2c4b8ef89548a7a6aeab5c9a576e3e7421" dependencies = [ "indexmap", "serde", @@ -356,9 +536,21 @@ dependencies = [ [[package]] name = "unicode-ident" -version = "1.0.11" +version = "1.0.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" + +[[package]] +name = "version_check" +version = "0.9.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" + +[[package]] +name = "wasi" +version = "0.11.0+wasi-snapshot-preview1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "301abaae475aa91687eb82514b328ab47a211a533026cb25fc3e519b86adfc3c" +checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" [[package]] name = "winapi" @@ -384,18 +576,28 @@ checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" [[package]] name = "windows" -version = "0.48.0" +version = "0.51.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ca229916c5ee38c2f2bc1e9d8f04df975b4bd93f9955dc69fabb5d91270045c9" +dependencies = [ + "windows-core", + "windows-targets", +] + +[[package]] +name = "windows-core" +version = "0.51.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e686886bc078bc1b0b600cac0147aadb815089b6e4da64016cbd754b6342700f" +checksum = "f1f8cf84f35d2db49a46868f947758c7a1138116f7fac3bc844f43ade1292e64" dependencies = [ "windows-targets", ] [[package]] name = "windows-targets" -version = "0.48.1" +version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "05d4b17490f70499f20b9e791dcf6a299785ce8af4d709018206dc5b4953e95f" +checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c" dependencies = [ "windows_aarch64_gnullvm", "windows_aarch64_msvc", @@ -408,51 +610,51 @@ dependencies = [ [[package]] name = "windows_aarch64_gnullvm" -version = "0.48.0" +version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "91ae572e1b79dba883e0d315474df7305d12f569b400fcf90581b06062f7e1bc" +checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" [[package]] name = "windows_aarch64_msvc" -version = "0.48.0" +version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b2ef27e0d7bdfcfc7b868b317c1d32c641a6fe4629c171b8928c7b08d98d7cf3" +checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" [[package]] name = "windows_i686_gnu" -version = "0.48.0" +version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "622a1962a7db830d6fd0a69683c80a18fda201879f0f447f065a3b7467daa241" +checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" [[package]] name = "windows_i686_msvc" -version = "0.48.0" +version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4542c6e364ce21bf45d69fdd2a8e455fa38d316158cfd43b3ac1c5b1b19f8e00" +checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" [[package]] name = "windows_x86_64_gnu" -version = "0.48.0" +version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ca2b8a661f7628cbd23440e50b05d705db3686f894fc9580820623656af974b1" +checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" [[package]] name = "windows_x86_64_gnullvm" -version = "0.48.0" +version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7896dbc1f41e08872e9d5e8f8baa8fdd2677f29468c4e156210174edc7f7b953" +checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" [[package]] name = "windows_x86_64_msvc" -version = "0.48.0" +version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1a515f5799fe4961cb532f983ce2b23082366b898e52ffbce459c86f67c8378a" +checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" [[package]] name = "winnow" -version = "0.5.10" +version = "0.5.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5504cc7644f4b593cbc05c4a55bf9bd4e94b867c3c0bd440934174d50482427d" +checksum = "7c2e3184b9c4e92ad5167ca73039d0c42476302ab603e2fec4487511f38ccefc" dependencies = [ "memchr", ] diff --git a/Cargo.toml b/Cargo.toml index 41cfb7e..89f0bc1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,19 +1,18 @@ [package] name = "clafrica-wish" -version = "0.2.1" +version = "0.3.0" edition = "2021" description = "Wish interface for the clafrica." repository = "https://github.com/pythonbrad/clafrica-wish" license = "MIT" readme = "README.md" -authors = ["Fomegne Brady "] +authors = ["Brady Fomegne "] keywords = ["african", "ime", "typing"] # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -clafrica = "0.3.1" -enigo = "0.1.2" +clafrica = "0.4.0" rstk = "0.1.0" serde = { version = "1.0.163", features = ["serde_derive"] } toml = "0.7.3" diff --git a/data/blank_sample.toml b/data/blank_sample.toml new file mode 100644 index 0000000..e69de29 diff --git a/data/sample.toml b/data/sample.toml index b6bb16a..971572b 100644 --- a/data/sample.toml +++ b/data/sample.toml @@ -1,6 +1,7 @@ [core] buffer_size = 20 page_size = 10 +auto_commit = false [theme] header.background = "#252320" @@ -10,9 +11,3 @@ body.background = "#dedddd" body.foreground = "#252320" body.font = { family = "Charis-SIL", size = 10, weight = "bold" } -[suggestions] -_hello = "Hi!" -sample = { path = "suggestions.toml" } - -[data] -_exit_ = "" \ No newline at end of file diff --git a/data/sample2.toml b/data/sample2.toml deleted file mode 100644 index 1584df2..0000000 --- a/data/sample2.toml +++ /dev/null @@ -1,3 +0,0 @@ -[suggestions] - -[data] \ No newline at end of file diff --git a/data/suggestions.toml b/data/suggestions.toml deleted file mode 100644 index 870ff69..0000000 --- a/data/suggestions.toml +++ /dev/null @@ -1,8 +0,0 @@ -[info] -name = "sample" -description = "Example of suggestion" -authors = ["Foo "] -website = "https://example.com" - -[suggestions] -_hi = "Hello!" \ No newline at end of file diff --git a/rust-toolchain b/rust-toolchain index 083b97b..cc31fcd 100644 --- a/rust-toolchain +++ b/rust-toolchain @@ -1 +1 @@ -1.68 +1.72 diff --git a/src/config.rs b/src/config.rs index bdc80f2..4186e0e 100644 --- a/src/config.rs +++ b/src/config.rs @@ -1,18 +1,10 @@ use serde::Deserialize; -use std::collections::HashMap; use std::{error, fs, path::Path}; use toml::{self}; #[derive(Deserialize, Debug)] pub struct Config { pub theme: Option, - pub core: Option, - suggestions: HashMap, -} - -#[derive(Deserialize, Debug)] -pub struct Core { - pub page_size: usize, } #[derive(Deserialize, Debug)] @@ -35,60 +27,13 @@ pub struct ThemeFont { pub weight: String, } -#[derive(Deserialize, Debug, Clone)] -#[serde(untagged)] -enum Data { - Simple(String), - File(DataFile), -} - -#[derive(Deserialize, Debug, Clone)] -struct DataFile { - path: String, -} - impl Config { pub fn from_file(filepath: &Path) -> Result> { let content = fs::read_to_string(filepath)?; - let mut config: Self = toml::from_str(&content)?; - - let config_path = filepath.parent().unwrap(); - - let mut suggestions = HashMap::new(); - - config.suggestions.iter().try_for_each( - |(key, value)| -> Result<(), Box> { - match value { - Data::File(DataFile { path }) => { - let filepath = config_path.join(path); - let conf = Config::from_file(&filepath)?; - suggestions.extend(conf.suggestions); - } - Data::Simple(_) => { - suggestions.insert(key.to_owned(), value.clone()); - } - }; - Ok(()) - }, - )?; - - config.suggestions = suggestions; + let config: Self = toml::from_str(&content)?; Ok(config) } - - pub fn extract_suggestions(&self) -> HashMap { - let mut suggestions = HashMap::new(); - - self.suggestions.iter().for_each(|(k, v)| { - match v { - Data::Simple(value) => suggestions.insert(k.to_owned(), value.to_owned()), - _ => None, - }; - }); - - suggestions - } } #[cfg(test)] @@ -101,7 +46,7 @@ mod tests { let config = Config::from_file(Path::new("./data/sample.toml")); assert!(config.is_ok()); - let config = Config::from_file(Path::new("./data/sample2.toml")); + let config = Config::from_file(Path::new("./data/blank_sample.toml")); assert!(config.is_ok()); } } diff --git a/src/lib.rs b/src/lib.rs index f718516..ad635f6 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -2,7 +2,6 @@ mod config; mod rstk_ext; use clafrica::api; -use enigo::{Enigo, Key, KeyboardControllable}; use rstk::*; use rstk_ext::*; use std::collections::HashMap; @@ -13,13 +12,12 @@ pub mod prelude { pub struct Wish { border: f64, - label: Option, - prediction_frame: Option, window: rstk::TkTopLevel, theme: HashMap<&'static str, Style>, - suggestions: HashMap, + predicates: Vec<(String, String, String)>, page_size: usize, - keyboard: Enigo, + current_predicate_id: usize, + input: String, } impl Wish { @@ -32,20 +30,13 @@ impl Wish { init_rstk_ext(); - let page_size = config.core.as_ref().map(|e| e.page_size).unwrap_or(10); - - let suggestions = config.extract_suggestions(); - let mut theme = HashMap::new(); if let Some(theme_config) = config.theme { let header_frame_style = Style { name: "header.TFrame", background: theme_config.header.background.to_owned(), - foreground: "".to_owned(), - font_size: 0, - font_family: "".to_owned(), - font_weight: "".to_owned(), + ..Default::default() }; header_frame_style.update(); theme.insert("HFrame", header_frame_style); @@ -64,10 +55,7 @@ impl Wish { let body_frame_style = Style { name: "body.TFrame", background: theme_config.body.background.to_owned(), - foreground: "".to_owned(), - font_size: 0, - font_family: "".to_owned(), - font_weight: "".to_owned(), + ..Default::default() }; body_frame_style.update(); theme.insert("BFrame", body_frame_style); @@ -86,13 +74,12 @@ impl Wish { Wish { window: wish, - label: None, border: 0.0, - prediction_frame: None, theme, - suggestions, - page_size, - keyboard: Enigo::new(), + predicates: Vec::new(), + page_size: 10, + current_predicate_id: 0, + input: "".to_owned(), } } @@ -105,21 +92,9 @@ impl Wish { self.window.topmost(true); self.window.deiconify(); - let header_frame = rstk::make_frame(&self.window); - if let Some(v) = self.theme.get("HFrame") { - header_frame.style(v); - } - - let label = rstk::make_label(&header_frame); + let label = rstk::make_label(&self.window); label.text("Type _exit_ to end the clafrica"); - if let Some(v) = self.theme.get("HLabel") { - label.style(v); - } - label.pack().side(PackSide::Left).layout(); - - header_frame.pack().fill(PackFill::X).layout(); - - self.label = Some(label); + label.pack().layout(); } } @@ -129,62 +104,98 @@ impl api::Frontend for Wish { } fn update_position(&mut self, position: (f64, f64)) { - { - let x = (position.0 + self.border) as u64; - let y = (position.1 + self.border) as u64; - self.window.position(x, y); + let x = (position.0 + self.border) as u64; + let y = (position.1 + self.border) as u64; + self.window.position(x, y); + } + + fn set_input(&mut self, text: &str) { + self.input = text.to_owned(); + } + + fn set_page_size(&mut self, size: usize) { + self.page_size = size; + } + + fn add_predicate(&mut self, code: &str, remaining_code: &str, text: &str) { + self.predicates + .push((code.to_owned(), remaining_code.to_owned(), text.to_owned())); + } + + fn clear_predicates(&mut self) { + self.predicates.clear(); + self.current_predicate_id = 0; + } + + fn previous_predicate(&mut self) { + if self.predicates.is_empty() { + return; + } + + self.current_predicate_id = + (self.current_predicate_id + self.predicates.len() - 1) % self.predicates.len(); + self.display(); + } + + fn next_predicate(&mut self) { + if self.predicates.is_empty() { + return; } + + self.current_predicate_id = (self.current_predicate_id + 1) % self.predicates.len(); + self.display(); } - fn update_text(&mut self, input: Vec) { - let input = input.into_iter().filter(|c| *c != '\0').collect::(); + fn get_selected_predicate(&self) -> Option<&(String, String, String)> { + self.predicates.get(self.current_predicate_id) + } - if input == "_exit_" { + fn display(&self) { + if self.input == "_exit_" { rstk::end_wish(); } - if let Some(label) = self.label.as_ref() { - label.text(&input); - } + self.window.clear(); + let header_frame = rstk::make_frame(&self.window); - self.prediction_frame.as_ref().map(TkWidget::destroy); + if let Some(v) = self.theme.get("HFrame") { + header_frame.style(v); + } - let prediction_frame = rstk::make_frame(&self.window); + let label = rstk::make_label(&header_frame); + label.text("Type _exit_ to end the clafrica"); - if input.len() > 1 { - self.suggestions - .iter() - .filter(|(code, _text)| code.starts_with(input.as_str())) - .take(self.page_size) - .enumerate() - .for_each(|(i, (code, text))| { - if code.len() == input.len() { - (0..code.len()).for_each(|_| self.keyboard.key_click(Key::Backspace)); - self.keyboard.key_sequence(text); - return; - } - - let frame = rstk::make_frame(&prediction_frame); - if let Some(v) = self.theme.get("BFrame") { - frame.style(v); - } - frame.pack().fill(PackFill::X).layout(); - - let label = rstk::make_label(&frame); - label.text(&format!( - "{}. {text} ~{}", - i + 1, - code.chars().skip(input.len()).collect::() - )); - if let Some(v) = self.theme.get("BLabel") { - label.style(v); - } - label.pack().side(PackSide::Left).layout(); - }); + if let Some(v) = self.theme.get("HLabel") { + label.style(v); } + label.pack().side(PackSide::Left).layout(); + header_frame.pack().fill(PackFill::X).layout(); + label.text(&self.input); - prediction_frame.pack().fill(PackFill::X).layout(); + let prediction_frame = rstk::make_frame(&self.window); + let page_size = std::cmp::min(self.page_size, self.predicates.len()); + self.predicates + .iter() + .enumerate() + .chain(self.predicates.iter().enumerate()) + .skip(self.current_predicate_id) + .take(page_size) + .for_each(|(i, (_code, remaining_code, text))| { + let frame = rstk::make_frame(&prediction_frame); + + if let Some(v) = self.theme.get("BFrame") { + frame.style(v); + } + frame.pack().fill(PackFill::X).layout(); + + let label = rstk::make_label(&frame); + label.text(&format!("{}. {text} ~{remaining_code}", i + 1,)); + if let Some(v) = self.theme.get("BLabel") { + label.style(v); + } + label.pack().side(PackSide::Left).layout(); + }); - self.prediction_frame = Some(prediction_frame); + prediction_frame.pack().fill(PackFill::X).layout(); } } diff --git a/src/rstk_ext.rs b/src/rstk_ext.rs index 3c53aba..541b9b4 100644 --- a/src/rstk_ext.rs +++ b/src/rstk_ext.rs @@ -5,7 +5,7 @@ pub fn init_rstk_ext() { rstk::tell_wish("chan configure stdin -encoding utf-8"); } -#[derive(Debug)] +#[derive(Debug, Default)] pub struct Style { pub name: &'static str, pub background: String, @@ -44,6 +44,7 @@ pub trait TkTopLevelExt { fn border(&self, _value: bool) {} fn topmost(&self, _value: bool) {} fn position(&self, _x: u64, _y: u64) {} + fn clear(&self) {} } impl TkTopLevelExt for TkTopLevel { @@ -58,4 +59,11 @@ impl TkTopLevelExt for TkTopLevel { fn position(&self, x: u64, y: u64) { rstk::tell_wish(&format!("wm geometry {} +{}+{}", &self.id, x, y)); } + + fn clear(&self) { + rstk::tell_wish(&format!( + "foreach e [winfo children {}] {{ destroy $e }}", + &self.id + )); + } }