From 4dce39e96b888a11396c1ad95e3c8a32d54c7ef9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=A1s=20Ortega=20Froysa?= Date: Thu, 2 Oct 2025 09:59:37 +0200 Subject: [PATCH] Only newline with comma if last_ch == ] or } --- src/worker.rs | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/worker.rs b/src/worker.rs index 9de83bb..6dd1d5a 100644 --- a/src/worker.rs +++ b/src/worker.rs @@ -83,11 +83,16 @@ pub fn work(in_path:Option<&str>, out_path:Option<&str>) -> Result<(), String> last_ch = ch; }, ',' => { - out_writer.write(format!("{}\n", ch).as_bytes()).unwrap(); - for _ in 0..tab_num { - out_writer.write(b" ").unwrap(); + out_writer.write(format!("{}", ch).as_bytes()).unwrap(); + if last_ch == '}' || last_ch == ']' { + out_writer.write(b"\n").unwrap(); + for _ in 0..tab_num { + out_writer.write(b" ").unwrap(); + } + last_ch = ' '; + } else { + last_ch = ch; } - last_ch = ' '; }, _ => { if ch != ' ' || last_ch != ' ' {