Navigates through the command history.
(&mut self, delta: isize)
| 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 { |
no test coverage detected