From 2773855cec2d6beb622f68a354d6e68718a2d3c2 Mon Sep 17 00:00:00 2001 From: Andrew Phillips Date: Tue, 2 Sep 2025 11:58:22 -0300 Subject: [PATCH] refactor: Use io::copy to simplify StripAnsiFilter Co-authored-by: aider (openai/andrew/openrouter/deepseek/deepseek-chat-v3.1) --- src/filter_plugin/strip_ansi.rs | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/src/filter_plugin/strip_ansi.rs b/src/filter_plugin/strip_ansi.rs index 14dc113..500f577 100644 --- a/src/filter_plugin/strip_ansi.rs +++ b/src/filter_plugin/strip_ansi.rs @@ -1,7 +1,5 @@ use std::io::{Result, Read, Write}; use strip_ansi_escapes::Writer; -use crate::common::PIPESIZE; - use super::FilterPlugin; pub struct StripAnsiFilter; @@ -14,16 +12,8 @@ impl StripAnsiFilter { impl FilterPlugin for StripAnsiFilter { fn filter(&mut self, reader: &mut R, writer: &mut W) -> Result<()> { - let mut buffer = vec![0; PIPESIZE]; let mut ansi_writer = Writer::new(writer); - - loop { - let bytes_read = reader.read(&mut buffer)?; - if bytes_read == 0 { - break; - } - ansi_writer.write_all(&buffer[..bytes_read])?; - } + std::io::copy(reader, &mut ansi_writer)?; ansi_writer.flush()?; Ok(()) }