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

Method do_up_down

std/src/console/readline.rs:292–323  ·  view source on GitHub ↗

Navigates through the command history.

(&mut self, delta: isize)

Source from the content-addressed store, hash-verified

290
291 /// Navigates through the command history.
292 fn do_up_down(&mut self, delta: isize) -> io::Result<DispatchResult> {
293 let (new_history_pos, new_line) = {
294 let history = match self.history.as_deref_mut() {
295 Some(history) => history,
296 None => return Ok(DispatchResult::Continue),
297 };
298
299 let new_history_pos = if delta < 0 {
300 if self.history_pos == 0 {
301 return Ok(DispatchResult::Continue);
302 }
303 self.history_pos - 1
304 } else {
305 if self.history_pos == history.len() - 1 {
306 return Ok(DispatchResult::Continue);
307 }
308 self.history_pos + 1
309 };
310
311 history[self.history_pos] = self.line.to_string();
312 (new_history_pos, history[new_history_pos].clone())
313 };
314
315 let old_pos = self.current_pos();
316 let clear_len = self.rendered_len;
317 self.history_pos = new_history_pos;
318 self.line = LineBuffer::from(&new_line);
319 self.pos = self.line.len();
320 self.reset_view_to_end();
321 self.redraw_line(old_pos, clear_len, self.current_pos())?;
322 Ok(DispatchResult::Continue)
323 }
324
325 /// Finalizes history bookkeeping and returns the edited line.
326 fn finish(mut self) -> String {

Callers 1

runMethod · 0.80

Calls 4

current_posMethod · 0.80
reset_view_to_endMethod · 0.80
redraw_lineMethod · 0.80
lenMethod · 0.45

Tested by

no test coverage detected