mirror of
https://github.com/nushell/nushell.git
synced 2025-08-16 09:28:32 +02:00
refactor: merge repl_buffer_state
, repl_cursor_pos
into one mutex (#9031)
# Description Merge `repl_buffer_state`, `repl_cursor_pos` into one mutex. # User-Facing Changes # Tests + Formatting # After Submitting
This commit is contained in:
@ -475,30 +475,19 @@ pub fn evaluate_repl(
|
||||
// hook
|
||||
if let Some(hook) = config.hooks.pre_execution.clone() {
|
||||
// Set the REPL buffer to the current command for the "pre_execution" hook
|
||||
let mut repl_buffer = engine_state
|
||||
.repl_buffer_state
|
||||
.lock()
|
||||
.expect("repl buffer state mutex");
|
||||
*repl_buffer = s.to_string();
|
||||
drop(repl_buffer);
|
||||
let mut repl = engine_state.repl_state.lock().expect("repl state mutex");
|
||||
repl.buffer = s.to_string();
|
||||
drop(repl);
|
||||
|
||||
if let Err(err) = eval_hook(engine_state, stack, None, vec![], &hook) {
|
||||
report_error_new(engine_state, &err);
|
||||
}
|
||||
}
|
||||
|
||||
let mut repl_cursor = engine_state
|
||||
.repl_cursor_pos
|
||||
.lock()
|
||||
.expect("repl cursor pos mutex");
|
||||
*repl_cursor = line_editor.current_insertion_point();
|
||||
drop(repl_cursor);
|
||||
let mut repl_buffer = engine_state
|
||||
.repl_buffer_state
|
||||
.lock()
|
||||
.expect("repl buffer state mutex");
|
||||
*repl_buffer = line_editor.current_buffer_contents().to_string();
|
||||
drop(repl_buffer);
|
||||
let mut repl = engine_state.repl_state.lock().expect("repl state mutex");
|
||||
repl.cursor_pos = line_editor.current_insertion_point();
|
||||
repl.buffer = line_editor.current_buffer_contents().to_string();
|
||||
drop(repl);
|
||||
|
||||
if shell_integration {
|
||||
run_ansi_sequence(PRE_EXECUTE_MARKER)?;
|
||||
@ -685,23 +674,15 @@ pub fn evaluate_repl(
|
||||
run_ansi_sequence(RESET_APPLICATION_MODE)?;
|
||||
}
|
||||
|
||||
let mut repl_buffer = engine_state
|
||||
.repl_buffer_state
|
||||
.lock()
|
||||
.expect("repl buffer state mutex");
|
||||
let mut repl_cursor_pos = engine_state
|
||||
.repl_cursor_pos
|
||||
.lock()
|
||||
.expect("repl cursor pos mutex");
|
||||
let mut repl = engine_state.repl_state.lock().expect("repl state mutex");
|
||||
line_editor.run_edit_commands(&[
|
||||
EditCommand::Clear,
|
||||
EditCommand::InsertString(repl_buffer.to_string()),
|
||||
EditCommand::MoveToPosition(*repl_cursor_pos),
|
||||
EditCommand::InsertString(repl.buffer.to_string()),
|
||||
EditCommand::MoveToPosition(repl.cursor_pos),
|
||||
]);
|
||||
*repl_buffer = "".to_string();
|
||||
drop(repl_buffer);
|
||||
*repl_cursor_pos = 0;
|
||||
drop(repl_cursor_pos);
|
||||
repl.buffer = "".to_string();
|
||||
repl.cursor_pos = 0;
|
||||
drop(repl);
|
||||
}
|
||||
Ok(Signal::CtrlC) => {
|
||||
// `Reedline` clears the line content. New prompt is shown
|
||||
|
Reference in New Issue
Block a user