@@ -73,19 +73,14 @@ pub async fn process_shell_stream() -> Result<(), i8> {
73
73
prompt ( ) ;
74
74
75
75
while let Some ( mut line) = stream. next ( ) . await {
76
+ assert ! ( line. ends_with( "\0 " ) ) ;
76
77
println ! ( "[async shell] (null terminated) line: {} (len: {} SHELL_BUFSIZE: {})" ,
77
78
line, line. len( ) , SHELL_BUFSIZE ) ;
78
79
//println!(" line.as_bytes(): {:?}", line.as_bytes());
79
- // println!(" line: {:?}", line);
80
+ println ! ( " line: {:?}" , line) ;
80
81
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 " ) ) ;
89
84
90
85
unsafe { handle_input_line_minerva ( shell_commands, line. as_ptr ( ) ) ; }
91
86
@@ -97,6 +92,27 @@ pub async fn process_shell_stream() -> Result<(), i8> {
97
92
Ok ( ( ) )
98
93
}
99
94
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
+
100
116
fn prompt ( ) {
101
117
//let tag: Option<&str> = None;
102
118
let tag = Some ( "(async)\0 " ) ;
0 commit comments