From cdd37f7f09778800a910454c78a8ebf8e7aee5b5 Mon Sep 17 00:00:00 2001 From: Simon Cozens Date: Fri, 17 May 2024 13:22:17 +0100 Subject: [PATCH] Tidy up console output --- src/bin/diffenator3.rs | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/src/bin/diffenator3.rs b/src/bin/diffenator3.rs index dd19d42..dbf7ccd 100644 --- a/src/bin/diffenator3.rs +++ b/src/bin/diffenator3.rs @@ -85,6 +85,10 @@ fn die(doing: &str, err: impl Error) -> ! { fn show_map_diff(fields: &Map, indent: usize, succinct: bool) { for (field, diff) in fields.iter() { print!("{}", " ".repeat(indent * 2)); + if field == "error" { + println!("{}", diff.as_str().unwrap().red()); + continue; + } if let Some(lr) = diff.as_array() { let (left, right) = (&lr[0], &lr[1]); if succinct && (left.is_something() && !right.is_something()) { @@ -158,7 +162,9 @@ fn main() { if diff.contains_key("tables") { for (table_name, diff) in diff["tables"].as_object().unwrap().iter() { - println!("\n# {}", table_name); + if diff.is_something() { + println!("\n# {}", table_name); + } if let Some(lr) = diff.as_array() { let (left, right) = (&lr[0], &lr[1]); if cli.succinct && (left.is_something() && !right.is_something()) { @@ -171,28 +177,39 @@ fn main() { } } else if let Some(fields) = diff.as_object() { show_map_diff(fields, 0, cli.succinct); + } else { + println!("Unexpected diff format: {}", diff); } } } if diff.contains_key("glyphs") { println!("\n# Glyphs"); + let display_glyph = |glyph: &serde_json::Value| { + println!( + " - {} ({}: {}) {:.3}%", + glyph["string"].as_str().unwrap(), + glyph["unicode"].as_str().unwrap(), + glyph["name"].as_str().unwrap(), + glyph["percent"].as_f64().unwrap() + ); + }; let map = diff["glyphs"].as_object().unwrap(); if map["missing"].is_something() { println!("\nMissing glyphs:"); for glyph in map["missing"].as_array().unwrap() { - println!(" {}", glyph); + display_glyph(glyph); } } if map["new"].is_something() { println!("\nNew glyphs:"); for glyph in map["new"].as_array().unwrap() { - println!(" {}", glyph); + display_glyph(glyph); } } if map["modified"].is_something() { println!("\nModified glyphs:"); for glyph in map["modified"].as_array().unwrap() { - println!(" {}", glyph); + display_glyph(glyph); } } } @@ -203,7 +220,7 @@ fn main() { println!("\n## {}", script); for difference in script_diff.as_array().unwrap().iter() { println!( - " - {} ({}%)", + " - {} ({:.3}%)", difference["word"].as_str().unwrap(), difference["percent"].as_f64().unwrap() );