From 802d776f2959e8c4eb72ce78fc1a99b7e7a8be60 Mon Sep 17 00:00:00 2001 From: Joscha Date: Tue, 22 Nov 2022 23:13:08 +0100 Subject: [PATCH] Include trailing newline in pretty print output --- src/main.rs | 2 +- src/pretty.rs | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/main.rs b/src/main.rs index a40fedc..0ac0aed 100644 --- a/src/main.rs +++ b/src/main.rs @@ -80,7 +80,7 @@ fn main() -> anyhow::Result<()> { .parse(stream) .map_err(|e| anyhow!("{e:?}"))?; - println!("{}", pretty::pretty_to_string(program, 100)); + print!("{}", pretty::pretty_to_string(program, 100)); } Command::Desugar { diff --git a/src/pretty.rs b/src/pretty.rs index cb1d34f..0c91c87 100644 --- a/src/pretty.rs +++ b/src/pretty.rs @@ -21,5 +21,7 @@ pub fn pretty_to_string>(p: P, width: usize) -> p.pretty(&RcAllocator) .render(width, &mut out) .expect("p could not be rendered"); - String::from_utf8(out).expect("p created non-utf8 string") + let mut s = String::from_utf8(out).expect("p created non-utf8 string"); + s.push('\n'); + s }