submission: Handle submitting strings

This commit is contained in:
Dorota Czaplejewicz
2020-01-14 13:13:42 +00:00
parent d1bc23e9d8
commit 42cb73cd8c
6 changed files with 126 additions and 23 deletions

View File

@ -1,13 +1,16 @@
/*! State of the emulated keyboard and keys.
* Regards the keyboard as if it was composed of switches. */
use std::cell::RefCell;
use std::collections::HashMap;
use std::fmt;
use std::io;
use std::rc::Rc;
use std::string::FromUtf8Error;
use ::action::Action;
// Traits
use std::io::Write;
use std::iter::{ FromIterator, IntoIterator };
@ -19,6 +22,11 @@ pub enum PressType {
pub type KeyCode = u32;
/// When the submitted actions of keys need to be tracked,
/// they need a stable, comparable ID
#[derive(PartialEq)]
pub struct KeyStateId(*const KeyState);
#[derive(Debug, Clone)]
pub struct KeyState {
pub pressed: PressType,
@ -48,6 +56,12 @@ impl KeyState {
..self
}
}
/// KeyStates instances are the unique identifiers of pressed keys,
/// and the actions submitted with them.
pub fn get_id(keystate: &Rc<RefCell<KeyState>>) -> KeyStateId {
KeyStateId(keystate.as_ptr() as *const KeyState)
}
}
/// Sorts an iterator by converting it to a Vector and back