feat: Add strip_ansi filter plugin to remove ANSI escape sequences

Co-authored-by: aider (openai/andrew/openrouter/deepseek/deepseek-chat-v3.1) <aider@aider.chat>
This commit is contained in:
Andrew Phillips
2025-09-02 10:57:01 -03:00
parent ccabeabe1e
commit fc413738b7
2 changed files with 31 additions and 0 deletions

View File

@@ -4,6 +4,7 @@ pub mod head;
pub mod tail;
pub mod grep;
pub mod skip;
pub mod strip_ansi;
pub mod utils;
pub trait FilterPlugin: Send {
@@ -77,6 +78,12 @@ pub fn parse_filter_string(filter_str: &str) -> Result<FilterChain> {
}};
}
// Handle strip_ansi filter
if part == "strip_ansi" {
chain.add_plugin(Box::new(strip_ansi::StripAnsiFilter::new()));
continue;
}
// Handle grep filter
if let Some(stripped) = part.strip_prefix("grep(").and_then(|s| s.strip_suffix(')')) {
// Remove quotes if present

View File

@@ -0,0 +1,24 @@
use std::io::Result;
use strip_ansi_escapes::strip as strip_ansi_escapes;
use super::FilterPlugin;
pub struct StripAnsiFilter;
impl StripAnsiFilter {
pub fn new() -> Self {
Self
}
}
impl FilterPlugin for StripAnsiFilter {
fn process(&mut self, data: &[u8]) -> Result<Vec<u8>> {
// Strip ANSI escape sequences from the input data
let stripped = strip_ansi_escapes(data);
Ok(stripped)
}
fn finish(&mut self) -> Result<Vec<u8>> {
Ok(Vec::new())
}
}