History

Struct History 

Source
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

Source

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
Source

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
Source

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.

Source

pub fn next_entry(&mut self) -> Option<&str>

Navigates to the next (newer) history entry.

When reaching the end of history, returns the saved current line that was passed to the first previous call.

§Returns

Some(&str) with the next history entry or saved line, or None if not currently viewing history.

Source

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.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.