File tree Expand file tree Collapse file tree 1 file changed +11
-5
lines changed Expand file tree Collapse file tree 1 file changed +11
-5
lines changed Original file line number Diff line number Diff line change @@ -134,7 +134,13 @@ fn print_help() {
134
134
135
135
fn prompt ( text : & str ) -> String {
136
136
print ! ( "{}" , text) ;
137
- let data: String = read ! ( ) ;
137
+ let mut data: String = read ! ( "{}\n " ) ;
138
+
139
+ // on Windows systems, if we read to \n, a \r character can be appended
140
+ // so we remove it - AFAIK this is a Windows-only isse
141
+ if data. ends_with ( '\r' ) {
142
+ data. pop ( ) ;
143
+ }
138
144
data
139
145
}
140
146
@@ -171,19 +177,19 @@ fn main() {
171
177
let mut active_portfolio: Portfolio = Portfolio { assets : vec ! [ ] } ;
172
178
let mut input: String ;
173
179
loop {
174
- print ! ( "» " ) ;
175
- input = read ! ( ) ;
180
+ input = prompt ( "» " ) ;
181
+
176
182
match input. as_str ( ) {
177
- // TODO: handle blank input properly somehow
178
183
"assets" => print_assets ( & active_portfolio. assets ) ,
179
- "exit" => break ,
180
184
"new" => active_portfolio. assets . push ( add_asset ( ) ) ,
181
185
"help" => print_help ( ) ,
182
186
"load" => match load_portfolio ( ) {
183
187
None => println ! ( "An error occurred when loading portfolio. Portfolio not loaded." ) ,
184
188
Some ( x) => active_portfolio = x,
185
189
} ,
186
190
"dump" => dump_portfolio ( & active_portfolio) ,
191
+ "exit" => break ,
192
+ "" => continue ,
187
193
_ => println ! ( "Unknown command. Enter 'help' for a list of valid commands" ) ,
188
194
}
189
195
}
You can’t perform that action at this time.
0 commit comments