Make box-drawing code more reusable

- Move it to 'pretty' module.
  - Have function work on colored strings titles and contents
This commit is contained in:
KtorZ
2022-12-20 15:15:11 +01:00
committed by Lucas
parent f26737ecb4
commit 2fc14c7c1f
5 changed files with 139 additions and 31 deletions

View File

@@ -125,28 +125,24 @@ impl telemetry::EventListener for Terminal {
let (max_mem, max_cpu) = find_max_execution_units(&tests);
for (module, infos) in &group_by_module(&tests) {
let first = fmt_test(infos.first().unwrap(), max_mem, max_cpu, false).len();
let title = module.bold().blue().to_string();
let tests = infos
.iter()
.map(|eval_info| fmt_test(eval_info, max_mem, max_cpu, true))
.collect::<Vec<String>>()
.join("\n");
let summary = fmt_test_summary(infos, true);
println!(
"{} {} {}",
" ┌──".bright_black(),
module.bold().blue(),
pretty::pad_left("".to_string(), first - module.len() - 3, "")
.bright_black()
);
for eval_info in infos {
println!(
" {} {}",
"".bright_black(),
fmt_test(eval_info, max_mem, max_cpu, true)
"{}\n",
pretty::indent(
&pretty::open_box(&title, &tests, &summary, |border| border
.bright_black()
.to_string()),
4
)
}
let last = fmt_test(infos.last().unwrap(), max_mem, max_cpu, false).len();
let summary = fmt_test_summary(infos, false).len();
println!(
"{} {}\n",
pretty::pad_right("".to_string(), last - summary + 5, "")
.bright_black(),
fmt_test_summary(infos, true),
);
}
}