From e177d786f81190826fc222cbdd40a7e0bcd157fe Mon Sep 17 00:00:00 2001 From: Schneems Date: Wed, 14 Feb 2024 15:10:34 -0600 Subject: [PATCH] Fix double newline after streaming Check if the streaming command emitted two newlines before adding an extra newline for padding. This fixes the case where an extra newline was being added when it wasn't needed. --- libherokubuildpack/src/buildpack_output/mod.rs | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/libherokubuildpack/src/buildpack_output/mod.rs b/libherokubuildpack/src/buildpack_output/mod.rs index 8ad885e8..9ea7ee6b 100644 --- a/libherokubuildpack/src/buildpack_output/mod.rs +++ b/libherokubuildpack/src/buildpack_output/mod.rs @@ -510,18 +510,21 @@ where /// /// Once you're finished streaming to the output, calling this function /// finalizes the stream's output and transitions back to a [`state::Section`]. - pub fn finish(mut self) -> BuildpackOutput> { + pub fn finish(self) -> BuildpackOutput> { let duration = self.state.started.elapsed(); - writeln_now(&mut self.state.write, ""); - - BuildpackOutput { + let mut output = BuildpackOutput { started: self.started, state: state::Section { write: self.state.write.unwrap(), }, + }; + + if !output.state.write_mut().was_paragraph { + writeln_now(&mut output.state.write, ""); } - .step(format!( + + output.step(format!( "Done {}", style::details(duration_format::human(&duration)) )) @@ -701,7 +704,6 @@ mod test { {tab_char} baz - - Done (< 0.1s) - Done (finished in < 0.1s) "};