pub struct History { /* private fields */ }
Expand description
Current state of the history.
Implementations§
source§impl History
impl History
sourcepub fn with_config(config: Config) -> Self
pub fn with_config(config: Config) -> Self
Customized constructor with:
Config::max_history_size()
,Config::history_ignore_space()
,Config::history_duplicates()
.
sourcepub fn get(&self, index: usize) -> Option<&String>
pub fn get(&self, index: usize) -> Option<&String>
Return the history entry at position index
, starting from 0.
sourcepub fn add<S: AsRef<str> + Into<String>>(&mut self, line: S) -> bool
pub fn add<S: AsRef<str> + Into<String>>(&mut self, line: S) -> bool
Add a new entry in the history.
sourcepub fn set_max_len(&mut self, len: usize)
pub fn set_max_len(&mut self, len: usize)
Set the maximum length for the history. This function can be called even
if there is already some history, the function will make sure to retain
just the latest len
elements if the new history length value is
smaller than the amount of items already inside the history.
Like stifle_history.
sourcepub fn save<P: AsRef<Path> + ?Sized>(&mut self, path: &P) -> Result<()>
pub fn save<P: AsRef<Path> + ?Sized>(&mut self, path: &P) -> Result<()>
Save the history in the specified file.
sourcepub fn append<P: AsRef<Path> + ?Sized>(&mut self, path: &P) -> Result<()>
pub fn append<P: AsRef<Path> + ?Sized>(&mut self, path: &P) -> Result<()>
Append new entries in the specified file.
sourcepub fn load<P: AsRef<Path> + ?Sized>(&mut self, path: &P) -> Result<()>
pub fn load<P: AsRef<Path> + ?Sized>(&mut self, path: &P) -> Result<()>
Load the history from the specified file.
§Errors
Will return Err
if path does not already exist or could not be read.
sourcepub fn search(
&self,
term: &str,
start: usize,
dir: SearchDirection,
) -> Option<SearchResult<'_>>
pub fn search( &self, term: &str, start: usize, dir: SearchDirection, ) -> Option<SearchResult<'_>>
Search history (start position inclusive [0, len-1]).
Return the absolute index of the nearest history entry that matches
term
.
Return None if no entry contains term
between [start, len -1] for
forward search
or between [0, start] for reverse search.
sourcepub fn starts_with(
&self,
term: &str,
start: usize,
dir: SearchDirection,
) -> Option<SearchResult<'_>>
pub fn starts_with( &self, term: &str, start: usize, dir: SearchDirection, ) -> Option<SearchResult<'_>>
Anchored search