diff --git a/Cargo.lock b/Cargo.lock index 68662de..8ab2cc3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2,6 +2,24 @@ # It is not intended for manual editing. version = 3 +[[package]] +name = "ahash" +version = "0.8.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77c3a9648d43b9cd48db467b3f87fdd6e146bcc88ab0180006cef2179fe11d01" +dependencies = [ + "cfg-if", + "once_cell", + "version_check", + "zerocopy", +] + +[[package]] +name = "allocator-api2" +version = "0.2.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0942ffc6dcaadf03badf6e6a2d0228460359d5e34b57ccdc720b7382dfbd5ec5" + [[package]] name = "ansi_term" version = "0.12.1" @@ -34,6 +52,12 @@ version = "1.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" +[[package]] +name = "bitflags" +version = "2.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed570934406eb16438a4e976b1b4500774099c13b8cb96eec99f620f05090ddf" + [[package]] name = "block-buffer" version = "0.10.4" @@ -63,7 +87,7 @@ checksum = "a0610544180c38b88101fecf2dd634b174a62eef6946f84dfc6a7127512b381c" dependencies = [ "ansi_term", "atty", - "bitflags", + "bitflags 1.3.2", "strsim", "textwrap", "unicode-width", @@ -72,20 +96,20 @@ dependencies = [ [[package]] name = "cpufeatures" -version = "0.2.9" +version = "0.2.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a17b76ff3a4162b0b27f354a0c87015ddad39d35f9c0c36607a3bdd175dde1f1" +checksum = "53fe5e26ff1b7aef8bca9c6080520cfb8d9333c7568e1829cef191a9723e5504" dependencies = [ "libc", ] [[package]] name = "crossterm" -version = "0.26.1" +version = "0.27.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a84cda67535339806297f1b331d6dd6320470d2a0fe65381e79ee9e156dd3d13" +checksum = "f476fe445d41c9e991fd07515a6f463074b782242ccf4a5b7b1d1012e70824df" dependencies = [ - "bitflags", + "bitflags 2.4.2", "crossterm_winapi", "libc", "mio", @@ -145,6 +169,12 @@ dependencies = [ "windows-sys", ] +[[package]] +name = "either" +version = "1.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a26ae43d7bcc3b814de94796a5e736d4029efb0ee900c12e2d54c993ad1a1e07" + [[package]] name = "equivalent" version = "1.0.1" @@ -163,9 +193,9 @@ dependencies = [ [[package]] name = "getrandom" -version = "0.2.10" +version = "0.2.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "be4136b2a15dd319360be1c07d9933517ccf0be8f16bf62a3bee4f0d618df427" +checksum = "190092ea657667030ac6a35e305e62fc4dd69fd98ac98631e5d3a2b1575a12b5" dependencies = [ "cfg-if", "libc", @@ -174,9 +204,13 @@ dependencies = [ [[package]] name = "hashbrown" -version = "0.14.1" +version = "0.14.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7dfda62a12f55daeae5015f81b0baea145391cb4520f86c248fc615d72640d12" +checksum = "290f1a1d9242c78d09ce40a5e87e7554ee637af1351968159f4952f028f75604" +dependencies = [ + "ahash", + "allocator-api2", +] [[package]] name = "heck" @@ -187,6 +221,12 @@ dependencies = [ "unicode-segmentation", ] +[[package]] +name = "heck" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8" + [[package]] name = "hermit-abi" version = "0.1.19" @@ -198,14 +238,29 @@ dependencies = [ [[package]] name = "indexmap" -version = "2.0.2" +version = "2.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8adf3ddd720272c6ea8bf59463c04e0f93d0bbf7c5439b691bca2987e0270897" +checksum = "824b2ae422412366ba479e8111fd301f7b5faece8149317bb81925979a53f520" dependencies = [ "equivalent", "hashbrown", ] +[[package]] +name = "indoc" +version = "2.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e186cfbae8084e513daff4240b4797e342f988cecda4fb6c939150f96315fd8" + +[[package]] +name = "itertools" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ba291022dbbd398a455acf126c1e341954079855bc60dfdda641363bd6922569" +dependencies = [ + "either", +] + [[package]] name = "lazy_static" version = "1.4.0" @@ -214,15 +269,26 @@ checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" [[package]] name = "libc" -version = "0.2.148" +version = "0.2.153" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c198f91728a82281a64e1f4f9eeb25d82cb32a5de251c6bd1b5154d63a8e7bd" + +[[package]] +name = "libredox" +version = "0.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9cdc71e17332e86d2e1d38c1f99edcb6288ee11b815fb1a4b049eaa2114d369b" +checksum = "85c833ca1e66078851dba29046874e38f08b2c883700aa29a03ddd3b23814ee8" +dependencies = [ + "bitflags 2.4.2", + "libc", + "redox_syscall", +] [[package]] name = "lock_api" -version = "0.4.10" +version = "0.4.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c1cc9717a20b1bb222f333e6a92fd32f7d8a18ddc5a3191a11af45dcbf4dcd16" +checksum = "3c168f8615b12bc01f9c17e2eb0cc07dcae1940121185446edc3744920e8ef45" dependencies = [ "autocfg", "scopeguard", @@ -234,17 +300,26 @@ version = "0.4.20" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b5e6163cb8c49088c2c36f57875e58ccd8c87c7427f7fbd50ea6710b2f3f2e8f" +[[package]] +name = "lru" +version = "0.12.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "db2c024b41519440580066ba82aab04092b333e09066a5eb86c7c4890df31f22" +dependencies = [ + "hashbrown", +] + [[package]] name = "memchr" -version = "2.6.4" +version = "2.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f665ee40bc4a3c5590afb1e9677db74a508659dfd71e126420da8274909a0167" +checksum = "523dc4f511e55ab87b694dc30d0f820d60906ef06413f93d4d7a1385599cc149" [[package]] name = "mio" -version = "0.8.8" +version = "0.8.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "927a765cd3fc26206e66b296465fa9d3e5ab003e651c1b3c060e7956d96b19d2" +checksum = "8f3d0b296e374a4e6f3c7b0a1f5a51d748a0d34c85e7dc48fc3fa9a87657fe09" dependencies = [ "libc", "log", @@ -252,6 +327,12 @@ dependencies = [ "windows-sys", ] +[[package]] +name = "once_cell" +version = "1.19.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" + [[package]] name = "option-ext" version = "0.2.0" @@ -270,17 +351,23 @@ dependencies = [ [[package]] name = "parking_lot_core" -version = "0.9.8" +version = "0.9.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "93f00c865fe7cabf650081affecd3871070f26767e7b2070a3ffae14c654b447" +checksum = "4c42a9226546d68acdd9c0a280d17ce19bfe27a46bf68784e4066115788d008e" dependencies = [ "cfg-if", "libc", - "redox_syscall 0.3.5", + "redox_syscall", "smallvec", "windows-targets", ] +[[package]] +name = "paste" +version = "1.0.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "de3145af08024dea9fa9914f381a17b8fc6034dfb00f3a84013f7ff43f29ed4c" + [[package]] name = "ppv-lite86" version = "0.2.17" @@ -313,18 +400,18 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.67" +version = "1.0.78" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3d433d9f1a3e8c1263d9456598b16fec66f4acc9a74dacffd35c7bb09b3a1328" +checksum = "e2422ad645d89c99f8f3e6b88a9fdeca7fabeac836b1002371c4367c8f984aae" dependencies = [ "unicode-ident", ] [[package]] name = "quote" -version = "1.0.33" +version = "1.0.35" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5267fca4496028628a95160fc423a33e8b2e6af8a5302579e322e4b520293cae" +checksum = "291ec9ab5efd934aaf503a6466c5d5251535d108ee747472c3977cc5acc868ef" dependencies = [ "proc-macro2", ] @@ -361,51 +448,48 @@ dependencies = [ [[package]] name = "ratatui" -version = "0.21.0" +version = "0.25.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ce841e0486e7c2412c3740168ede33adeba8e154a15107b879d8162d77c7174e" +checksum = "a5659e52e4ba6e07b2dad9f1158f578ef84a73762625ddb51536019f34d180eb" dependencies = [ - "bitflags", + "bitflags 2.4.2", "cassowary", "crossterm", + "indoc", + "itertools", + "lru", + "paste", + "stability", + "strum", "unicode-segmentation", "unicode-width", ] [[package]] name = "redox_syscall" -version = "0.2.16" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fb5a58c1855b4b6819d59012155603f0b22ad30cad752600aadfcb695265519a" -dependencies = [ - "bitflags", -] - -[[package]] -name = "redox_syscall" -version = "0.3.5" +version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "567664f262709473930a4bf9e51bf2ebf3348f2e748ccc50dea20646858f8f29" +checksum = "4722d768eff46b75989dd134e5c353f0d6296e5aaa3132e776cbdb56be7731aa" dependencies = [ - "bitflags", + "bitflags 1.3.2", ] [[package]] name = "redox_users" -version = "0.4.3" +version = "0.4.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b033d837a7cf162d7993aded9304e30a83213c648b6e389db233191f891e5c2b" +checksum = "a18479200779601e498ada4e8c1e1f50e3ee19deb0259c25825a98b5603b2cb4" dependencies = [ "getrandom", - "redox_syscall 0.2.16", + "libredox", "thiserror", ] [[package]] name = "rust-embed" -version = "6.8.1" +version = "8.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a36224c3276f8c4ebc8c20f158eca7ca4359c8db89991c4925132aaaf6702661" +checksum = "a82c0bbc10308ed323529fd3c1dce8badda635aa319a5ff0e6466f33b8101e3f" dependencies = [ "rust-embed-impl", "rust-embed-utils", @@ -414,27 +498,33 @@ dependencies = [ [[package]] name = "rust-embed-impl" -version = "6.8.1" +version = "8.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "49b94b81e5b2c284684141a2fb9e2a31be90638caf040bf9afbc5a0416afe1ac" +checksum = "6227c01b1783cdfee1bcf844eb44594cd16ec71c35305bf1c9fb5aade2735e16" dependencies = [ "proc-macro2", "quote", "rust-embed-utils", - "syn 2.0.37", + "syn 2.0.48", "walkdir", ] [[package]] name = "rust-embed-utils" -version = "7.8.1" +version = "8.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9d38ff6bf570dc3bb7100fce9f7b60c33fa71d80e88da3f2580df4ff2bdded74" +checksum = "8cb0a25bfbb2d4b4402179c2cf030387d9990857ce08a32592c6238db9fa8665" dependencies = [ "sha2", "walkdir", ] +[[package]] +name = "rustversion" +version = "1.0.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7ffc183a10b4478d04cbbbfc96d0873219d962dd5accaff2ffbd4ceb7df837f4" + [[package]] name = "same-file" version = "1.0.6" @@ -452,29 +542,29 @@ checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" [[package]] name = "serde" -version = "1.0.188" +version = "1.0.196" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cf9e0fcba69a370eed61bcf2b728575f726b50b55cba78064753d708ddc7549e" +checksum = "870026e60fa08c69f064aa766c10f10b1d62db9ccd4d0abb206472bee0ce3b32" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.188" +version = "1.0.196" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4eca7ac642d82aa35b60049a6eccb4be6be75e599bd2e9adb5f875a737654af2" +checksum = "33c85360c95e7d137454dc81d9a4ed2b8efd8fbe19cee57357b32b9771fccb67" dependencies = [ "proc-macro2", "quote", - "syn 2.0.37", + "syn 2.0.48", ] [[package]] name = "serde_spanned" -version = "0.6.3" +version = "0.6.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "96426c9936fd7a0124915f9185ea1d20aa9445cc9821142f0a73bc9207a2e186" +checksum = "eb3622f419d1296904700073ea6cc23ad690adbd66f13ea683df73298736f0c1" dependencies = [ "serde", ] @@ -522,9 +612,19 @@ dependencies = [ [[package]] name = "smallvec" -version = "1.11.1" +version = "1.13.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6ecd384b10a64542d77071bd64bd7b231f4ed5940fba55e98c3de13824cf3d7" + +[[package]] +name = "stability" +version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "942b4a808e05215192e39f4ab80813e599068285906cc91aa64f923db842bd5a" +checksum = "ebd1b177894da2a2d9120208c3386066af06a488255caabc5de8ddca22dbc3ce" +dependencies = [ + "quote", + "syn 1.0.109", +] [[package]] name = "strsim" @@ -549,13 +649,35 @@ version = "0.4.18" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dcb5ae327f9cc13b68763b5749770cb9e048a99bd9dfdfa58d0cf05d5f64afe0" dependencies = [ - "heck", + "heck 0.3.3", "proc-macro-error", "proc-macro2", "quote", "syn 1.0.109", ] +[[package]] +name = "strum" +version = "0.25.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "290d54ea6f91c969195bdbcd7442c8c2a2ba87da8bf60a7ee86a235d4bc1e125" +dependencies = [ + "strum_macros", +] + +[[package]] +name = "strum_macros" +version = "0.25.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "23dc1fa9ac9c169a78ba62f0b841814b7abae11bdd047b9c58f893439e309ea0" +dependencies = [ + "heck 0.4.1", + "proc-macro2", + "quote", + "rustversion", + "syn 2.0.48", +] + [[package]] name = "syn" version = "1.0.109" @@ -569,9 +691,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.37" +version = "2.0.48" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7303ef2c05cd654186cb250d29049a24840ca25d2747c25c0381c8d9e2f582e8" +checksum = "0f3531638e407dfc0814761abb7c00a5b54992b849452a0646b7f65c9f770f3f" dependencies = [ "proc-macro2", "quote", @@ -589,29 +711,29 @@ dependencies = [ [[package]] name = "thiserror" -version = "1.0.49" +version = "1.0.56" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1177e8c6d7ede7afde3585fd2513e611227efd6481bd78d2e82ba1ce16557ed4" +checksum = "d54378c645627613241d077a3a79db965db602882668f9136ac42af9ecb730ad" dependencies = [ "thiserror-impl", ] [[package]] name = "thiserror-impl" -version = "1.0.49" +version = "1.0.56" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "10712f02019e9288794769fba95cd6847df9874d49d871d062172f9dd41bc4cc" +checksum = "fa0faa943b50f3db30a20aa7e265dbc66076993efed8463e8de414e5d06d3471" dependencies = [ "proc-macro2", "quote", - "syn 2.0.37", + "syn 2.0.48", ] [[package]] name = "toml" -version = "0.7.8" +version = "0.8.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dd79e69d3b627db300ff956027cc6c3798cef26d22526befdfcd12feeb6d2257" +checksum = "c6a4b9e8023eb94392d3dca65d717c53abc5dad49c07cb65bb8fcd87115fa325" dependencies = [ "serde", "serde_spanned", @@ -621,18 +743,18 @@ dependencies = [ [[package]] name = "toml_datetime" -version = "0.6.3" +version = "0.6.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7cda73e2f1397b1262d6dfdcef8aafae14d1de7748d66822d3bfeeb6d03e5e4b" +checksum = "3550f4e9685620ac18a50ed434eb3aec30db8ba93b0287467bca5826ea25baf1" dependencies = [ "serde", ] [[package]] name = "toml_edit" -version = "0.19.15" +version = "0.21.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1b5bb770da30e5cbfde35a2d7b9b8a2c4b8ef89548a7a6aeab5c9a576e3e7421" +checksum = "6a8534fd7f78b5405e860340ad6575217ce99f38d4d5c8f2442cb5ecb50090e1" dependencies = [ "indexmap", "serde", @@ -643,7 +765,7 @@ dependencies = [ [[package]] name = "ttyper" -version = "1.4.0" +version = "1.4.1" dependencies = [ "crossterm", "dirs", @@ -806,9 +928,29 @@ checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" [[package]] name = "winnow" -version = "0.5.15" +version = "0.5.36" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7c2e3184b9c4e92ad5167ca73039d0c42476302ab603e2fec4487511f38ccefc" +checksum = "818ce546a11a9986bc24f93d0cdf38a8a1a400f1473ea8c82e59f6e0ffab9249" dependencies = [ "memchr", ] + +[[package]] +name = "zerocopy" +version = "0.7.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "74d4d3961e53fa4c9a25a8637fc2bfaf2595b3d3ae34875568a5cf64787716be" +dependencies = [ + "zerocopy-derive", +] + +[[package]] +name = "zerocopy-derive" +version = "0.7.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9ce1b18ccd8e73a9321186f97e46f9f04b778851177567b1975109d26a08d2a6" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.48", +] diff --git a/Cargo.toml b/Cargo.toml index dd1596e..b0dabaa 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "ttyper" description = "Terminal-based typing test." -version = "1.4.0" +version = "1.4.1" readme = "README.md" repository = "https://github.com/max-niederman/ttyper.git" homepage = "https://github.com/max-niederman/ttyper" @@ -12,12 +12,12 @@ edition = "2021" [dependencies] structopt = "^0.3" dirs = "^5.0" -crossterm = "^0.26" -rust-embed = "^6.4" -toml = "^0.7" +crossterm = "^0.27" +rust-embed = "^8.2" +toml = "^0.8" [dependencies.ratatui] -version = "^0.21" +version = "^0.25" [dependencies.rand] version = "^0.8" diff --git a/resources/runtime/language/cpp b/resources/runtime/language/cpp new file mode 100644 index 0000000..4e2b26f --- /dev/null +++ b/resources/runtime/language/cpp @@ -0,0 +1,139 @@ +--i +-= +!= +*= +/= +&& +&= +#define +#include +#pragma +%= +^= +++i ++= +<< +<<= +<= + + + + +== +>= +>> +>>= +|= +|| +alignas +alignof +and +and_eq +asm +atomic_cancel +atomic_commit +atomic_noexcept +auto +bitand +bitor +bool +break +case +catch +char +char16_t +char32_t +char8_t +class +co_await +co_return +co_yield +compl +concept +const +const_cast +consteval +constexpr +constinit +continue +decltype +default +delete +do +double +dynamic_cast +else +enum +explicit +export +extern +false +final +float +for +friend +goto +i-- +i++ +if +import +inline +int +long +module +mutable +namespace +new +noexcept +not +not_eq +nullptr +operator +or +or_eq +override +private +protected +public +reflexpr +register +reinterpret_cast +requires +return +short +signed +sizeof +sizeof(long long) +static +static_assert +static_cast +std::cout +std::endl +std::map +std::move +std::string +std::vector +struct +switch +synchronized +template +template +template +this +thread_local +throw +true +try +typedef +typeid +typename +union +unsigned +using +virtual +void +volatile +wchar_t +while +xor +xor_eq \ No newline at end of file diff --git a/resources/runtime/language/english-ngrams b/resources/runtime/language/english-ngrams new file mode 100644 index 0000000..8192556 --- /dev/null +++ b/resources/runtime/language/english-ngrams @@ -0,0 +1,300 @@ +ou +te +me +ve +li +ed +ng +ne +at +ll +of +ha +he +in +st +ce +le +as +ti +or +se +om +is +al +nt +co +ro +io +re +it +on +to +es +th +ar +en +hi +er +ea +si +nd +ri +ma +be +ic +de +ra +ch +ur +an +con +lit +pre +din +tha +art +ore +lan +tri +der +ren +orm +tho +ion +eri +ran +ove +ast +mor +wit +can +anc +rie +ies +res +rou +ard +nes +ime +ght +age +hat +one +sio +hin +spe +cou +ure +ntr +pla +hei +omp +ers +ass +ont +rec +nde +ant +she +ith +iti +ese +out +ver +tte +oth +sin +and +nal +men +whe +rit +but +ear +int +nte +are +cha +wor +tic +ave +ter +nat +sta +rat +nts +cti +sen +ame +ces +lar +oun +rin +whi +ide +ven +end +ted +rea +you +ive +pos +oug +par +uld +ati +ble +les +ica +era +tur +ind +ons +ric +ned +ate +ing +ste +ust +ort +ssi +all +fro +the +tes +ess +tiv +han +hou +ent +ial +ell +ome +ere +ona +eat +dis +tra +ugh +ich +eas +str +ist +ins +tio +den +igh +und +wer +rom +use +ice +thi +abl +ern +man +ten +ple +hav +lat +red +lly +enc +ite +lin +our +was +sti +nti +tin +tor +tat +hic +tan +hen +not +eme +had +inc +oul +eve +per +sed +ene +app +cal +pro +any +for +ect +een +ine +ill +por +ral +com +hey +nce +ity +ord +ose +her +ndi +ain +ous +tim +act +min +est +his +form +ctio +ally +hich +ring +whic +that +ting +nter +ions +othe +thei +ould +were +thin +tive +ence +over +sion +ever +heir +ture +inte +ight +some +cont +this +ents +ment +part +ough +rati +ding +ther +cons +here +ning +ance +ecti +comp +from +tion +ated +they +ical +atio +with +able +have +pres diff --git a/src/main.rs b/src/main.rs index bc5a3e5..999493b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -59,6 +59,10 @@ struct Opt { /// Disable backtracking to completed words #[structopt(long)] no_backtrack: bool, + + /// Enable sudden death mode to restart on first error + #[structopt(long)] + sudden_death: bool, } impl Opt { @@ -175,7 +179,7 @@ impl State { &self, terminal: &mut Terminal, config: &Config, - ) -> crossterm::Result<()> { + ) -> io::Result<()> { match self { State::Test(test) => { terminal.draw(|f| { @@ -192,7 +196,7 @@ impl State { } } -fn main() -> crossterm::Result<()> { +fn main() -> io::Result<()> { let opt = Opt::from_args(); if opt.debug { dbg!(&opt); @@ -228,6 +232,7 @@ fn main() -> crossterm::Result<()> { "Couldn't get test contents. Make sure the specified language actually exists.", ), !opt.no_backtrack, + opt.sudden_death, )); state.render_into(&mut terminal, &config)?; @@ -276,7 +281,8 @@ fn main() -> crossterm::Result<()> { opt.gen_contents().expect( "Couldn't get test contents. Make sure the specified language actually exists.", ), - !opt.no_backtrack + !opt.no_backtrack, + opt.sudden_death )); } Event::Key(KeyEvent { @@ -294,7 +300,11 @@ fn main() -> crossterm::Result<()> { .flat_map(|w| vec![w.clone(); 5]) .collect(); practice_words.shuffle(&mut thread_rng()); - state = State::Test(Test::new(practice_words, !opt.no_backtrack)); + state = State::Test(Test::new( + practice_words, + !opt.no_backtrack, + opt.sudden_death, + )); } Event::Key(KeyEvent { code: KeyCode::Char('q'), diff --git a/src/test/mod.rs b/src/test/mod.rs index 01295d9..0780bb8 100644 --- a/src/test/mod.rs +++ b/src/test/mod.rs @@ -10,6 +10,10 @@ pub struct TestEvent { pub correct: Option, } +pub fn is_missed_word_event(event: &TestEvent) -> bool { + event.correct != Some(true) +} + impl fmt::Debug for TestEvent { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.debug_struct("TestEvent") @@ -48,15 +52,17 @@ pub struct Test { pub current_word: usize, pub complete: bool, pub backtracking_enabled: bool, + pub sudden_death_enabled: bool, } impl Test { - pub fn new(words: Vec, backtracking_enabled: bool) -> Self { + pub fn new(words: Vec, backtracking_enabled: bool, sudden_death_enabled: bool) -> Self { Self { words: words.into_iter().map(TestWord::from).collect(), current_word: 0, complete: false, backtracking_enabled, + sudden_death_enabled, } } @@ -76,12 +82,17 @@ impl Test { key, }) } else if !word.progress.is_empty() || word.text.is_empty() { - word.events.push(TestEvent { - time: Instant::now(), - correct: Some(word.text == word.progress), - key, - }); - self.next_word(); + let correct = word.text == word.progress; + if self.sudden_death_enabled && !correct { + self.reset(); + } else { + word.events.push(TestEvent { + time: Instant::now(), + correct: Some(correct), + key, + }); + self.next_word(); + } } } KeyCode::Backspace => { @@ -96,8 +107,10 @@ impl Test { word.progress.pop(); } } - // CTRL-BackSpace - KeyCode::Char('h') if key.modifiers.contains(KeyModifiers::CONTROL) => { + // CTRL-BackSpace and CTRL-W + KeyCode::Char('h') | KeyCode::Char('w') + if key.modifiers.contains(KeyModifiers::CONTROL) => + { if self.words[self.current_word].progress.is_empty() { self.last_word(); } @@ -113,14 +126,19 @@ impl Test { } KeyCode::Char(c) => { word.progress.push(c); - word.events.push(TestEvent { - time: Instant::now(), - correct: Some(word.text.starts_with(&word.progress[..])), - key, - }); - if word.progress == word.text && self.current_word == self.words.len() - 1 { - self.complete = true; - self.current_word = 0; + let correct = word.text.starts_with(&word.progress[..]); + if self.sudden_death_enabled && !correct { + self.reset(); + } else { + word.events.push(TestEvent { + time: Instant::now(), + correct: Some(correct), + key, + }); + if word.progress == word.text && self.current_word == self.words.len() - 1 { + self.complete = true; + self.current_word = 0; + } } } _ => {} @@ -141,4 +159,13 @@ impl Test { self.current_word += 1; } } + + fn reset(&mut self) { + self.words.iter_mut().for_each(|word: &mut TestWord| { + word.progress.clear(); + word.events.clear(); + }); + self.current_word = 0; + self.complete = false; + } } diff --git a/src/test/results.rs b/src/test/results.rs index bda35b3..6ac73d5 100644 --- a/src/test/results.rs +++ b/src/test/results.rs @@ -1,4 +1,4 @@ -use super::Test; +use super::{is_missed_word_event, Test}; use crossterm::event::KeyEvent; use std::collections::HashMap; @@ -150,10 +150,6 @@ fn calc_accuracy(events: &[&super::TestEvent]) -> AccuracyData { } fn calc_missed_words(test: &Test) -> Vec { - let is_missed_word_event = |event: &super::TestEvent| -> bool { - event.correct == Some(false) || event.correct.is_none() - }; - test.words .iter() .filter(|word| word.events.iter().any(is_missed_word_event))