mirror of
https://github.com/saymrwulf/xous-core.git
synced 2026-11-21 09:14:34 +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 core::fmt::Write;
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
|
||||||
use xous::MessageEnvelope;
|
|
||||||
use String;
|
use String;
|
||||||
|
use xous::MessageEnvelope;
|
||||||
/////////////////////////// Common items to all commands
|
/////////////////////////// Common items to all commands
|
||||||
pub trait ShellCmdApi<'a> {
|
pub trait ShellCmdApi<'a> {
|
||||||
// user implemented:
|
// user implemented:
|
||||||
|
|
@ -123,7 +123,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;
|
||||||
|
|
||||||
// search through the list of commands linearly until one matches,
|
// search through the list of commands linearly until one matches,
|
||||||
// then run it.
|
// then run it.
|
||||||
|
|
@ -131,7 +131,7 @@ impl CmdEnv {
|
||||||
for cmd in commands.iter_mut() {
|
for cmd in commands.iter_mut() {
|
||||||
if cmd.matches(verb) {
|
if cmd.matches(verb) {
|
||||||
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");
|
||||||
};
|
};
|
||||||
|
|
@ -145,7 +145,7 @@ impl CmdEnv {
|
||||||
if !first {
|
if !first {
|
||||||
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))
|
||||||
|
|
@ -159,8 +159,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;
|
||||||
|
|
@ -190,13 +190,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
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,9 @@
|
||||||
use core::fmt::Write;
|
use core::fmt::Write;
|
||||||
|
|
||||||
|
use String;
|
||||||
use codec::*;
|
use codec::*;
|
||||||
use locales::t;
|
use locales::t;
|
||||||
use xous::{Message, MessageEnvelope};
|
use xous::{Message, MessageEnvelope};
|
||||||
use String;
|
|
||||||
|
|
||||||
use crate::{CommonEnv, ShellCmdApi};
|
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> {
|
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 helpstring = t!("replapp.audio.help", locales::LANG);
|
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() {
|
if let Some(sub_cmd) = tokens.next() {
|
||||||
match sub_cmd {
|
match sub_cmd {
|
||||||
|
|
|
||||||
|
|
@ -122,20 +122,16 @@ impl Repl {
|
||||||
|
|
||||||
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;
|
||||||
|
|
@ -157,11 +153,11 @@ impl Repl {
|
||||||
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