Erases a character and redraws the visible tail of the line.
(&mut self, cursor_pos: usize, remove_pos: usize)
| 110 | |
| 111 | /// Erases a character and redraws the visible tail of the line. |
| 112 | fn erase_at(&mut self, cursor_pos: usize, remove_pos: usize) -> io::Result<()> { |
| 113 | debug_assert!(remove_pos < self.line.len()); |
| 114 | debug_assert!(remove_pos <= cursor_pos); |
| 115 | |
| 116 | self.console.hide_cursor()?; |
| 117 | let delta = cursor_pos - remove_pos; |
| 118 | if delta > 0 { |
| 119 | self.console.move_within_line(-(delta as i16))?; |
| 120 | } |
| 121 | let tail_len = self.line.len() - remove_pos - 1; |
| 122 | if self.echo { |
| 123 | self.console.write(&self.line.end(remove_pos + 1))?; |
| 124 | } else { |
| 125 | self.console.write(&SECURE_CHAR.repeat(tail_len))?; |
| 126 | } |
| 127 | self.console.write(" ")?; |
| 128 | self.console.move_within_line(-((tail_len + 1) as i16))?; |
| 129 | self.console.show_cursor()?; |
| 130 | self.line.remove(remove_pos); |
| 131 | Ok(()) |
| 132 | } |
| 133 | |
| 134 | /// Handles a backspace key press. |
| 135 | fn do_backspace(&mut self) -> io::Result<DispatchResult> { |
no test coverage detected