Radish alpha
h
Radicle Heartwood Protocol & Stack
Radicle
Git (anonymous pull)
Log in to clone via SSH
term: Fix editor closing `stderr` stream
Alexis Sellier committed 3 years ago
commit 0c41de143317d34c6d71a0365e3c0bf7939d45d0
parent 94cd7658b1c08d8819ab836154e82d772979eb92
3 files changed +12 -1
modified Cargo.lock
@@ -2141,6 +2141,7 @@ dependencies = [
 "anyhow",
 "inquire",
 "is-terminal",
+
 "libc",
 "once_cell",
 "pretty_assertions",
 "tempfile",
modified 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 }
modified 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()?;