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:
@@ -373,6 +373,16 @@ impl 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>> {
|
||||
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)
|
||||
match std::fs::read_link("/dev/tty") {
|
||||
Ok(path) => Ok(format!("/dev/{}", path.to_string_lossy())),
|
||||
// Use the tty command to get the current terminal
|
||||
match std::process::Command::new("tty").output() {
|
||||
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()),
|
||||
}
|
||||
}
|
||||
@@ -399,4 +421,8 @@ impl MetaPlugin for TtyMetaPlugin {
|
||||
fn meta_name(&mut self) -> String {
|
||||
self.meta_name.clone()
|
||||
}
|
||||
|
||||
fn program_info(&self) -> Option<(&str, Vec<&str>)> {
|
||||
Some(("tty", vec![]))
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user