diff --git a/src/afterfact.rs b/src/afterfact.rs index 3e4c2f15..c66fa36a 100644 --- a/src/afterfact.rs +++ b/src/afterfact.rs @@ -654,17 +654,22 @@ fn _print_detection_summary_tables( sorted_detections.sort_by(|a, b| (-a.1).cmp(&(-b.1))); - for x in sorted_detections.iter().take(5) { + let take_cnt = if LEVEL_FULL.get(level.as_str()).unwrap_or(&"-".to_string()) == "critical" { + 10 + } else { + 5 + }; + for x in sorted_detections.iter().take(take_cnt) { col_output.push(format!( "{} ({})", x.0, x.1.to_formatted_string(&Locale::en) )); } - let na_cnt = if sorted_detections.len() > 5 { + let na_cnt = if sorted_detections.len() > take_cnt { 0 } else { - 5 - sorted_detections.len() + take_cnt - sorted_detections.len() }; for _x in 0..na_cnt { col_output.push("N/A".to_string()); @@ -675,28 +680,42 @@ fn _print_detection_summary_tables( let mut tb = Table::new(); tb.load_preset(UTF8_FULL) .apply_modifier(UTF8_ROUND_CORNERS) - .set_content_arrangement(ContentArrangement::Dynamic) - .set_width(500); - for x in 0..2 { - tb.add_row(vec![ - Cell::new(&output[2 * x][0]).fg(col_color[2 * x].unwrap_or(comfy_table::Color::Reset)), - Cell::new(&output[2 * x + 1][0]) - .fg(col_color[2 * x + 1].unwrap_or(comfy_table::Color::Reset)), - ]); + .set_style(TableComponent::VerticalLines, ' '); + for x in 0..3 { + if x == 0 { + let hlch = tb.style(TableComponent::HorizontalLines).unwrap(); + let tbch = tb.style(TableComponent::TopBorder).unwrap(); + tb.add_row(vec![ + Cell::new(&output[0][0]).fg(col_color[0].unwrap_or(comfy_table::Color::Reset)), + Cell::new(""), + ]) + .set_style(TableComponent::MiddleIntersections, hlch) + .set_style(TableComponent::TopBorderIntersections, tbch) + .set_style(TableComponent::BottomBorderIntersections, hlch); - tb.add_row(vec![ - Cell::new(&output[2 * x][1..].join("\n")) - .fg(col_color[2 * x].unwrap_or(comfy_table::Color::Reset)), - Cell::new(&output[2 * x + 1][1..].join("\n")) - .fg(col_color[2 * x + 1].unwrap_or(comfy_table::Color::Reset)), - ]); + let odd_row = &mut output[0].iter().skip(1).step_by(2); + let even_row = &mut output[0].iter().step_by(2).skip(1); + tb.add_row(vec![ + Cell::new(odd_row.join("\n")).fg(col_color[0].unwrap_or(comfy_table::Color::Reset)), + Cell::new(even_row.join("\n")) + .fg(col_color[0].unwrap_or(comfy_table::Color::Reset)), + ]); + } else { + tb.add_row(vec![ + Cell::new(&output[2 * x - 1][0]) + .fg(col_color[2 * x - 1].unwrap_or(comfy_table::Color::Reset)), + Cell::new(&output[2 * x][0]) + .fg(col_color[2 * x].unwrap_or(comfy_table::Color::Reset)), + ]); + + tb.add_row(vec![ + Cell::new(&output[2 * x - 1][1..].join("\n")) + .fg(col_color[2 * x - 1].unwrap_or(comfy_table::Color::Reset)), + Cell::new(&output[2 * x][1..].join("\n")) + .fg(col_color[2 * x].unwrap_or(comfy_table::Color::Reset)), + ]); + } } - tb.add_row(vec![ - Cell::new(&output[4][0]).fg(col_color[4].unwrap_or(comfy_table::Color::Reset)) - ]); - tb.add_row(vec![ - Cell::new(&output[4][1..].join("\n")).fg(col_color[4].unwrap_or(comfy_table::Color::Reset)) - ]); println!("{tb}"); }