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:
@@ -4,6 +4,7 @@ pub mod head;
|
|||||||
pub mod tail;
|
pub mod tail;
|
||||||
pub mod grep;
|
pub mod grep;
|
||||||
pub mod skip;
|
pub mod skip;
|
||||||
|
pub mod strip_ansi;
|
||||||
pub mod utils;
|
pub mod utils;
|
||||||
|
|
||||||
pub trait FilterPlugin: Send {
|
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
|
// Handle grep filter
|
||||||
if let Some(stripped) = part.strip_prefix("grep(").and_then(|s| s.strip_suffix(')')) {
|
if let Some(stripped) = part.strip_prefix("grep(").and_then(|s| s.strip_suffix(')')) {
|
||||||
// Remove quotes if present
|
// Remove quotes if present
|
||||||
|
|||||||
@@ -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())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user