port apps/mtxcli to xous-ipc 0.10

This commit is contained in:
bunnie 2024-09-23 14:30:46 +08:00
parent 4239176bec
commit 553f98f7f2
6 changed files with 22 additions and 26 deletions

View file

@ -714,7 +714,7 @@ impl CmdEnv {
let mut cmd_ret: Result<Option<String>, 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<Option<String>, 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<String> {
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

View file

@ -15,7 +15,7 @@ impl<'a> ShellCmdApi<'a> for Get {
fn process(&mut self, args: String, env: &mut CommonEnv) -> Result<Option<String>, 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 {

View file

@ -17,7 +17,7 @@ impl<'a> ShellCmdApi<'a> for Help {
fn process(&mut self, args: String, _env: &mut CommonEnv) -> Result<Option<String>, 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 };

View file

@ -15,7 +15,7 @@ impl<'a> ShellCmdApi<'a> for Set {
fn process(&mut self, args: String, env: &mut CommonEnv) -> Result<Option<String>, 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 {

View file

@ -15,7 +15,7 @@ impl<'a> ShellCmdApi<'a> for Unset {
fn process(&mut self, args: String, env: &mut CommonEnv) -> Result<Option<String>, 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 {

View file

@ -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");
}