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§
source§impl FileBackedHistory
impl FileBackedHistory
sourcepub fn new(capacity: usize) -> Result<Self>
pub fn new(capacity: usize) -> Result<Self>
Creates a new in-memory history that remembers n <= capacity
elements
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§
source§impl Debug for FileBackedHistory
impl Debug for FileBackedHistory
source§impl Default for FileBackedHistory
impl Default for FileBackedHistory
source§fn 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()
§Panics
If HISTORY_SIZE == usize::MAX
source§impl Drop for FileBackedHistory
impl Drop for FileBackedHistory
source§fn 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()
.
source§impl History for FileBackedHistory
impl History for FileBackedHistory
source§fn save(&mut self, h: HistoryItem) -> Result<HistoryItem>
fn save(&mut self, h: HistoryItem) -> Result<HistoryItem>
only saves a value if it’s different than the last value
source§fn sync(&mut self) -> Result<()>
fn sync(&mut self) -> Result<()>
Writes unwritten history contents to disk.
If file would exceed capacity
truncates the oldest entries.