pub struct History { /* private fields */ }
Expand description
Current state of the history.
Implementations§
Source§impl History
impl History
pub fn new() -> History
pub fn with_config(config: Config) -> History
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](http://cnswww.cns.cwru. edu/php/chet/readline/history.html#IDX11).
Sourcepub fn save<P: AsRef<Path> + ?Sized>(&self, path: &P) -> Result<()>
pub fn save<P: AsRef<Path> + ?Sized>(&self, path: &P) -> Result<()>
Save the history 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: Direction) -> Option<usize>
pub fn search(&self, term: &str, start: usize, dir: Direction) -> Option<usize>
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.