mirror of
https://github.com/saymrwulf/xous-core.git
synced 2026-11-20 09:03:28 +00:00
port apps/mtxcli to xous-ipc 0.10
This commit is contained in:
parent
4239176bec
commit
553f98f7f2
6 changed files with 22 additions and 26 deletions
|
|
@ -714,7 +714,7 @@ impl CmdEnv {
|
||||||
|
|
||||||
let mut cmd_ret: Result<Option<String>, xous::Error> = Ok(None);
|
let mut cmd_ret: Result<Option<String>, xous::Error> = Ok(None);
|
||||||
if let Some(verb_string) = maybe_verb {
|
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 a slash then it's a command (else chat)
|
||||||
if verb.starts_with("/") {
|
if verb.starts_with("/") {
|
||||||
|
|
@ -725,7 +725,7 @@ impl CmdEnv {
|
||||||
for cmd in commands.iter_mut() {
|
for cmd in commands.iter_mut() {
|
||||||
if cmd.matches(command) {
|
if cmd.matches(command) {
|
||||||
match_found = true;
|
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();
|
self.lastverb.clear();
|
||||||
write!(self.lastverb, "{}", verb).expect("couldn't record last verb");
|
write!(self.lastverb, "{}", verb).expect("couldn't record last verb");
|
||||||
};
|
};
|
||||||
|
|
@ -740,7 +740,7 @@ impl CmdEnv {
|
||||||
ret.push_str(", ");
|
ret.push_str(", ");
|
||||||
}
|
}
|
||||||
ret.push_str("/");
|
ret.push_str("/");
|
||||||
ret.append(cmd.verb())?;
|
ret.push_str(cmd.verb());
|
||||||
first = false;
|
first = false;
|
||||||
}
|
}
|
||||||
Ok(Some(ret))
|
Ok(Some(ret))
|
||||||
|
|
@ -751,7 +751,7 @@ impl CmdEnv {
|
||||||
// chat
|
// chat
|
||||||
let mut text = String::from(verb);
|
let mut text = String::from(verb);
|
||||||
text.push_str(" ");
|
text.push_str(" ");
|
||||||
text.push_str(cmdline.to_str());
|
text.push_str(cmdline);
|
||||||
self.common_env.user_says(&text);
|
self.common_env.user_says(&text);
|
||||||
// only for sync case Ok(Some(ret))
|
// only for sync case Ok(Some(ret))
|
||||||
Ok(None)
|
Ok(None)
|
||||||
|
|
@ -764,8 +764,8 @@ impl CmdEnv {
|
||||||
let mut cmd_ret: Result<Option<String>, xous::Error> = Ok(None);
|
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
|
// 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)) {
|
let verb = match self.common_env.cb_registrations.get(&(callback.body.id() as u32)) {
|
||||||
Some(verb) => verb.to_str(),
|
Some(verb) => &verb,
|
||||||
None => self.lastverb.to_str(),
|
None => &self.lastverb,
|
||||||
};
|
};
|
||||||
// now dispatch
|
// now dispatch
|
||||||
let mut verbfound = false;
|
let mut verbfound = false;
|
||||||
|
|
@ -795,13 +795,13 @@ pub fn tokenize(line: &mut String) -> Option<String> {
|
||||||
let mut foundrest = false;
|
let mut foundrest = false;
|
||||||
for ch in lineiter {
|
for ch in lineiter {
|
||||||
if ch != ' ' && !foundspace {
|
if ch != ' ' && !foundspace {
|
||||||
token.push(ch).unwrap();
|
token.push(ch);
|
||||||
} else if foundspace && foundrest {
|
} else if foundspace && foundrest {
|
||||||
retline.push(ch).unwrap();
|
retline.push(ch);
|
||||||
} else if foundspace && ch != ' ' {
|
} else if foundspace && ch != ' ' {
|
||||||
// handle case of multiple spaces in a row
|
// handle case of multiple spaces in a row
|
||||||
foundrest = true;
|
foundrest = true;
|
||||||
retline.push(ch).unwrap();
|
retline.push(ch);
|
||||||
} else {
|
} else {
|
||||||
foundspace = true;
|
foundspace = true;
|
||||||
// consume the space
|
// consume the space
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,7 @@ impl<'a> ShellCmdApi<'a> for Get {
|
||||||
|
|
||||||
fn process(&mut self, args: String, env: &mut CommonEnv) -> Result<Option<String>, xous::Error> {
|
fn process(&mut self, args: String, env: &mut CommonEnv) -> Result<Option<String>, xous::Error> {
|
||||||
let mut ret = String::new();
|
let mut ret = String::new();
|
||||||
let mut tokens = &args.split(' ');
|
let mut tokens = args.split(' ');
|
||||||
|
|
||||||
if let Some(key) = tokens.next() {
|
if let Some(key) = tokens.next() {
|
||||||
match key {
|
match key {
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,7 @@ impl<'a> ShellCmdApi<'a> for Help {
|
||||||
|
|
||||||
fn process(&mut self, args: String, _env: &mut CommonEnv) -> Result<Option<String>, xous::Error> {
|
fn process(&mut self, args: String, _env: &mut CommonEnv) -> Result<Option<String>, xous::Error> {
|
||||||
let mut ret = String::new();
|
let mut ret = String::new();
|
||||||
let mut tokens = &args.split(' ');
|
let mut tokens = args.split(' ');
|
||||||
|
|
||||||
if let Some(slashcmd) = tokens.next() {
|
if let Some(slashcmd) = tokens.next() {
|
||||||
let cmd = if slashcmd.starts_with("/") { &slashcmd[1..] } else { slashcmd };
|
let cmd = if slashcmd.starts_with("/") { &slashcmd[1..] } else { slashcmd };
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,7 @@ impl<'a> ShellCmdApi<'a> for Set {
|
||||||
|
|
||||||
fn process(&mut self, args: String, env: &mut CommonEnv) -> Result<Option<String>, xous::Error> {
|
fn process(&mut self, args: String, env: &mut CommonEnv) -> Result<Option<String>, xous::Error> {
|
||||||
let mut ret = String::new();
|
let mut ret = String::new();
|
||||||
let mut tokens = &args.split(' ');
|
let mut tokens = args.split(' ');
|
||||||
|
|
||||||
if let Some(key) = tokens.next() {
|
if let Some(key) = tokens.next() {
|
||||||
match key {
|
match key {
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,7 @@ impl<'a> ShellCmdApi<'a> for Unset {
|
||||||
|
|
||||||
fn process(&mut self, args: String, env: &mut CommonEnv) -> Result<Option<String>, xous::Error> {
|
fn process(&mut self, args: String, env: &mut CommonEnv) -> Result<Option<String>, xous::Error> {
|
||||||
let mut ret = String::new();
|
let mut ret = String::new();
|
||||||
let mut tokens = &args.split(' ');
|
let mut tokens = args.split(' ');
|
||||||
|
|
||||||
if let Some(key) = tokens.next() {
|
if let Some(key) = tokens.next() {
|
||||||
match key {
|
match key {
|
||||||
|
|
|
||||||
|
|
@ -117,20 +117,16 @@ impl Mtxcli {
|
||||||
|
|
||||||
let mut dirty = true;
|
let mut dirty = true;
|
||||||
// take the input and pass it on to the various command parsers, and attach result
|
// take the input and pass it on to the various command parsers, and attach result
|
||||||
if let Some(local) = &self.input {
|
if let Some(local) = &mut self.input {
|
||||||
if let Some(res) =
|
if let Some(res) = self.env.dispatch(Some(local), None).expect("command dispatch failed") {
|
||||||
self.env.dispatch(Some(&mut String::from(&local)), None).expect("command dispatch failed")
|
let output_history = History { text: String::from(res.as_str()), is_input: false };
|
||||||
{
|
|
||||||
let output_history =
|
|
||||||
History { text: String::from(res.as_str().unwrap_or("UTF-8 Error")), is_input: false };
|
|
||||||
self.circular_push(output_history);
|
self.circular_push(output_history);
|
||||||
} else {
|
} else {
|
||||||
dirty = false;
|
dirty = false;
|
||||||
}
|
}
|
||||||
} else if let Some(msg) = &self.msg {
|
} else if let Some(msg) = &self.msg {
|
||||||
if let Some(res) = self.env.dispatch(None, Some(msg)).expect("callback failed") {
|
if let Some(res) = self.env.dispatch(None, Some(msg)).expect("callback failed") {
|
||||||
let output_history =
|
let output_history = History { text: String::from(res.as_str()), is_input: false };
|
||||||
History { text: String::from(res.as_str().unwrap_or("UTF-8 Error")), is_input: false };
|
|
||||||
self.circular_push(output_history);
|
self.circular_push(output_history);
|
||||||
} else {
|
} else {
|
||||||
dirty = false;
|
dirty = false;
|
||||||
|
|
@ -152,11 +148,11 @@ impl Mtxcli {
|
||||||
self.gam
|
self.gam
|
||||||
.draw_rectangle(
|
.draw_rectangle(
|
||||||
self.content,
|
self.content,
|
||||||
Rectangle::new_with_style(
|
Rectangle::new_with_style(Point::new(0, 0), self.screensize, DrawStyle {
|
||||||
Point::new(0, 0),
|
fill_color: Some(PixelColor::Light),
|
||||||
self.screensize,
|
stroke_color: None,
|
||||||
DrawStyle { fill_color: Some(PixelColor::Light), stroke_color: None, stroke_width: 0 },
|
stroke_width: 0,
|
||||||
),
|
}),
|
||||||
)
|
)
|
||||||
.expect("can't clear content area");
|
.expect("can't clear content area");
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue