diff --git a/README.md b/README.md index b357f98..7e68183 100644 --- a/README.md +++ b/README.md @@ -43,7 +43,6 @@ Features - [ ] 💻 Support for both desktop and web platform. - [ ] 🤖 Support for the Rhai scripting language. - [ ] 📝 Auto-suggestion / Auto-correction / Auto-completion. - - [ ] ☁️ Full immersion mode for non-latin languages. (🚧 Experimental 🚧) Installation === diff --git a/engine/preprocessor/Cargo.toml b/engine/preprocessor/Cargo.toml index 869fa61..e3ef5b0 100644 --- a/engine/preprocessor/Cargo.toml +++ b/engine/preprocessor/Cargo.toml @@ -13,13 +13,9 @@ authors.workspace = true # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [features] default = [] -inhibit = [] serde = ["dep:serde", "keyboard-types/serde"] [dependencies] keyboard-types = { version = "0.8.3", features = ["webdriver"] } afrim-memory = { version = "0.4.2", path = "../../memory" } serde = { version = "1.0.228", features = ["derive"], optional = true } - -[dev-dependencies] -keyboard-types = { version = "0.8.3", features = ["webdriver"] } diff --git a/engine/preprocessor/README.md b/engine/preprocessor/README.md index 59c4668..7ad73cf 100644 --- a/engine/preprocessor/README.md +++ b/engine/preprocessor/README.md @@ -4,5 +4,4 @@ It generate a sequence of command to be perform to execute a particular task. ### Features -- inhibit: Enable the inhibit mode. - serde: Enable serialization/deserialization. diff --git a/engine/preprocessor/src/lib.rs b/engine/preprocessor/src/lib.rs index 5ff4bc4..a5d5332 100644 --- a/engine/preprocessor/src/lib.rs +++ b/engine/preprocessor/src/lib.rs @@ -32,8 +32,6 @@ //! }); //! //! // Now let's look at the generated commands. -//! // The expected results without `inhibit` feature. -//! #[cfg(not(feature = "inhibit"))] //! let mut expecteds = VecDeque::from(vec![ //! Command::Pause, //! Command::Delete("c".to_string()), @@ -42,26 +40,12 @@ //! Command::Resume, //! ]); //! -//! // The expected results with `inhibit` feature. -//! #[cfg(feature = "inhibit")] -//! let mut expecteds = VecDeque::from(vec![ -//! Command::Pause, -//! Command::Delete("c".to_string()), -//! Command::Resume, -//! Command::Pause, -//! Command::Delete("c".to_string()), -//! Command::CommitText("ç".to_owned()), -//! Command::Resume, -//! ]); -//! //! // Verification. //! while let Some(command) = preprocessor.pop_queue() { //! assert_eq!(command, expecteds.pop_front().unwrap()); //! } //! assert_eq!(expecteds.is_empty(), true); //! ``` -//! **Note**: When dealing with non latin languages. The `inhibit` feature allows for the removal of -//! unwanted characters typically latin characters, as much as posssible. mod message; @@ -136,7 +120,6 @@ impl Preprocessor { true } else { - #[cfg(not(feature = "inhibit"))] self.queue .push_back(Command::Delete(_curr_char.to_string())); self.cursor.resume(); @@ -190,8 +173,6 @@ impl Preprocessor { /// assert_eq!(preprocessor.get_input(), "si3".to_owned()); /// /// // The generated commands. - /// // The expected results without inhibit feature. - /// #[cfg(not(feature = "inhibit"))] /// let mut expecteds = VecDeque::from(vec![ /// Command::Pause, /// Command::Delete("3".to_string()), @@ -200,21 +181,6 @@ impl Preprocessor { /// Command::Resume, /// ]); /// - /// // The expected results with inhibit feature. - /// #[cfg(feature = "inhibit")] - /// let mut expecteds = VecDeque::from(vec![ - /// Command::Pause, - /// Command::Delete("s".to_string()), - /// Command::Resume, - /// Command::Pause, - /// Command::Delete("i".to_string()), - /// Command::Resume, - /// Command::Pause, - /// Command::Delete("3".to_string()), - /// Command::CommitText("ī".to_owned()), - /// Command::Resume, - /// ]); - /// /// // Verification. /// while let Some(command) = preprocessor.pop_queue() { /// assert_eq!(command, expecteds.pop_front().unwrap()); @@ -226,14 +192,11 @@ impl Preprocessor { match (event.state, event.key) { (KeyState::Down, Key::Named(NamedKey::Backspace)) => { - #[cfg(not(feature = "inhibit"))] { self.pause(); committed = self.rollback(); self.resume(); } - #[cfg(feature = "inhibit")] - self.cursor.clear(); changed = true; } (KeyState::Down, Key::Character(character)) @@ -243,25 +206,17 @@ impl Preprocessor { .map(|e| e.is_alphanumeric() || e.is_ascii_punctuation()) .unwrap_or(false) => { - #[cfg(feature = "inhibit")] - self.pause(); - #[cfg(feature = "inhibit")] - self.queue.push_back(Command::Delete(character.clone())); - let character = character.chars().next().unwrap(); if let Some(_in) = self.cursor.hit(character) { - #[cfg(not(feature = "inhibit"))] self.pause(); let mut prev_cursor = self.cursor.clone(); prev_cursor.undo(); - #[cfg(not(feature = "inhibit"))] self.queue.push_back(Command::Delete(character.to_string())); // Remove the remaining code while let (None, 1.., _c) = prev_cursor.state() { prev_cursor.undo(); - #[cfg(not(feature = "inhibit"))] self.queue.push_back(Command::Delete(_c.to_string())); } @@ -270,13 +225,10 @@ impl Preprocessor { } self.queue.push_back(Command::CommitText(_in)); - #[cfg(not(feature = "inhibit"))] self.resume(); committed = true; }; - #[cfg(feature = "inhibit")] - self.resume(); changed = true; } (KeyState::Down, Key::Named(NamedKey::Shift) | Key::Named(NamedKey::CapsLock)) => (), @@ -320,8 +272,6 @@ impl Preprocessor { /// preprocessor.commit("sī".to_owned()); /// /// // The generated commands. - /// // The expected results without inhibit feature. - /// #[cfg(not(feature = "inhibit"))] /// let mut expecteds = VecDeque::from(vec![ /// Command::Pause, /// Command::Delete("s".to_string()), @@ -329,17 +279,6 @@ impl Preprocessor { /// Command::Resume, /// ]); /// - /// // The expected results with inhibit feature. - /// #[cfg(feature = "inhibit")] - /// let mut expecteds = VecDeque::from(vec![ - /// Command::Pause, - /// Command::Delete("s".to_string()), - /// Command::Resume, - /// Command::Pause, - /// Command::CommitText("sī".to_owned()), - /// Command::Resume, - /// ]); - /// /// // Verification. /// while let Some(command) = preprocessor.pop_queue() { /// assert_eq!(command, expecteds.pop_front().unwrap()); @@ -352,8 +291,6 @@ impl Preprocessor { while !self.cursor.is_empty() { self.rollback(); } - #[cfg(feature = "inhibit")] - self.cursor.clear(); self.queue.push_back(Command::CommitText(text)); self.resume(); // We clear the buffer @@ -492,7 +429,6 @@ mod tests { _ => unimplemented!(), }; }); - #[cfg(not(feature = "inhibit"))] let mut expecteds = VecDeque::from(vec![ // c c Command::Pause, @@ -509,29 +445,6 @@ mod tests { Command::CommitText("ç".to_owned()), Command::Resume, ]); - #[cfg(feature = "inhibit")] - let mut expecteds = VecDeque::from(vec![ - // c c - Command::Pause, - Command::Delete("c".to_string()), - Command::Resume, - Command::Pause, - Command::Delete("c".to_string()), - Command::CommitText("ç".to_owned()), - Command::Resume, - // c e d - Command::Pause, - Command::Delete("c".to_string()), - Command::Resume, - Command::Pause, - Command::Delete("e".to_string()), - Command::Resume, - Command::Pause, - Command::Delete("d".to_string()), - Command::Delete("ç".to_string()), - Command::CommitText("ç".to_owned()), - Command::Resume, - ]); while let Some(command) = preprocessor.pop_queue() { assert_eq!(command, expecteds.pop_front().unwrap()); @@ -551,10 +464,6 @@ mod tests { let mut expecteds = VecDeque::from(vec![ Command::Pause, Command::Delete("a".to_string()), - #[cfg(feature = "inhibit")] - Command::Resume, - #[cfg(feature = "inhibit")] - Command::Pause, Command::CommitText("word".to_owned()), Command::Resume, ]); @@ -587,13 +496,10 @@ mod tests { preprocessor.clear_queue(); assert_eq!(preprocessor.get_input(), "ccced".to_owned()); preprocessor.process(backspace_event.clone()); - #[cfg(not(feature = "inhibit"))] assert_eq!(preprocessor.get_input(), "cc".to_owned()); - #[cfg(not(feature = "inhibit"))] preprocessor.process(backspace_event); assert_eq!(preprocessor.get_input(), "".to_owned()); - #[cfg(not(feature = "inhibit"))] let mut expecteds = VecDeque::from(vec![ Command::Pause, Command::Delete("ç".to_string()), @@ -604,10 +510,6 @@ mod tests { Command::Resume, ]); - // NOTE: The inhibit feature don't support rollback - #[cfg(feature = "inhibit")] - let mut expecteds = VecDeque::from(vec![]); - while let Some(command) = preprocessor.pop_queue() { assert_eq!(command, expecteds.pop_front().unwrap()); } @@ -633,7 +535,6 @@ mod tests { }; }); - #[cfg(not(feature = "inhibit"))] let mut expecteds = VecDeque::from(vec![ // Process // u backspace @@ -765,118 +666,6 @@ mod tests { Command::Delete("\0".to_string()), Command::Resume, ]); - #[cfg(feature = "inhibit")] - let mut expecteds = VecDeque::from(vec![ - // Process - // u backspace - Command::Pause, - Command::Delete("u".to_string()), - Command::Resume, - // u u backspace - Command::Pause, - Command::Delete("u".to_string()), - Command::Resume, - Command::Pause, - Command::Delete("u".to_string()), - Command::CommitText("ʉ".to_owned()), - Command::Resume, - // u - Command::Pause, - Command::Delete("u".to_string()), - Command::Resume, - // c _ - Command::Pause, - Command::Delete("c".to_string()), - Command::Resume, - Command::Pause, - Command::Delete("_".to_string()), - Command::CommitText("ç".to_owned()), - Command::Resume, - // c e d - Command::Pause, - Command::Delete("c".to_string()), - Command::Resume, - Command::Pause, - Command::Delete("e".to_string()), - Command::Resume, - Command::Pause, - Command::Delete("d".to_string()), - Command::Delete("ç".to_string()), - Command::CommitText("ç".to_owned()), - Command::Resume, - // u u - Command::Pause, - Command::Delete("u".to_string()), - Command::Resume, - Command::Pause, - Command::Delete("u".to_string()), - Command::CommitText("ʉ".to_owned()), - Command::Resume, - // a f 3 - Command::Pause, - Command::Delete("a".to_string()), - Command::Resume, - Command::Pause, - Command::Delete("f".to_string()), - Command::Resume, - Command::Pause, - Command::Delete("3".to_string()), - Command::Delete("ʉ".to_string()), - Command::CommitText("ʉ\u{304}ɑ\u{304}".to_owned()), - Command::Resume, - // a f - Command::Pause, - Command::Delete("a".to_string()), - Command::Resume, - Command::Pause, - Command::Delete("f".to_string()), - Command::CommitText("ɑ".to_owned()), - Command::Resume, - // a f - Command::Pause, - Command::Delete("a".to_string()), - Command::Resume, - Command::Pause, - Command::Delete("f".to_string()), - Command::CommitText("ɑ".to_owned()), - Command::Resume, - // a f - Command::Pause, - Command::Delete("a".to_string()), - Command::Resume, - Command::Pause, - Command::Delete("f".to_string()), - Command::CommitText("ɑ".to_owned()), - Command::Resume, - // f - Command::Pause, - Command::Delete("f".to_string()), - Command::Delete("ɑ".to_string()), - Command::CommitText("ɑɑ".to_owned()), - Command::Resume, - // 3 - Command::Pause, - Command::Delete("3".to_string()), - Command::Delete("ɑɑ".to_string()), - Command::CommitText("ɑ\u{304}ɑ\u{304}".to_owned()), - Command::Resume, - // uu - Command::Pause, - Command::Delete("u".to_string()), - Command::Resume, - Command::Pause, - Command::Delete("u".to_string()), - Command::CommitText("ʉ".to_owned()), - Command::Resume, - // 3 - Command::Pause, - Command::Delete("3".to_string()), - Command::Delete("ʉ".to_owned()), - Command::CommitText("ʉ\u{304}".to_owned()), - Command::Resume, - // Rollback - // NOTE: The inhibit feature don't support rollback - ]); while let Some(command) = preprocessor.pop_queue() { let c = expecteds.pop_front().unwrap(); diff --git a/service/Cargo.toml b/service/Cargo.toml index bf0646e..f95fdb7 100644 --- a/service/Cargo.toml +++ b/service/Cargo.toml @@ -21,7 +21,6 @@ path = "./src/main.rs" default = ["rhai", "strsim"] rhai = ["afrim-config/rhai", "afrim-translator/rhai"] strsim = ["afrim-translator/strsim"] -inhibit = ["afrim-preprocessor/inhibit"] serde = ["dep:serde", "afrim-translator/serde"] [dependencies] diff --git a/service/src/lib.rs b/service/src/lib.rs index 403b4bb..d7caa34 100644 --- a/service/src/lib.rs +++ b/service/src/lib.rs @@ -292,7 +292,6 @@ mod tests { thread::sleep(typing_speed_ms); input!(KeyU, typing_speed_ms); - #[cfg(not(feature = "inhibit"))] input!(Backspace, typing_speed_ms); input!(KeyU KeyU Backspace KeyU, typing_speed_ms); input!( @@ -303,20 +302,12 @@ mod tests { KeyA KeyF KeyA KeyF KeyA KeyF KeyF Num3, typing_speed_ms); input!(KeyU KeyU Num3, typing_speed_ms); - #[cfg(feature = "inhibit")] - output!(textfield, format!("{LIMIT}çʉ̄ɑ̄ɑɑɑ̄ɑ̄ʉ̄")); - #[cfg(not(feature = "inhibit"))] output!(textfield, format!("{LIMIT}uçʉ̄ɑ̄ɑɑɑ̄ɑ̄ʉ̄")); // We verify that the undo (backspace) works as expected - #[cfg(not(feature = "inhibit"))] (0..12).for_each(|_| { input!(Backspace, typing_speed_ms); }); - #[cfg(feature = "inhibit")] - (0..13).for_each(|_| { - input!(Backspace, typing_speed_ms); - }); output!(textfield, LIMIT); // We verify that the pause/resume works as expected