pub struct History { /* private fields */ }Expand description
Command history manager with circular buffer storage.
Maintains a fixed-size history of entered commands with automatic duplicate and empty-line filtering. Supports bidirectional navigation and preserves the current line when browsing history.
§Examples
use editline::History;
let mut hist = History::new(50);
hist.add("first command");
hist.add("second command");
// Navigate through history
assert_eq!(hist.previous(""), Some("second command"));
assert_eq!(hist.previous(""), Some("first command"));Implementations§
Source§impl History
impl History
Sourcepub fn new(capacity: usize) -> Self
pub fn new(capacity: usize) -> Self
Creates a new history buffer with the specified capacity.
When the capacity is reached, the oldest entries are overwritten.
§Arguments
capacity- Maximum number of history entries to store
Sourcepub fn add(&mut self, line: &str)
pub fn add(&mut self, line: &str)
Adds a line to the history.
Empty lines (including whitespace-only) and consecutive duplicates are automatically skipped. When the buffer is full, the oldest entry is overwritten.
§Arguments
line- The command line to add to history
Sourcepub fn previous(&mut self, current_line: &str) -> Option<&str>
pub fn previous(&mut self, current_line: &str) -> Option<&str>
Navigates to the previous (older) history entry.
On the first call, saves current_line so it can be restored when
navigating forward past the most recent entry.
§Arguments
current_line- The current line content to save (only used on first call)
§Returns
Some(&str) with the previous history entry, or None if at the oldest entry.
Sourcepub fn next_entry(&mut self) -> Option<&str>
pub fn next_entry(&mut self) -> Option<&str>
Sourcepub fn reset_view(&mut self)
pub fn reset_view(&mut self)
Resets the history view to the current line.
Called when the user starts typing to exit history browsing mode.