Radish alpha
h
Radicle Heartwood Protocol & Stack
Radicle
Git (anonymous pull)
Log in to clone via SSH
term: Ensure `Editor` gets a TTY
Alexis Sellier committed 2 years ago
commit 9418a20caef73bb0888a42c5462b4b19ed1af6cd
parent bb099faa4f6e6219f4cb61efbbe3ccd9011c4ae6
1 file changed +10 -1
modified radicle-term/src/editor.rs
@@ -1,4 +1,5 @@
use std::ffi::OsString;
+
use std::io::IsTerminal;
use std::io::Write;
use std::os::fd::{AsRawFd, FromRawFd};
use std::path::PathBuf;
@@ -73,11 +74,19 @@ impl Editor {
        // child exits.
        let stderr = io::stderr().as_raw_fd();
        let stderr = unsafe { libc::dup(stderr) };
+
        let stdin = if io::stdin().is_terminal() {
+
            process::Stdio::inherit()
+
        } else {
+
            let tty = termion::get_tty()?;
+
            // If standard input is not a terminal device, the editor won't work correctly.
+
            // In that case, we use the terminal device, eg. `/dev/tty` as standard input.
+
            process::Stdio::from(tty)
+
        };

        process::Command::new(cmd)
            .stdout(unsafe { process::Stdio::from_raw_fd(stderr) })
            .stderr(process::Stdio::inherit())
-
            .stdin(process::Stdio::inherit())
+
            .stdin(stdin)
            .arg(&self.path)
            .spawn()?
            .wait()?;