refactor: Remove duplicated program info definitions in status mode
Co-authored-by: aider (openai/andrew.openrouter.qwen.qwen3-coder) <aider@aider.chat>
This commit is contained in:
@@ -37,6 +37,7 @@ pub trait MetaPlugin {
|
|||||||
fn is_supported(&self) -> bool {
|
fn is_supported(&self) -> bool {
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
|
|
||||||
fn create(&self) -> Result<Box<dyn Write>>;
|
fn create(&self) -> Result<Box<dyn Write>>;
|
||||||
fn finalize(&mut self) -> io::Result<String>;
|
fn finalize(&mut self) -> io::Result<String>;
|
||||||
|
|
||||||
@@ -44,6 +45,11 @@ pub trait MetaPlugin {
|
|||||||
fn update(&mut self, data: &[u8]);
|
fn update(&mut self, data: &[u8]);
|
||||||
|
|
||||||
fn meta_name(&mut self) -> String;
|
fn meta_name(&mut self) -> String;
|
||||||
|
|
||||||
|
// Get program information for display in status
|
||||||
|
fn program_info(&self) -> Option<(&str, Vec<&str>)> {
|
||||||
|
None
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
use std::io::Write;
|
use std::io::Write;
|
||||||
|
|||||||
@@ -117,6 +117,14 @@ impl MetaPlugin for MetaPluginProgram {
|
|||||||
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>)> {
|
||||||
|
if self.supported {
|
||||||
|
Some((&self.program, self.args.iter().map(|s| s.as_str()).collect()))
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -147,29 +147,12 @@ fn build_meta_plugin_table(enabled_meta_plugins: &Vec<MetaPluginType>) -> Table
|
|||||||
},
|
},
|
||||||
// For program-based plugins, show program info
|
// For program-based plugins, show program info
|
||||||
_ => {
|
_ => {
|
||||||
// Get the program info by downcasting to MetaPluginProgram
|
// Get program info from the meta plugin itself
|
||||||
// This is a bit hacky but necessary to get the program info
|
if let Some((program, args)) = meta_plugin.program_info() {
|
||||||
let program_name = match meta_plugin_type {
|
(program.to_string(), args.join(" "))
|
||||||
MetaPluginType::FileMagic => "file".to_string(),
|
} else {
|
||||||
MetaPluginType::FileMime => "file".to_string(),
|
("<NOT FOUND>".to_string(), "".to_string())
|
||||||
MetaPluginType::FileEncoding => "file".to_string(),
|
}
|
||||||
MetaPluginType::LineCount => "wc".to_string(),
|
|
||||||
MetaPluginType::WordCount => "wc".to_string(),
|
|
||||||
MetaPluginType::DigestMd5 => "md5sum".to_string(),
|
|
||||||
_ => "".to_string(),
|
|
||||||
};
|
|
||||||
|
|
||||||
let args = match meta_plugin_type {
|
|
||||||
MetaPluginType::FileMagic => "-bE -",
|
|
||||||
MetaPluginType::FileMime => "-b --mime-type -",
|
|
||||||
MetaPluginType::FileEncoding => "-b --mime-encoding -",
|
|
||||||
MetaPluginType::LineCount => "-l",
|
|
||||||
MetaPluginType::WordCount => "-w",
|
|
||||||
MetaPluginType::DigestMd5 => "",
|
|
||||||
_ => "",
|
|
||||||
};
|
|
||||||
|
|
||||||
(program_name, args.to_string())
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user