From 8036acb8c95dda56d7da346359712c61b17ef6c0 Mon Sep 17 00:00:00 2001 From: Horasal Date: Fri, 8 Sep 2023 09:38:15 +0900 Subject: [PATCH] Pass `Command` to `reedline` use one temp file per instance Pull in recent reedline Fix to `with_buffer_editor` https://github.com/nushell/reedline/pull/630 --- Cargo.lock | 8 ++++---- Cargo.toml | 2 +- crates/nu-cli/Cargo.toml | 1 + crates/nu-cli/src/repl.rs | 11 ++++++++++- 4 files changed, 16 insertions(+), 6 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index dc0ed244725d..92fee234b57c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2746,6 +2746,7 @@ dependencies = [ "rstest", "sysinfo", "unicode-segmentation", + "uuid", ] [[package]] @@ -4291,8 +4292,7 @@ dependencies = [ [[package]] name = "reedline" version = "0.24.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "971ac45071721aae18927f3feb7e4c2b95cce387d96af185c5103166d332e55c" +source = "git+https://github.com/nushell/reedline.git?branch=main#b1344f6a653b7c37154a1dd79b3c4e34afe6cfc9" dependencies = [ "chrono", "crossterm 0.27.0", @@ -5705,9 +5705,9 @@ checksum = "37db35583cf0ad896592892034f281ef0906c893b3b6d901acf3918357f28199" [[package]] name = "uuid" -version = "1.4.0" +version = "1.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d023da39d1fde5a8a3fe1f3e01ca9632ada0a63e9797de55a879d6e2236277be" +checksum = "79daa5ed5740825c40b389c5e50312b9c86df53fccd33f281df655642b43869d" dependencies = [ "getrandom", ] diff --git a/Cargo.toml b/Cargo.toml index d823a1b2edd8..759ed1c0cb26 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -164,7 +164,7 @@ bench = false # To use a development version of a dependency please use a global override here # changing versions in each sub-crate of the workspace is tedious [patch.crates-io] -# reedline = { git = "https://github.com/nushell/reedline.git", branch = "main"} +reedline = { git = "https://github.com/nushell/reedline.git", branch = "main"} # nu-ansi-term = {git = "https://github.com/nushell/nu-ansi-term.git", branch = "main"} # Criterion benchmarking setup diff --git a/crates/nu-cli/Cargo.toml b/crates/nu-cli/Cargo.toml index 447a18b01c3d..4b1df657f543 100644 --- a/crates/nu-cli/Cargo.toml +++ b/crates/nu-cli/Cargo.toml @@ -38,6 +38,7 @@ once_cell = "1.18" percent-encoding = "2" sysinfo = "0.29" unicode-segmentation = "1.10" +uuid = { version = "1.4.1", features = ["v4"] } [features] plugin = [] diff --git a/crates/nu-cli/src/repl.rs b/crates/nu-cli/src/repl.rs index 908f589ddd99..87c08b78b0e1 100644 --- a/crates/nu-cli/src/repl.rs +++ b/crates/nu-cli/src/repl.rs @@ -26,6 +26,7 @@ use reedline::{ SqliteBackedHistory, Vi, }; use std::{ + env::temp_dir, io::{self, IsTerminal, Write}, path::Path, sync::atomic::Ordering, @@ -94,6 +95,7 @@ pub fn evaluate_repl( let mut start_time = std::time::Instant::now(); let mut line_editor = Reedline::create(); + let temp_file = temp_dir().join(format!("{}.nu", uuid::Uuid::new_v4())); // Now that reedline is created, get the history session id and store it in engine_state store_history_id_in_engine(engine_state, &line_editor); @@ -338,7 +340,14 @@ pub fn evaluate_repl( }; line_editor = if let Some(buffer_editor) = buffer_editor { - line_editor.with_buffer_editor(buffer_editor, "nu".into()) + let mut command = std::process::Command::new(&buffer_editor); + command.arg(&temp_file).envs( + engine_state + .render_env_vars() + .into_iter() + .filter_map(|(k, v)| v.as_string().ok().map(|v| (k, v))), + ); + line_editor.with_buffer_editor(command, temp_file.clone()) } else { line_editor };