4242 /// Maximum four levels deep
4343 menus : [ Option < & ' a Menu < ' a , T > > ; 4 ] ,
4444 depth : usize ,
45- pub output : & ' a mut T ,
45+ pub context : & ' a mut T ,
4646}
4747
4848enum Outcome {
@@ -54,7 +54,7 @@ impl<'a, T> Runner<'a, T>
5454where
5555 T : core:: fmt:: Write ,
5656{
57- pub fn new ( menu : & ' a Menu < ' a , T > , buffer : & ' a mut [ u8 ] , output : & ' a mut T ) -> Runner < ' a , T > {
57+ pub fn new ( menu : & ' a Menu < ' a , T > , buffer : & ' a mut [ u8 ] , context : & ' a mut T ) -> Runner < ' a , T > {
5858 if let Some ( cb_fn) = menu. entry {
5959 cb_fn ( menu) ;
6060 }
@@ -63,25 +63,25 @@ where
6363 depth : 0 ,
6464 buffer,
6565 used : 0 ,
66- output ,
66+ context ,
6767 } ;
6868 r. prompt ( ) ;
6969 r
7070 }
7171
7272 pub fn prompt ( & mut self ) {
73- write ! ( self . output , "\n " ) . unwrap ( ) ;
73+ write ! ( self . context , "\n " ) . unwrap ( ) ;
7474 if self . depth != 0 {
7575 let mut depth = 1 ;
7676 while depth <= self . depth {
7777 if depth > 1 {
78- write ! ( self . output , "/" ) . unwrap ( ) ;
78+ write ! ( self . context , "/" ) . unwrap ( ) ;
7979 }
80- write ! ( self . output , "/{}" , self . menus[ depth] . unwrap( ) . label) . unwrap ( ) ;
80+ write ! ( self . context , "/{}" , self . menus[ depth] . unwrap( ) . label) . unwrap ( ) ;
8181 depth += 1 ;
8282 }
8383 }
84- write ! ( self . output , "> " ) . unwrap ( ) ;
84+ write ! ( self . context , "> " ) . unwrap ( ) ;
8585 }
8686
8787 pub fn input_byte ( & mut self , input : u8 ) {
@@ -90,25 +90,25 @@ where
9090 return ;
9191 }
9292 let outcome = if input == 0x0D {
93- write ! ( self . output , "\n " ) . unwrap ( ) ;
93+ write ! ( self . context , "\n " ) . unwrap ( ) ;
9494 if let Ok ( s) = core:: str:: from_utf8 ( & self . buffer [ 0 ..self . used ] ) {
9595 if s == "help" {
9696 let menu = self . menus [ self . depth ] . unwrap ( ) ;
9797 for item in menu. items {
9898 if let Some ( help) = item. help {
99- writeln ! ( self . output , "{} - {}" , item. command, help) . unwrap ( ) ;
99+ writeln ! ( self . context , "{} - {}" , item. command, help) . unwrap ( ) ;
100100 } else {
101- writeln ! ( self . output , "{}" , item. command) . unwrap ( ) ;
101+ writeln ! ( self . context , "{}" , item. command) . unwrap ( ) ;
102102 }
103103 }
104104 if self . depth != 0 {
105- writeln ! ( self . output , "exit - leave this menu." ) . unwrap ( ) ;
105+ writeln ! ( self . context , "exit - leave this menu." ) . unwrap ( ) ;
106106 }
107- writeln ! ( self . output , "help - print this help text." ) . unwrap ( ) ;
107+ writeln ! ( self . context , "help - print this help text." ) . unwrap ( ) ;
108108 Outcome :: CommandProcessed
109109 } else if s == "exit" && self . depth != 0 {
110110 if self . depth == self . menus . len ( ) {
111- writeln ! ( self . output , "Can't enter menu - structure too deep." ) . unwrap ( ) ;
111+ writeln ! ( self . context , "Can't enter menu - structure too deep." ) . unwrap ( ) ;
112112 } else {
113113 self . menus [ self . depth ] = None ;
114114 self . depth -= 1 ;
@@ -122,7 +122,7 @@ where
122122 for item in menu. items {
123123 if cmd == item. command {
124124 match item. item_type {
125- ItemType :: Callback ( f) => f ( menu, item, s, & mut self . output ) ,
125+ ItemType :: Callback ( f) => f ( menu, item, s, & mut self . context ) ,
126126 ItemType :: Menu ( m) => {
127127 self . depth += 1 ;
128128 self . menus [ self . depth ] = Some ( m) ;
@@ -133,33 +133,33 @@ where
133133 }
134134 }
135135 if !found {
136- writeln ! ( self . output , "Command {:?} not found. Try 'help'." , cmd)
136+ writeln ! ( self . context , "Command {:?} not found. Try 'help'." , cmd)
137137 . unwrap ( ) ;
138138 }
139139 Outcome :: CommandProcessed
140140 } else {
141- writeln ! ( self . output , "Input empty" ) . unwrap ( ) ;
141+ writeln ! ( self . context , "Input empty" ) . unwrap ( ) ;
142142 Outcome :: CommandProcessed
143143 }
144144 }
145145 } else {
146- writeln ! ( self . output , "Input not valid UTF8" ) . unwrap ( ) ;
146+ writeln ! ( self . context , "Input not valid UTF8" ) . unwrap ( ) ;
147147 Outcome :: CommandProcessed
148148 }
149149 } else if input == 0x08 {
150150 // Handling backspace
151151 if self . used > 0 {
152- write ! ( self . output , "\u{0008} \u{0008} " ) . unwrap ( ) ;
152+ write ! ( self . context , "\u{0008} \u{0008} " ) . unwrap ( ) ;
153153 self . used -= 1 ;
154154 }
155155 Outcome :: NeedMore
156156 } else if self . used < self . buffer . len ( ) {
157157 self . buffer [ self . used ] = input;
158158 self . used += 1 ;
159- write ! ( self . output , "{}" , input as char ) . unwrap ( ) ;
159+ write ! ( self . context , "{}" , input as char ) . unwrap ( ) ;
160160 Outcome :: NeedMore
161161 } else {
162- writeln ! ( self . output , "Buffer overflow!" ) . unwrap ( ) ;
162+ writeln ! ( self . context , "Buffer overflow!" ) . unwrap ( ) ;
163163 Outcome :: NeedMore
164164 } ;
165165 match outcome {
0 commit comments