From dc091e828590de6fd335af3f1d001ede851ac20a Mon Sep 17 00:00:00 2001 From: unrelentingtech Date: Fri, 9 Sep 2022 22:12:30 +0300 Subject: [PATCH] Allow external manipulation of the command line buffer (#472) This allows nushell to implement a command similar to fish's `commandline`: https://fishshell.com/docs/current/cmds/commandline.html that would allow commands run via `executehostcommand` bindings to do interesting things to the contents of the input buffer. --- src/engine.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/engine.rs b/src/engine.rs index b570b56..2b4c86a 100644 --- a/src/engine.rs +++ b/src/engine.rs @@ -415,6 +415,11 @@ impl Reedline { result } + /// Returns the current contents of the input buffer. + pub fn current_buffer_contents(&self) -> &str { + self.editor.get_buffer() + } + /// Writes `msg` to the terminal with a following carriage return and newline fn print_line(&mut self, msg: &str) -> Result<()> { self.painter.paint_line(msg) @@ -1095,7 +1100,7 @@ impl Reedline { } /// Executes [`EditCommand`] actions by modifying the internal state appropriately. Does not output itself. - fn run_edit_commands(&mut self, commands: &[EditCommand]) { + pub fn run_edit_commands(&mut self, commands: &[EditCommand]) { if self.input_mode == InputMode::HistoryTraversal { if matches!( self.history_cursor.get_navigation(),