From 553f98f7f259751604fe9282be7ae4a062429396 Mon Sep 17 00:00:00 2001 From: bunnie Date: Mon, 23 Sep 2024 14:30:46 +0800 Subject: [PATCH] port apps/mtxcli to xous-ipc 0.10 --- apps/mtxcli/src/cmds.rs | 18 +++++++++--------- apps/mtxcli/src/cmds/get.rs | 2 +- apps/mtxcli/src/cmds/help.rs | 2 +- apps/mtxcli/src/cmds/set.rs | 2 +- apps/mtxcli/src/cmds/unset.rs | 2 +- apps/mtxcli/src/mtxcli.rs | 22 +++++++++------------- 6 files changed, 22 insertions(+), 26 deletions(-) diff --git a/apps/mtxcli/src/cmds.rs b/apps/mtxcli/src/cmds.rs index ae38df0c6..dfd42a4e6 100644 --- a/apps/mtxcli/src/cmds.rs +++ b/apps/mtxcli/src/cmds.rs @@ -714,7 +714,7 @@ impl CmdEnv { let mut cmd_ret: Result, xous::Error> = Ok(None); if let Some(verb_string) = maybe_verb { - let verb = verb_string.to_str(); + let verb = &verb_string; // if verb starts with a slash then it's a command (else chat) if verb.starts_with("/") { @@ -725,7 +725,7 @@ impl CmdEnv { for cmd in commands.iter_mut() { if cmd.matches(command) { match_found = true; - cmd_ret = cmd.process(*cmdline, &mut self.common_env); + cmd_ret = cmd.process(cmdline.to_string(), &mut self.common_env); self.lastverb.clear(); write!(self.lastverb, "{}", verb).expect("couldn't record last verb"); }; @@ -740,7 +740,7 @@ impl CmdEnv { ret.push_str(", "); } ret.push_str("/"); - ret.append(cmd.verb())?; + ret.push_str(cmd.verb()); first = false; } Ok(Some(ret)) @@ -751,7 +751,7 @@ impl CmdEnv { // chat let mut text = String::from(verb); text.push_str(" "); - text.push_str(cmdline.to_str()); + text.push_str(cmdline); self.common_env.user_says(&text); // only for sync case Ok(Some(ret)) Ok(None) @@ -764,8 +764,8 @@ impl CmdEnv { let mut cmd_ret: Result, xous::Error> = Ok(None); // first check and see if we have a callback registration; if not, just map to the last verb let verb = match self.common_env.cb_registrations.get(&(callback.body.id() as u32)) { - Some(verb) => verb.to_str(), - None => self.lastverb.to_str(), + Some(verb) => &verb, + None => &self.lastverb, }; // now dispatch let mut verbfound = false; @@ -795,13 +795,13 @@ pub fn tokenize(line: &mut String) -> Option { let mut foundrest = false; for ch in lineiter { if ch != ' ' && !foundspace { - token.push(ch).unwrap(); + token.push(ch); } else if foundspace && foundrest { - retline.push(ch).unwrap(); + retline.push(ch); } else if foundspace && ch != ' ' { // handle case of multiple spaces in a row foundrest = true; - retline.push(ch).unwrap(); + retline.push(ch); } else { foundspace = true; // consume the space diff --git a/apps/mtxcli/src/cmds/get.rs b/apps/mtxcli/src/cmds/get.rs index edf802df7..b165490bd 100644 --- a/apps/mtxcli/src/cmds/get.rs +++ b/apps/mtxcli/src/cmds/get.rs @@ -15,7 +15,7 @@ impl<'a> ShellCmdApi<'a> for Get { fn process(&mut self, args: String, env: &mut CommonEnv) -> Result, xous::Error> { let mut ret = String::new(); - let mut tokens = &args.split(' '); + let mut tokens = args.split(' '); if let Some(key) = tokens.next() { match key { diff --git a/apps/mtxcli/src/cmds/help.rs b/apps/mtxcli/src/cmds/help.rs index 8a08c660c..cb727088f 100644 --- a/apps/mtxcli/src/cmds/help.rs +++ b/apps/mtxcli/src/cmds/help.rs @@ -17,7 +17,7 @@ impl<'a> ShellCmdApi<'a> for Help { fn process(&mut self, args: String, _env: &mut CommonEnv) -> Result, xous::Error> { let mut ret = String::new(); - let mut tokens = &args.split(' '); + let mut tokens = args.split(' '); if let Some(slashcmd) = tokens.next() { let cmd = if slashcmd.starts_with("/") { &slashcmd[1..] } else { slashcmd }; diff --git a/apps/mtxcli/src/cmds/set.rs b/apps/mtxcli/src/cmds/set.rs index e3b7b4c59..5ba47d974 100644 --- a/apps/mtxcli/src/cmds/set.rs +++ b/apps/mtxcli/src/cmds/set.rs @@ -15,7 +15,7 @@ impl<'a> ShellCmdApi<'a> for Set { fn process(&mut self, args: String, env: &mut CommonEnv) -> Result, xous::Error> { let mut ret = String::new(); - let mut tokens = &args.split(' '); + let mut tokens = args.split(' '); if let Some(key) = tokens.next() { match key { diff --git a/apps/mtxcli/src/cmds/unset.rs b/apps/mtxcli/src/cmds/unset.rs index 920bcae2f..cde00253d 100644 --- a/apps/mtxcli/src/cmds/unset.rs +++ b/apps/mtxcli/src/cmds/unset.rs @@ -15,7 +15,7 @@ impl<'a> ShellCmdApi<'a> for Unset { fn process(&mut self, args: String, env: &mut CommonEnv) -> Result, xous::Error> { let mut ret = String::new(); - let mut tokens = &args.split(' '); + let mut tokens = args.split(' '); if let Some(key) = tokens.next() { match key { diff --git a/apps/mtxcli/src/mtxcli.rs b/apps/mtxcli/src/mtxcli.rs index 0453b38cb..f558151f7 100644 --- a/apps/mtxcli/src/mtxcli.rs +++ b/apps/mtxcli/src/mtxcli.rs @@ -117,20 +117,16 @@ impl Mtxcli { let mut dirty = true; // take the input and pass it on to the various command parsers, and attach result - if let Some(local) = &self.input { - if let Some(res) = - self.env.dispatch(Some(&mut String::from(&local)), None).expect("command dispatch failed") - { - let output_history = - History { text: String::from(res.as_str().unwrap_or("UTF-8 Error")), is_input: false }; + if let Some(local) = &mut self.input { + if let Some(res) = self.env.dispatch(Some(local), None).expect("command dispatch failed") { + let output_history = History { text: String::from(res.as_str()), is_input: false }; self.circular_push(output_history); } else { dirty = false; } } else if let Some(msg) = &self.msg { if let Some(res) = self.env.dispatch(None, Some(msg)).expect("callback failed") { - let output_history = - History { text: String::from(res.as_str().unwrap_or("UTF-8 Error")), is_input: false }; + let output_history = History { text: String::from(res.as_str()), is_input: false }; self.circular_push(output_history); } else { dirty = false; @@ -152,11 +148,11 @@ impl Mtxcli { self.gam .draw_rectangle( self.content, - Rectangle::new_with_style( - Point::new(0, 0), - self.screensize, - DrawStyle { fill_color: Some(PixelColor::Light), stroke_color: None, stroke_width: 0 }, - ), + Rectangle::new_with_style(Point::new(0, 0), self.screensize, DrawStyle { + fill_color: Some(PixelColor::Light), + stroke_color: None, + stroke_width: 0, + }), ) .expect("can't clear content area"); }