Skip to content

Commit

Permalink
Merge pull request #2 from schneems/schneems/fix-header-newlines
Browse files Browse the repository at this point in the history
Fix duplicate header newlines
  • Loading branch information
schneems authored Jun 3, 2024
2 parents 4e3c407 + 3917260 commit ee2706d
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 4 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## Unreleased

## v0.1.1 - 2024/06/03

- Fix double newlines for headers (https://github.com/schneems/bullet_stream/pull/2)

## v0.1.0 - 2024/06/03

- First
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "bullet_stream"
version = "0.1.0"
version = "0.1.1"
edition = "2021"
license = "MIT"
description = "Bulletproof printing for bullet point text"
Expand Down
54 changes: 52 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -384,11 +384,15 @@ where
/// This function will transition your buildpack output to [`state::Bullet`].
#[must_use]
pub fn h2(mut self, buildpack_name: impl AsRef<str>) -> Output<state::Bullet<W>> {
if !self.state.write.was_paragraph {
writeln_now(&mut self.state.write, "");
}

writeln_now(
&mut self.state.write,
ansi_escape::wrap_ansi_escape_each_line(
&ANSI::BoldPurple,
format!("\n## {}\n", buildpack_name.as_ref().trim()),
format!("## {}\n", buildpack_name.as_ref().trim()),
),
);

Expand Down Expand Up @@ -443,11 +447,15 @@ where
/// Outputs an H2 header
#[must_use]
pub fn h2(mut self, buildpack_name: impl AsRef<str>) -> Output<state::Bullet<W>> {
if !self.state.write.was_paragraph {
writeln_now(&mut self.state.write, "");
}

writeln_now(
&mut self.state.write,
ansi_escape::wrap_ansi_escape_each_line(
&ANSI::BoldPurple,
format!("\n## {}\n", buildpack_name.as_ref().trim()),
format!("## {}\n", buildpack_name.as_ref().trim()),
),
);

Expand Down Expand Up @@ -769,6 +777,48 @@ mod test {
use libcnb_test::assert_contains;
use std::fs::File;

#[test]
fn double_h2_h2_newlines() {
let writer = Vec::new();
let output = Output::new(writer).h2("Header 2").h2("Header 2");

let io = output.done();
let expected = formatdoc! {"
## Header 2
## Header 2
- Done (finished in < 0.1s)
"};

assert_eq!(
expected,
strip_ansi_escape_sequences(String::from_utf8_lossy(&io))
)
}

#[test]
fn double_h1_h2_newlines() {
let writer = Vec::new();
let output = Output::new(writer).h1("Header 1").h2("Header 2");

let io = output.done();
let expected = formatdoc! {"
# Header 1
## Header 2
- Done (finished in < 0.1s)
"};

assert_eq!(
expected,
strip_ansi_escape_sequences(String::from_utf8_lossy(&io))
)
}

#[test]
fn stream_with() {
let writer = Vec::new();
Expand Down

0 comments on commit ee2706d

Please sign in to comment.