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:
@@ -33,6 +33,7 @@ pub enum MetaPluginType {
|
|||||||
ReadRate,
|
ReadRate,
|
||||||
Hostname,
|
Hostname,
|
||||||
FullHostname,
|
FullHostname,
|
||||||
|
Tty,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait MetaPlugin {
|
pub trait MetaPlugin {
|
||||||
@@ -75,6 +76,7 @@ pub fn get_meta_plugin(meta_plugin_type: MetaPluginType) -> Box<dyn MetaPlugin>
|
|||||||
MetaPluginType::ReadRate => Box::new(ReadRateMetaPlugin::new()),
|
MetaPluginType::ReadRate => Box::new(ReadRateMetaPlugin::new()),
|
||||||
MetaPluginType::Hostname => Box::new(HostnameMetaPlugin::new()),
|
MetaPluginType::Hostname => Box::new(HostnameMetaPlugin::new()),
|
||||||
MetaPluginType::FullHostname => Box::new(FullHostnameMetaPlugin::new()),
|
MetaPluginType::FullHostname => Box::new(FullHostnameMetaPlugin::new()),
|
||||||
|
MetaPluginType::Tty => Box::new(TtyMetaPlugin::new()),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -358,3 +358,45 @@ impl MetaPlugin for FullHostnameMetaPlugin {
|
|||||||
self.meta_name.clone()
|
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