add history-clear to demo (#537)

This commit is contained in:
Darren Schroeder 2023-02-10 11:34:30 -06:00 committed by GitHub
parent d83cc56cb5
commit 572a391211
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 0 deletions

View File

@ -149,6 +149,13 @@ fn main() -> Result<()> {
line_editor.print_history()?;
continue;
}
if buffer.trim() == "clear-history" {
let hstry = Box::new(line_editor.history_mut());
hstry
.clear()
.map_err(|e| std::io::Error::new(std::io::ErrorKind::Other, e))?;
continue;
}
println!("Our buffer: {buffer}");
#[cfg(any(feature = "sqlite", feature = "sqlite-dynlib"))]
if !buffer.is_empty() {

View File

@ -411,6 +411,11 @@ impl Reedline {
&*self.history
}
/// Mutable view of the history
pub fn history_mut(&mut self) -> &mut dyn History {
&mut *self.history
}
/// Update the underlying [`History`] to/from disk
pub fn sync_history(&mut self) -> std::io::Result<()> {
// TODO: check for interactions in the non-submitting events