Skip to main content

Crate afrim_preprocessor

Crate afrim_preprocessor 

Source
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§

KeyboardEvent
Keyboard events are issued for all pressed and released keys.
Node
A node in the text buffer.
Preprocessor
The main structure of the preprocessor.

Enums§

Command
Possible commands that can be generated by the afrim-preprocessor.
Key
The value received from the keypress.
KeyState
Describes the state a key is in.
NamedKey
Key represents the meaning of a keypress.