mirror of
https://github.com/saymrwulf/xous-core.git
synced 2026-11-16 08:38:26 +00:00
port apps/repl to xous-ipc 0.10
This commit is contained in:
parent
f4a4dfbc53
commit
d581bd4a33
3 changed files with 20 additions and 24 deletions
|
|
@ -1,8 +1,8 @@
|
|||
use core::fmt::Write;
|
||||
use std::collections::HashMap;
|
||||
|
||||
use xous::MessageEnvelope;
|
||||
use String;
|
||||
use xous::MessageEnvelope;
|
||||
/////////////////////////// Common items to all commands
|
||||
pub trait ShellCmdApi<'a> {
|
||||
// user implemented:
|
||||
|
|
@ -123,7 +123,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;
|
||||
|
||||
// search through the list of commands linearly until one matches,
|
||||
// then run it.
|
||||
|
|
@ -131,7 +131,7 @@ impl CmdEnv {
|
|||
for cmd in commands.iter_mut() {
|
||||
if cmd.matches(verb) {
|
||||
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");
|
||||
};
|
||||
|
|
@ -145,7 +145,7 @@ impl CmdEnv {
|
|||
if !first {
|
||||
ret.push_str(", ");
|
||||
}
|
||||
ret.append(cmd.verb())?;
|
||||
ret.push_str(cmd.verb());
|
||||
first = false;
|
||||
}
|
||||
Ok(Some(ret))
|
||||
|
|
@ -159,8 +159,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;
|
||||
|
|
@ -190,13 +190,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
|
||||
|
|
|
|||
|
|
@ -1,9 +1,9 @@
|
|||
use core::fmt::Write;
|
||||
|
||||
use String;
|
||||
use codec::*;
|
||||
use locales::t;
|
||||
use xous::{Message, MessageEnvelope};
|
||||
use String;
|
||||
|
||||
use crate::{CommonEnv, ShellCmdApi};
|
||||
|
||||
|
|
@ -63,7 +63,7 @@ impl<'a> ShellCmdApi<'a> for Audio {
|
|||
fn process(&mut self, args: String, env: &mut CommonEnv) -> Result<Option<String>, xous::Error> {
|
||||
let mut ret = String::new();
|
||||
let helpstring = t!("replapp.audio.help", locales::LANG);
|
||||
let mut tokens = &args.split(' ');
|
||||
let mut tokens = args.split(' ');
|
||||
|
||||
if let Some(sub_cmd) = tokens.next() {
|
||||
match sub_cmd {
|
||||
|
|
|
|||
|
|
@ -122,20 +122,16 @@ impl Repl {
|
|||
|
||||
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;
|
||||
|
|
@ -157,11 +153,11 @@ impl Repl {
|
|||
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");
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue