Improve history handling with regards to position and duplicates
This commit is contained in:
parent
aa164087fa
commit
fae004f76c
@ -3,7 +3,7 @@ use std::collections::VecDeque;
|
|||||||
pub struct History {
|
pub struct History {
|
||||||
pub entries: VecDeque<String>,
|
pub entries: VecDeque<String>,
|
||||||
pub max_size: usize,
|
pub max_size: usize,
|
||||||
current_position: Option<usize>,
|
pub current_position: Option<usize>,
|
||||||
}
|
}
|
||||||
impl Default for History {
|
impl Default for History {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
|
@ -359,7 +359,11 @@ impl LineState {
|
|||||||
self.clear_and_render(term)?;
|
self.clear_and_render(term)?;
|
||||||
|
|
||||||
// Add to history...
|
// Add to history...
|
||||||
|
if self.history.entries.front() != Some(&line) {
|
||||||
self.history.entries.push_front(line.clone());
|
self.history.entries.push_front(line.clone());
|
||||||
|
self.history.entries.truncate(self.history.max_size);
|
||||||
|
}
|
||||||
|
self.history.current_position = None;
|
||||||
|
|
||||||
// Return line
|
// Return line
|
||||||
return Ok(Some(ReadlineEvent::Line(line)));
|
return Ok(Some(ReadlineEvent::Line(line)));
|
||||||
|
Loading…
Reference in New Issue
Block a user