From 74388d4bf44cdfebc0d6dc8e5faa81bffe71ddd6 Mon Sep 17 00:00:00 2001 From: mo8it Date: Mon, 26 Aug 2024 04:41:26 +0200 Subject: [PATCH] Only trigger write when needed --- src/term.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/term.rs b/src/term.rs index 51fcad1..fa71ac6 100644 --- a/src/term.rs +++ b/src/term.rs @@ -47,8 +47,10 @@ pub trait CountedWrite<'a> { impl<'a, 'b> CountedWrite<'b> for MaxLenWriter<'a, 'b> { fn write_ascii(&mut self, ascii: &[u8]) -> io::Result<()> { let n = ascii.len().min(self.max_len.saturating_sub(self.len)); - self.stdout.write_all(&ascii[..n])?; - self.len += n; + if n > 0 { + self.stdout.write_all(&ascii[..n])?; + self.len += n; + } Ok(()) }