Improve history handling with regards to position and duplicates

This commit is contained in:
Condorra 2024-08-17 22:09:06 +10:00
parent aa164087fa
commit fae004f76c
2 changed files with 6 additions and 2 deletions

View File

@ -3,7 +3,7 @@ use std::collections::VecDeque;
pub struct History {
pub entries: VecDeque<String>,
pub max_size: usize,
current_position: Option<usize>,
pub current_position: Option<usize>,
}
impl Default for History {
fn default() -> Self {

View File

@ -359,7 +359,11 @@ impl LineState {
self.clear_and_render(term)?;
// Add to history...
self.history.entries.push_front(line.clone());
if self.history.entries.front() != Some(&line) {
self.history.entries.push_front(line.clone());
self.history.entries.truncate(self.history.max_size);
}
self.history.current_position = None;
// Return line
return Ok(Some(ReadlineEvent::Line(line)));