Struct reedline::FileBackedHistory
source · [−]pub struct FileBackedHistory { /* private fields */ }
Expand description
Stateful history that allows up/down-arrow browsing with an internal cursor.
Can optionally be associated with a newline separated history file using the FileBackedHistory::with_file()
constructor.
Similar to bash’s behavior without HISTTIMEFORMAT.
(See https://www.gnu.org/software/bash/manual/html_node/Bash-History-Facilities.html)
If the history is associated to a file all new changes within a given history capacity will be written to disk when History is dropped.
Implementations
sourceimpl FileBackedHistory
impl FileBackedHistory
sourcepub fn new(capacity: usize) -> Self
pub fn new(capacity: usize) -> Self
Creates a new in-memory history that remembers n <= capacity
elements
Panics
If capacity == usize::MAX
sourcepub fn with_file(capacity: usize, file: PathBuf) -> Result<Self>
pub fn with_file(capacity: usize, file: PathBuf) -> Result<Self>
Creates a new history with an associated history file.
History file format: commands separated by new lines. If file exists file will be read otherwise empty file will be created.
Side effects: creates all nested directories to the file
Trait Implementations
sourceimpl Debug for FileBackedHistory
impl Debug for FileBackedHistory
sourceimpl Default for FileBackedHistory
impl Default for FileBackedHistory
sourcefn default() -> Self
fn default() -> Self
Creates an in-memory History
with a maximal capacity of HISTORY_SIZE
.
To create a History
that is synchronized with a file use FileBackedHistory::with_file()
sourceimpl Drop for FileBackedHistory
impl Drop for FileBackedHistory
sourcefn drop(&mut self)
fn drop(&mut self)
On drop the content of the History
will be written to the file if specified via FileBackedHistory::with_file()
.
sourceimpl History for FileBackedHistory
impl History for FileBackedHistory
sourcefn append(&mut self, entry: &str)
fn append(&mut self, entry: &str)
Appends an entry if non-empty and not repetition of the previous entry. Resets the browsing cursor to the default state in front of the most recent entry.
sourcefn sync(&mut self) -> Result<()>
fn sync(&mut self) -> Result<()>
Writes unwritten history contents to disk.
If file would exceed capacity
truncates the oldest entries.
sourcefn reset_cursor(&mut self)
fn reset_cursor(&mut self)
Reset the internal browsing cursor
sourcefn iter_chronologic(&self) -> Iter<'_, String>
fn iter_chronologic(&self) -> Iter<'_, String>
Chronologic interaction over all entries present in the history
sourcefn back(&mut self)
fn back(&mut self)
This moves the cursor backwards respecting the navigation query that is set Read more
sourcefn forward(&mut self)
fn forward(&mut self)
This moves the cursor forwards respecting the navigation-query that is set Read more
sourcefn string_at_cursor(&self) -> Option<String>
fn string_at_cursor(&self) -> Option<String>
Returns the string (if present) at the cursor
Set a new navigation mode for search based on input query defined in HistoryNavigationQuery
Read more
Poll the current HistoryNavigationQuery
mode
sourcefn query_entries(&self, search: &str) -> Vec<String>
fn query_entries(&self, search: &str) -> Vec<String>
Query the values in the history entries
sourcefn max_values(&self) -> usize
fn max_values(&self) -> usize
Max number of values that can be queried from the history
Auto Trait Implementations
impl RefUnwindSafe for FileBackedHistory
impl Send for FileBackedHistory
impl Sync for FileBackedHistory
impl Unpin for FileBackedHistory
impl UnwindSafe for FileBackedHistory
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more