refactor: Use io::copy to simplify StripAnsiFilter
Co-authored-by: aider (openai/andrew/openrouter/deepseek/deepseek-chat-v3.1) <aider@aider.chat>
This commit is contained in:
@@ -1,7 +1,5 @@
|
|||||||
use std::io::{Result, Read, Write};
|
use std::io::{Result, Read, Write};
|
||||||
use strip_ansi_escapes::Writer;
|
use strip_ansi_escapes::Writer;
|
||||||
use crate::common::PIPESIZE;
|
|
||||||
|
|
||||||
use super::FilterPlugin;
|
use super::FilterPlugin;
|
||||||
|
|
||||||
pub struct StripAnsiFilter;
|
pub struct StripAnsiFilter;
|
||||||
@@ -14,16 +12,8 @@ impl StripAnsiFilter {
|
|||||||
|
|
||||||
impl FilterPlugin for StripAnsiFilter {
|
impl FilterPlugin for StripAnsiFilter {
|
||||||
fn filter<R: Read, W: Write>(&mut self, reader: &mut R, writer: &mut W) -> Result<()> {
|
fn filter<R: Read, W: Write>(&mut self, reader: &mut R, writer: &mut W) -> Result<()> {
|
||||||
let mut buffer = vec![0; PIPESIZE];
|
|
||||||
let mut ansi_writer = Writer::new(writer);
|
let mut ansi_writer = Writer::new(writer);
|
||||||
|
std::io::copy(reader, &mut ansi_writer)?;
|
||||||
loop {
|
|
||||||
let bytes_read = reader.read(&mut buffer)?;
|
|
||||||
if bytes_read == 0 {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
ansi_writer.write_all(&buffer[..bytes_read])?;
|
|
||||||
}
|
|
||||||
ansi_writer.flush()?;
|
ansi_writer.flush()?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user