type chars rather than bytes

This commit is contained in:
Patryk Laurent 2023-01-15 08:10:55 -08:00
parent e36a9287ce
commit 6045f8a05b
2 changed files with 7 additions and 8 deletions

View file

@ -278,20 +278,19 @@ impl Gam {
} }
} }
pub fn type_keys(&self, s: &str) -> Result<bool, xous::Error> { pub fn type_chars(&self, s: &str) -> Result<bool, xous::Error> {
let mut view = s.chars().peekable(); let mut view = s.chars().peekable();
while view.peek().is_some() { while view.peek().is_some() {
let chunk: std::string::String = view.by_ref().take(4).collect(); let chunk: std::string::String = view.by_ref().take(4).collect();
let bytes = chunk.as_bytes();
send_message(self.conn, send_message(self.conn,
Message::new_scalar(Opcode::KeyboardEvent.to_usize().unwrap(), Message::new_scalar(Opcode::KeyboardEvent.to_usize().unwrap(),
bytes[0] as usize, chunk.chars().nth(0).unwrap() as usize,
if bytes.len() > 1 {bytes[1]} else {0} as usize, if chunk.len() > 1 {chunk.chars().nth(1).unwrap()} else {'\u{0000}'} as usize,
if bytes.len() > 2 {bytes[2]} else {0} as usize, if chunk.len() > 2 {chunk.chars().nth(2).unwrap()} else {'\u{0000}'} as usize,
if bytes.len() > 3 {bytes[3]} else {0} as usize if chunk.len() > 3 {chunk.chars().nth(3).unwrap()} else {'\u{0000}'} as usize
) )
).expect("Couldn't type keys"); ).expect("Couldn't type chars");
} }
Ok(true) Ok(true)

View file

@ -180,7 +180,7 @@ impl<'a> ShellCmdApi<'a> for PddbCmd {
editcmd.push_str(" "); editcmd.push_str(" ");
editcmd.push_str(&s); editcmd.push_str(&s);
match _env.gam.type_keys(&editcmd) { match _env.gam.type_chars(&editcmd) {
Ok(_) => { Ok(_) => {
write!(ret, "Edit the value and press enter:").unwrap() write!(ret, "Edit the value and press enter:").unwrap()
} }