File tree 1 file changed +19
-6
lines changed
1 file changed +19
-6
lines changed Original file line number Diff line number Diff line change @@ -54,18 +54,31 @@ impl UART {
54
54
55
55
pub fn read_line < ' a > ( & mut self , buf : & ' a mut [ u8 ] , echo : bool ) -> & ' a [ u8 ] {
56
56
let mut max_len = buf. len ( ) ;
57
- let mut count = 0 ;
57
+ let mut count: usize = 0 ;
58
58
while max_len > 0 {
59
59
let cur = self . read_byte ( ) ;
60
60
if cur == b'\r' || cur == b'\n' {
61
61
break ;
62
62
}
63
- if echo {
64
- self . write_byte ( cur) ;
63
+ match cur {
64
+ b'\r' | b'\n' => break ,
65
+ // delete and backspace
66
+ b'\x7f' | b'\x08' => {
67
+ if echo && count > 0 {
68
+ self . write_bytes ( b"\x08 \x20 \x08 " ) ;
69
+ }
70
+ count = count. checked_sub ( 1 ) . unwrap_or ( 0 ) ;
71
+ max_len = max_len. checked_add ( 1 ) . unwrap_or ( 0 ) ;
72
+ }
73
+ _ => {
74
+ if echo {
75
+ self . write_byte ( cur) ;
76
+ }
77
+ buf[ count] = cur;
78
+ count += 1 ;
79
+ max_len -= 1 ;
80
+ }
65
81
}
66
- buf[ count] = cur;
67
- count += 1 ;
68
- max_len -= 1 ;
69
82
}
70
83
if echo {
71
84
self . write_byte ( b'\n' ) ;
You can’t perform that action at this time.
0 commit comments