feat: add tty meta plugin to get current terminal device
Co-authored-by: aider (openai/andrew.openrouter.qwen.qwen3-coder) <aider@aider.chat>
This commit is contained in:
@@ -358,3 +358,45 @@ impl MetaPlugin for FullHostnameMetaPlugin {
|
||||
self.meta_name.clone()
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Default)]
|
||||
pub struct TtyMetaPlugin {
|
||||
meta_name: String,
|
||||
}
|
||||
|
||||
impl TtyMetaPlugin {
|
||||
pub fn new() -> TtyMetaPlugin {
|
||||
TtyMetaPlugin {
|
||||
meta_name: "tty".to_string(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl MetaPlugin for TtyMetaPlugin {
|
||||
fn create(&self) -> Result<Box<dyn Write>> {
|
||||
Ok(Box::new(io::sink()))
|
||||
}
|
||||
|
||||
fn finalize(&mut self) -> io::Result<String> {
|
||||
// Try to get the TTY from the TTY environment variable first
|
||||
if let Ok(tty) = env::var("TTY") {
|
||||
if !tty.is_empty() {
|
||||
return Ok(tty);
|
||||
}
|
||||
}
|
||||
|
||||
// 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())),
|
||||
Err(_) => Ok("not a tty".to_string()),
|
||||
}
|
||||
}
|
||||
|
||||
fn update(&mut self, _data: &[u8]) {
|
||||
// No update needed for TTY
|
||||
}
|
||||
|
||||
fn meta_name(&mut self) -> String {
|
||||
self.meta_name.clone()
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user