Skip to content

Commit

Permalink
Pass Command to reedline
Browse files Browse the repository at this point in the history
use one temp file per instance
Pull in recent reedline

Fix to `with_buffer_editor`

nushell/reedline#630
  • Loading branch information
Horasal authored and sholderbach committed Sep 28, 2023
1 parent 546fffe commit 8036acb
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 6 deletions.
8 changes: 4 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions crates/nu-cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 = []
11 changes: 10 additions & 1 deletion crates/nu-cli/src/repl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ use reedline::{
SqliteBackedHistory, Vi,
};
use std::{
env::temp_dir,
io::{self, IsTerminal, Write},
path::Path,
sync::atomic::Ordering,
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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
};
Expand Down

0 comments on commit 8036acb

Please sign in to comment.