sl_liner

Struct History

Source
pub struct History { /* private fields */ }
Expand description

Structure encapsulating command history

Implementations§

Source§

impl History

Source

pub fn new() -> History

Create new History structure.

Source

pub fn set_max_contexts(&mut self, n: usize)

Source

pub fn set_search_context(&mut self, context: Option<String>)

Source

pub fn clear_history(&mut self)

Clears out the history.

Source

pub fn load_history(&mut self, append: bool) -> Result<()>

Loads the history file from the saved path and appends it to the end of the history if append is true otherwise replace history.

Source

pub fn load_history_file<P: AsRef<Path>>( &mut self, path: P, append: bool, ) -> Result<u64>

Loads the history file from path and appends it to the end of the history if append is true.

Source

pub fn set_file_name_and_load_history<P: AsRef<Path>>( &mut self, path: P, ) -> Result<u64>

Set history file name and at the same time load the history.

Source

pub fn set_max_history_size(&mut self, size: usize)

Set maximal number of buffers in history

Source

pub fn len(&self) -> usize

Number of items in history.

Source

pub fn is_empty(&self) -> bool

Is the history empty

Source

pub fn push_throwaway(&mut self, new_item: impl Into<String>) -> Result<()>

Adds a “throwaway” history item. Any of these will be removed once push is called. Intended to allow “error” or other bad items to stick around long enough for the user to correct without cluttering history long term.

Source

pub fn push(&mut self, new_item: impl Into<String>) -> Result<()>

Add a command to the history buffer and remove the oldest commands when the max history size has been met. If writing to the disk is enabled, this function will be used for logging history to the designated history file.

Source

pub fn get_newest_match( &self, curr_position: Option<usize>, new_buff: &str, ) -> Option<usize>

Go through the history and try to find an index (newest to oldest) which starts the same as the new buffer given to this function as argument. Starts at curr_position. Does not wrap.

Source

pub fn get_history_subset(&self, search_term: &str) -> Vec<usize>

Source

pub fn search_index(&self, search_term: &str) -> Vec<usize>

Source

pub fn file_name(&self) -> Option<&str>

Get the history file name.

Source

pub fn commit_to_file_path<P: AsRef<Path>>(&mut self, path: P) -> Result<()>

Source

pub fn commit_to_file(&mut self) -> Result<()>

Source

pub fn get_context(&self, index: usize) -> &Option<Vec<String>>

Trait Implementations§

Source§

impl Default for History

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Index<usize> for History

Source§

type Output = str

The returned type after indexing.
Source§

fn index(&self, index: usize) -> &str

Performs the indexing (container[index]) operation. Read more

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.