Skip to content

Commit

Permalink
Tidy up console output
Browse files Browse the repository at this point in the history
  • Loading branch information
simoncozens committed May 17, 2024
1 parent ac03b00 commit cdd37f7
Showing 1 changed file with 22 additions and 5 deletions.
27 changes: 22 additions & 5 deletions src/bin/diffenator3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,10 @@ fn die(doing: &str, err: impl Error) -> ! {
fn show_map_diff(fields: &Map<String, serde_json::Value>, 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()) {
Expand Down Expand Up @@ -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()) {
Expand All @@ -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);
}
}
}
Expand All @@ -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()
);
Expand Down

0 comments on commit cdd37f7

Please sign in to comment.