Skip to content

Commit abd68ec

Browse files
committed
Add filter_alias() WIP
1 parent c2b244c commit abd68ec

File tree

1 file changed

+25
-9
lines changed

1 file changed

+25
-9
lines changed

examples/xbd-net/src/xbd/shell.rs

+25-9
Original file line numberDiff line numberDiff line change
@@ -73,19 +73,14 @@ pub async fn process_shell_stream() -> Result<(), i8> {
7373
prompt();
7474

7575
while let Some(mut line) = stream.next().await {
76+
assert!(line.ends_with("\0"));
7677
println!("[async shell] (null terminated) line: {} (len: {} SHELL_BUFSIZE: {})",
7778
line, line.len(), SHELL_BUFSIZE);
7879
//println!(" line.as_bytes(): {:?}", line.as_bytes());
79-
//println!(" line: {:?}", line);
80+
println!(" line: {:?}", line);
8081

81-
match line.as_str() { // alias handling
82-
"h\0" => {
83-
line.clear();
84-
line.push_str("help\0").unwrap();
85-
},
86-
// ...
87-
_ => (),
88-
}
82+
filter_alias(&mut line);
83+
assert!(line.ends_with("\0"));
8984

9085
unsafe { handle_input_line_minerva(shell_commands, line.as_ptr()); }
9186

@@ -97,6 +92,27 @@ pub async fn process_shell_stream() -> Result<(), i8> {
9792
Ok(())
9893
}
9994

95+
fn filter_alias(line: &mut ShellBuf) {
96+
assert!(line.ends_with("\0"));
97+
98+
let expand = |line: &mut ShellBuf, alias| {
99+
line.clear();
100+
line.push_str(alias).unwrap();
101+
line.push('\0').unwrap();
102+
};
103+
104+
match &line[..line.len() - 1] { // chars that precede '\0'
105+
"alias" | "a" => {
106+
println!("aliases: <list> ..."); // TODO
107+
expand(line, "");
108+
},
109+
"h" => expand(line, "help"),
110+
"1" => expand(line, "gcoap get [::1] /riot/board"),
111+
"2" => expand(line, "gcoap get [::1] /const/song.txt"),
112+
_ => (),
113+
}
114+
}
115+
100116
fn prompt() {
101117
//let tag: Option<&str> = None;
102118
let tag = Some("(async)\0");

0 commit comments

Comments
 (0)