radicle-term: Inline `termion::get_tty` for Unix

This commit is contained in:
Lorenz Leutgeb 2025-06-26 17:49:31 +02:00
parent ec47566cb0
commit ee8ffcc799
1 changed files with 10 additions and 2 deletions

View File

@ -133,11 +133,19 @@ impl Editor {
let stderr = unsafe { libc::dup(stderr) }; let stderr = unsafe { libc::dup(stderr) };
let stdin = if io::stdin().is_terminal() { let stdin = if io::stdin().is_terminal() {
process::Stdio::inherit() process::Stdio::inherit()
} else { } else if cfg!(unix) {
let tty = termion::get_tty()?;
// If standard input is not a terminal device, the editor won't work correctly. // 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. // In that case, we use the terminal device, eg. `/dev/tty` as standard input.
let tty = fs::OpenOptions::new()
.read(true)
.write(true)
.open("/dev/tty")?;
process::Stdio::from(tty) process::Stdio::from(tty)
} else {
return Err(io::Error::new(
io::ErrorKind::Unsupported,
format!("standard input is not a terminal, refusing to execute editor {cmd:?}"),
));
}; };
process::Command::new(program) process::Command::new(program)