Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: immediately execute command #882

Open
wants to merge 15 commits into
base: main
Choose a base branch
from
Next Next commit
feat: immediately execute command
mrdgo committed Feb 11, 2025
commit 74b3007b7fbbeff2a4145e4207b1b295f24fa364
13 changes: 10 additions & 3 deletions src/engine.rs
Original file line number Diff line number Diff line change
@@ -642,12 +642,12 @@ impl Reedline {
///
/// Returns a [`std::io::Result`] in which the `Err` type is [`std::io::Result`]
/// and the `Ok` variant wraps a [`Signal`] which handles user inputs.
pub fn read_line(&mut self, prompt: &dyn Prompt) -> Result<Signal> {
pub fn read_line(&mut self, prompt: &dyn Prompt, immediately_execute: bool) -> Result<Signal> {
terminal::enable_raw_mode()?;
self.bracketed_paste.enter();
self.kitty_protocol.enter();

let result = self.read_line_helper(prompt);
let result = self.read_line_helper(prompt, immediately_execute);

self.bracketed_paste.exit();
self.kitty_protocol.exit();
@@ -687,7 +687,11 @@ impl Reedline {

/// Helper implementing the logic for [`Reedline::read_line()`] to be wrapped
/// in a `raw_mode` context.
fn read_line_helper(&mut self, prompt: &dyn Prompt) -> Result<Signal> {
fn read_line_helper(
&mut self,
prompt: &dyn Prompt,
immediately_execute: bool,
) -> Result<Signal> {
self.painter
.initialize_prompt_position(self.suspended_state.as_ref())?;
if self.suspended_state.is_some() {
@@ -781,6 +785,9 @@ impl Reedline {
}
}
}
if immediately_execute {
reedline_events.push(ReedlineEvent::Submit);
}
if !edits.is_empty() {
reedline_events.push(ReedlineEvent::Edit(edits));
}