fix: use tty command instead of reading /dev/tty link for TTY meta plugin

Co-authored-by: aider (openai/andrew.openrouter.qwen.qwen3-coder) <aider@aider.chat>
This commit is contained in:
Andrew Phillips
2025-07-29 14:40:00 -03:00
parent 8a2468522a
commit f20cecbcc7

View File

@@ -373,6 +373,16 @@ impl TtyMetaPlugin {
} }
impl MetaPlugin for TtyMetaPlugin { impl MetaPlugin for TtyMetaPlugin {
fn is_supported(&self) -> bool {
// Check if the 'tty' command is available
std::process::Command::new("sh")
.arg("-c")
.arg("command -v tty")
.output()
.map(|output| output.status.success())
.unwrap_or(false)
}
fn create(&self) -> Result<Box<dyn Write>> { fn create(&self) -> Result<Box<dyn Write>> {
Ok(Box::new(io::sink())) Ok(Box::new(io::sink()))
} }
@@ -385,9 +395,21 @@ impl MetaPlugin for TtyMetaPlugin {
} }
} }
// Try to get TTY from /dev/tty (this will give us the current terminal) // Use the tty command to get the current terminal
match std::fs::read_link("/dev/tty") { match std::process::Command::new("tty").output() {
Ok(path) => Ok(format!("/dev/{}", path.to_string_lossy())), Ok(output) => {
if output.status.success() {
let tty_path = String::from_utf8_lossy(&output.stdout);
let trimmed = tty_path.trim();
if trimmed.is_empty() || trimmed == "not a tty" {
Ok("not a tty".to_string())
} else {
Ok(trimmed.to_string())
}
} else {
Ok("not a tty".to_string())
}
}
Err(_) => Ok("not a tty".to_string()), Err(_) => Ok("not a tty".to_string()),
} }
} }
@@ -399,4 +421,8 @@ impl MetaPlugin for TtyMetaPlugin {
fn meta_name(&mut self) -> String { fn meta_name(&mut self) -> String {
self.meta_name.clone() self.meta_name.clone()
} }
fn program_info(&self) -> Option<(&str, Vec<&str>)> {
Some(("tty", vec![]))
}
} }