diff --git a/examples/demo.rs b/examples/demo.rs index a545b04..a17b48f 100644 --- a/examples/demo.rs +++ b/examples/demo.rs @@ -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() { diff --git a/src/engine.rs b/src/engine.rs index 90d7af8..56170db 100644 --- a/src/engine.rs +++ b/src/engine.rs @@ -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