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.
This commit is contained in:
unrelentingtech 2022-09-09 22:12:30 +03:00 committed by GitHub
parent d636eefd64
commit dc091e8285
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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(),