Expand description
Preprocess keyboard events for an input method.
Enables the generation of keyboard event responses from a keyboard input event in an input method
engine.
The afrim-preprocessor crate is built on the top of the afrim-memory crate.
§Example
use afrim_preprocessor::{utils::{self, webdriver}, Command, Preprocessor, Node};
use std::{collections::VecDeque, rc::Rc};
// Prepares the memory.
let data = utils::load_data("cc ç");
let text_buffer: Node = utils::build_map(data);
let memory = Rc::new(text_buffer);
// Builds the preprocessor.
let mut preprocessor = Preprocessor::new(memory, 8);
// Process an input.
let input = "cc";
webdriver::send_keys(input)
.into_iter()
.for_each(|event| {
match event {
// Triggers the generated keyboard input event.
webdriver::Event::Keyboard(event) => preprocessor.process(event),
_ => unimplemented!(),
};
});
// Now let's look at the generated commands.
let mut expecteds = VecDeque::from(vec![
Command::Pause,
Command::Delete("c".to_string()),
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);Modules§
- utils
- Utilities.
Structs§
- Keyboard
Event - Keyboard events are issued for all pressed and released keys.
- Node
- A node in the text buffer.
- Preprocessor
- The main structure of the preprocessor.