feat: immediately accept

This commit is contained in:
mrdgo
2025-02-11 14:27:51 +01:00
parent 553c951a60
commit 7a13cd1676
4 changed files with 27 additions and 1 deletions

View File

@ -325,6 +325,7 @@ bench = false
# changing versions in each sub-crate of the workspace is tedious
[patch.crates-io]
# reedline = { git = "https://github.com/nushell/reedline", branch = "main" }
reedline = { git = "https://github.com/mrdgo/reedline.git", rev = "3a6ad518", features = ["bashisms", "sqlite"] }
# nu-ansi-term = {git = "https://github.com/nushell/nu-ansi-term.git", branch = "main"}
# Run all benchmarks with `cargo bench`

View File

@ -26,6 +26,11 @@ impl Command for SubCommand {
"replaces the current contents of the buffer (default)",
Some('r'),
)
.switch(
"accept",
"immediately executes the result after edit",
Some('A'),
)
.required(
"str",
SyntaxShape::String,
@ -61,6 +66,13 @@ impl Command for SubCommand {
repl.buffer = str;
repl.cursor_pos = repl.buffer.len();
}
if call.has_flag(engine_state, stack, "accept")? {
if let Ok(mut flag) = engine_state.immediately_execute.lock() {
*flag = true;
}
}
Ok(Value::nothing(call.head).into_pipeline_data())
}
}

View File

@ -481,7 +481,18 @@ fn loop_iteration(ctx: LoopContext) -> (bool, Stack, Reedline) {
start_time = std::time::Instant::now();
line_editor = line_editor.with_transient_prompt(transient_prompt);
let input = line_editor.read_line(nu_prompt);
let input = line_editor.read_line(
nu_prompt,
if let Ok(mut flag) = engine_state.immediately_execute.lock() {
let ret = *flag;
*flag = false;
ret
} else {
false
},
);
// we got our inputs, we can now drop our stack references
// This lists all of the stack references that we have cleaned up
line_editor = line_editor

View File

@ -95,6 +95,7 @@ pub struct EngineState {
pub config: Arc<Config>,
pub pipeline_externals_state: Arc<(AtomicU32, AtomicU32)>,
pub repl_state: Arc<Mutex<ReplState>>,
pub immediately_execute: Arc<Mutex<bool>>,
pub table_decl_id: Option<DeclId>,
#[cfg(feature = "plugin")]
pub plugin_path: Option<PathBuf>,
@ -180,6 +181,7 @@ impl EngineState {
startup_time: -1,
is_debugging: IsDebugging::new(false),
debugger: Arc::new(Mutex::new(Box::new(NoopDebugger))),
immediately_execute: Arc::new(Mutex::new(false)),
}
}