@@ -255,9 +255,7 @@ impl Term {
255
255
buffer. extend_from_slice ( prompt. as_bytes ( ) ) ;
256
256
Ok ( ( ) )
257
257
}
258
- None => {
259
- self . write_through ( format ! ( "{}\n {}" , s, prompt. as_str( ) ) . as_bytes ( ) )
260
- }
258
+ None => self . write_through ( format ! ( "{}\n {}" , s, prompt. as_str( ) ) . as_bytes ( ) ) ,
261
259
}
262
260
}
263
261
@@ -315,7 +313,7 @@ impl Term {
315
313
}
316
314
317
315
/// Read one line of input with initial text.
318
- ///
316
+ ///
319
317
/// This method blocks until no other thread is waiting for this read_line
320
318
/// before reading a line from the terminal.
321
319
/// This does not include the trailing newline. If the terminal is not
@@ -331,31 +329,31 @@ impl Term {
331
329
self . write_str ( initial) ?;
332
330
333
331
fn read_line_internal ( slf : & Term , initial : & str ) -> io:: Result < String > {
334
- let prefix_len = initial. len ( ) ;
332
+ let prefix_len = initial. len ( ) ;
335
333
336
- let mut chars: Vec < char > = initial. chars ( ) . collect ( ) ;
334
+ let mut chars: Vec < char > = initial. chars ( ) . collect ( ) ;
337
335
338
- loop {
339
- match slf. read_key ( ) ? {
340
- Key :: Backspace => {
341
- if prefix_len < chars. len ( ) && chars. pop ( ) . is_some ( ) {
342
- slf. clear_chars ( 1 ) ?;
343
- }
344
- slf. flush ( ) ?;
345
- }
346
- Key :: Char ( chr) => {
347
- chars. push ( chr) ;
348
- let mut bytes_char = [ 0 ; 4 ] ;
349
- chr. encode_utf8 ( & mut bytes_char) ;
350
- slf. write_str ( chr. encode_utf8 ( & mut bytes_char) ) ?;
351
- slf. flush ( ) ?;
352
- }
353
- Key :: Enter => {
354
- slf. write_through ( format ! ( "\n {}" , initial) . as_bytes ( ) ) ?;
355
- break ;
336
+ loop {
337
+ match slf. read_key ( ) ? {
338
+ Key :: Backspace => {
339
+ if prefix_len < chars. len ( ) && chars. pop ( ) . is_some ( ) {
340
+ slf. clear_chars ( 1 ) ?;
356
341
}
357
- _ => ( ) ,
342
+ slf . flush ( ) ? ;
358
343
}
344
+ Key :: Char ( chr) => {
345
+ chars. push ( chr) ;
346
+ let mut bytes_char = [ 0 ; 4 ] ;
347
+ chr. encode_utf8 ( & mut bytes_char) ;
348
+ slf. write_str ( chr. encode_utf8 ( & mut bytes_char) ) ?;
349
+ slf. flush ( ) ?;
350
+ }
351
+ Key :: Enter => {
352
+ slf. write_through ( format ! ( "\n {}" , initial) . as_bytes ( ) ) ?;
353
+ break ;
354
+ }
355
+ _ => ( ) ,
356
+ }
359
357
}
360
358
Ok ( chars. iter ( ) . skip ( prefix_len) . collect :: < String > ( ) )
361
359
}
0 commit comments