MCPcopy Index your code
hub / github.com/endbasic/endbasic / erase_at

Method erase_at

std/src/console/readline.rs:112–132  ·  view source on GitHub ↗

Erases a character and redraws the visible tail of the line.

(&mut self, cursor_pos: usize, remove_pos: usize)

Source from the content-addressed store, hash-verified

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> {

Callers 2

do_backspaceMethod · 0.80
do_deleteMethod · 0.80

Calls 7

endMethod · 0.80
removeMethod · 0.80
hide_cursorMethod · 0.45
move_within_lineMethod · 0.45
lenMethod · 0.45
writeMethod · 0.45
show_cursorMethod · 0.45

Tested by

no test coverage detected