diff --git a/Cargo.lock b/Cargo.lock index 40d12d31..0fcd052b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2141,6 +2141,7 @@ dependencies = [ "anyhow", "inquire", "is-terminal", + "libc", "once_cell", "pretty_assertions", "tempfile", diff --git a/radicle-term/Cargo.toml b/radicle-term/Cargo.toml index 5f10a981..9bf6f519 100644 --- a/radicle-term/Cargo.toml +++ b/radicle-term/Cargo.toml @@ -10,6 +10,7 @@ anyhow = { version = "1" } anstyle-query = { version = "1.0.0" } is-terminal = { version = "0.4.4" } inquire = { version = "0.6", default-features = false, features = ["termion", "editor"] } +libc = { version = "0.2" } once_cell = { version = "1.13" } termion = { version = "2" } unicode-width = { version = "0.1.10", default-features = false } diff --git a/radicle-term/src/editor.rs b/radicle-term/src/editor.rs index 1ee79c08..4e6e86b5 100644 --- a/radicle-term/src/editor.rs +++ b/radicle-term/src/editor.rs @@ -67,8 +67,17 @@ impl Editor { ) ); }; + + // We duplicate the stderr file descriptor to pass it to the child process, otherwise, if + // we simply pass the `RawFd` of our stderr, `Command` will close our stderr when the + // child exits. + let stderr = io::stderr().as_raw_fd(); + let stderr = unsafe { libc::dup(stderr) }; + process::Command::new(cmd) - .stdout(unsafe { process::Stdio::from_raw_fd(io::stderr().as_raw_fd()) }) + .stdout(unsafe { process::Stdio::from_raw_fd(stderr) }) + .stderr(process::Stdio::inherit()) + .stdin(process::Stdio::inherit()) .arg(&self.path) .spawn()? .wait()?;