2026-11-19 09:29:21 -08:00
|
|
|
|
//! Text comparison reports and presentation roles shared with the terminal.
|
2026-11-19 08:44:28 -08:00
|
|
|
|
|
2026-11-19 09:29:21 -08:00
|
|
|
|
use super::{hierarchy::write_hierarchy, *};
|
2026-11-19 08:44:28 -08:00
|
|
|
|
use std::ops::Range;
|
|
|
|
|
|
|
2026-11-19 09:29:21 -08:00
|
|
|
|
/// Additional presentation options for a text comparison.
|
|
|
|
|
|
#[derive(Clone, Copy, Debug, Default)]
|
|
|
|
|
|
pub struct TextReportOptions {
|
|
|
|
|
|
/// Print individual object evidence, including both sides of replacements.
|
|
|
|
|
|
pub details: bool,
|
|
|
|
|
|
/// Append the ASCII hierarchy at this depth when provided.
|
|
|
|
|
|
pub ascii_depth: Option<usize>,
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-11-19 08:44:28 -08:00
|
|
|
|
/// A presentation role for a span of report text.
|
|
|
|
|
|
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
|
|
|
|
|
|
pub enum TextStyle {
|
|
|
|
|
|
Heading,
|
|
|
|
|
|
Layer,
|
|
|
|
|
|
Added,
|
|
|
|
|
|
Removed,
|
|
|
|
|
|
Changed,
|
|
|
|
|
|
Success,
|
|
|
|
|
|
Warning,
|
|
|
|
|
|
Error,
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
impl TextStyle {
|
|
|
|
|
|
pub(super) fn change(marker: char) -> Self {
|
|
|
|
|
|
match marker {
|
|
|
|
|
|
'+' => Self::Added,
|
|
|
|
|
|
'-' => Self::Removed,
|
|
|
|
|
|
_ => Self::Changed,
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// A plain text report with optional style spans.
|
|
|
|
|
|
#[derive(Default)]
|
|
|
|
|
|
pub struct TextReport {
|
|
|
|
|
|
text: String,
|
|
|
|
|
|
spans: Option<Vec<(Range<usize>, TextStyle)>>,
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
impl TextReport {
|
|
|
|
|
|
pub fn new(styled: bool) -> Self {
|
|
|
|
|
|
Self {
|
|
|
|
|
|
text: String::new(),
|
|
|
|
|
|
spans: styled.then(Vec::new),
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
pub fn as_str(&self) -> &str {
|
|
|
|
|
|
&self.text
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
pub fn into_string(self) -> String {
|
|
|
|
|
|
self.text
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// Byte ranges are in output order and never overlap.
|
|
|
|
|
|
pub fn styles(&self) -> &[(Range<usize>, TextStyle)] {
|
|
|
|
|
|
self.spans.as_deref().unwrap_or(&[])
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
pub(super) fn is_styled(&self) -> bool {
|
|
|
|
|
|
self.spans.is_some()
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
pub fn write_styled(&mut self, style: TextStyle, text: fmt::Arguments<'_>) {
|
|
|
|
|
|
let start = self.len();
|
|
|
|
|
|
self.write_fmt(text).unwrap();
|
|
|
|
|
|
self.mark(start, style);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
pub(super) fn push_str(&mut self, text: &str) {
|
|
|
|
|
|
self.text.push_str(text);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
pub(super) fn push(&mut self, ch: char) {
|
|
|
|
|
|
self.text.push(ch);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
pub(super) fn len(&self) -> usize {
|
|
|
|
|
|
self.text.len()
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
pub(super) fn mark(&mut self, start: usize, style: TextStyle) {
|
|
|
|
|
|
let end = self.text.len();
|
|
|
|
|
|
if start < end
|
|
|
|
|
|
&& let Some(spans) = &mut self.spans
|
|
|
|
|
|
{
|
|
|
|
|
|
if let Some((range, previous)) = spans.last_mut()
|
|
|
|
|
|
&& range.end == start
|
|
|
|
|
|
&& *previous == style
|
|
|
|
|
|
{
|
|
|
|
|
|
range.end = end;
|
|
|
|
|
|
} else {
|
|
|
|
|
|
spans.push((start..end, style));
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
impl fmt::Write for TextReport {
|
|
|
|
|
|
fn write_str(&mut self, text: &str) -> fmt::Result {
|
|
|
|
|
|
self.push_str(text);
|
|
|
|
|
|
Ok(())
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
enum Part {
|
|
|
|
|
|
Text(String),
|
|
|
|
|
|
Layer(Layer),
|
|
|
|
|
|
Placements(Option<(u64, u64)>),
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// Cell details awaiting inline layer labels and reference placement totals.
|
|
|
|
|
|
pub(super) struct CellText<'a> {
|
|
|
|
|
|
names: &'a BTreeMap<Layer, String>,
|
|
|
|
|
|
name_changes: &'a [LayerNameChange],
|
|
|
|
|
|
layers: BTreeMap<Layer, bool>,
|
|
|
|
|
|
parts: Vec<(Option<TextStyle>, Part)>,
|
|
|
|
|
|
styled: bool,
|
|
|
|
|
|
style: Option<TextStyle>,
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
impl<'a> CellText<'a> {
|
|
|
|
|
|
pub fn new(
|
|
|
|
|
|
names: &'a BTreeMap<Layer, String>,
|
|
|
|
|
|
name_changes: &'a [LayerNameChange],
|
|
|
|
|
|
styled: bool,
|
|
|
|
|
|
) -> Self {
|
|
|
|
|
|
Self {
|
|
|
|
|
|
names,
|
|
|
|
|
|
name_changes,
|
|
|
|
|
|
layers: BTreeMap::new(),
|
|
|
|
|
|
parts: Vec::new(),
|
|
|
|
|
|
styled,
|
|
|
|
|
|
style: None,
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
pub fn style(&mut self, style: Option<TextStyle>) {
|
|
|
|
|
|
self.style = style.filter(|_| self.styled);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
pub fn write_layer(&mut self, layer: Layer, side: Option<Side>) {
|
|
|
|
|
|
if self.names.contains_key(&layer) {
|
|
|
|
|
|
self.layers
|
|
|
|
|
|
.entry(layer)
|
|
|
|
|
|
.and_modify(|repeated| *repeated = true)
|
|
|
|
|
|
.or_insert(false);
|
|
|
|
|
|
self.parts.push((self.style, Part::Layer(layer)));
|
|
|
|
|
|
} else {
|
|
|
|
|
|
write!(self, "{}/{}", layer.0, layer.1).unwrap();
|
|
|
|
|
|
if let Some(name) = self.transition_name(layer, side) {
|
|
|
|
|
|
write!(self, " ({})", cell_label(name)).unwrap();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
pub fn reserve_placements(&mut self) -> usize {
|
|
|
|
|
|
let index = self.parts.len();
|
|
|
|
|
|
self.parts.push((self.style, Part::Placements(None)));
|
|
|
|
|
|
index
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
pub fn set_placements(&mut self, index: usize, old: u64, new: u64) {
|
|
|
|
|
|
self.parts[index].1 = Part::Placements(Some((old, new)));
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
pub fn push_str(&mut self, text: &str) {
|
|
|
|
|
|
self.write_str(text).unwrap();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
pub fn push(&mut self, ch: char) {
|
|
|
|
|
|
self.write_char(ch).unwrap();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
fn append(&mut self, text: &str) {
|
|
|
|
|
|
if text.is_empty() {
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
if let Some((style, Part::Text(current))) = self.parts.last_mut()
|
|
|
|
|
|
&& *style == self.style
|
|
|
|
|
|
{
|
|
|
|
|
|
current.push_str(text);
|
|
|
|
|
|
} else {
|
|
|
|
|
|
self.parts.push((self.style, Part::Text(text.to_string())));
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
fn transition_name(&self, layer: Layer, side: Option<Side>) -> Option<&'a str> {
|
|
|
|
|
|
let side = side?;
|
|
|
|
|
|
let at = self
|
|
|
|
|
|
.name_changes
|
|
|
|
|
|
.binary_search_by_key(&layer, |change| change.layer)
|
|
|
|
|
|
.ok()?;
|
|
|
|
|
|
let change = &self.name_changes[at];
|
|
|
|
|
|
match side {
|
|
|
|
|
|
Side::Old => change.old.as_deref(),
|
|
|
|
|
|
Side::New => change.new.as_deref(),
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
pub fn write_legend(&self, out: &mut TextReport) {
|
|
|
|
|
|
for (&(layer, datatype), &repeated) in &self.layers {
|
|
|
|
|
|
if repeated {
|
|
|
|
|
|
writeln!(
|
|
|
|
|
|
out,
|
|
|
|
|
|
"{layer}/{datatype}: name {:?}",
|
|
|
|
|
|
self.names[&(layer, datatype)]
|
|
|
|
|
|
)
|
|
|
|
|
|
.unwrap();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
pub fn write_body(self, out: &mut TextReport) {
|
|
|
|
|
|
for (style, part) in self.parts {
|
|
|
|
|
|
let start = out.len();
|
|
|
|
|
|
match part {
|
|
|
|
|
|
Part::Text(text) => out.push_str(&text),
|
|
|
|
|
|
Part::Layer((layer, datatype)) => {
|
|
|
|
|
|
write!(out, "{layer}/{datatype}").unwrap();
|
|
|
|
|
|
if !self.layers[&(layer, datatype)] {
|
|
|
|
|
|
write!(out, " ({})", cell_label(&self.names[&(layer, datatype)])).unwrap();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
Part::Placements(Some((old, new))) if old == new => {
|
|
|
|
|
|
let suffix = if new == 1 { "" } else { "s" };
|
|
|
|
|
|
write!(out, " · {new} total placement{suffix}").unwrap();
|
|
|
|
|
|
}
|
|
|
|
|
|
Part::Placements(Some((old, new))) => {
|
|
|
|
|
|
write!(out, " · placements {old} -> {new}").unwrap();
|
|
|
|
|
|
}
|
|
|
|
|
|
Part::Placements(None) => (),
|
|
|
|
|
|
}
|
|
|
|
|
|
if let Some(style) = style {
|
|
|
|
|
|
out.mark(start, style);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
impl fmt::Write for CellText<'_> {
|
|
|
|
|
|
fn write_str(&mut self, text: &str) -> fmt::Result {
|
|
|
|
|
|
if self.style.is_some()
|
|
|
|
|
|
&& let Some((first, rest)) = text.split_once('\n')
|
|
|
|
|
|
{
|
|
|
|
|
|
self.append(first);
|
|
|
|
|
|
self.style = None;
|
|
|
|
|
|
self.append("\n");
|
|
|
|
|
|
self.append(rest);
|
|
|
|
|
|
} else {
|
|
|
|
|
|
self.append(text);
|
|
|
|
|
|
}
|
|
|
|
|
|
Ok(())
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2026-11-19 09:29:21 -08:00
|
|
|
|
|
|
|
|
|
|
impl TextComparison {
|
|
|
|
|
|
pub fn render_text(
|
|
|
|
|
|
&self,
|
|
|
|
|
|
max_objects: usize,
|
|
|
|
|
|
show: &DisplayFilter,
|
|
|
|
|
|
show_library_presence: bool,
|
|
|
|
|
|
) -> String {
|
|
|
|
|
|
self.comparison
|
|
|
|
|
|
.render_text(max_objects, show, show_library_presence)
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
pub fn render_text_with_options(
|
|
|
|
|
|
&self,
|
|
|
|
|
|
max_objects: usize,
|
|
|
|
|
|
show: &DisplayFilter,
|
|
|
|
|
|
show_library_presence: bool,
|
|
|
|
|
|
options: TextReportOptions,
|
|
|
|
|
|
) -> String {
|
|
|
|
|
|
self.comparison
|
|
|
|
|
|
.render_text_with_options(max_objects, show, show_library_presence, options)
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
pub fn write_text_report(
|
|
|
|
|
|
&self,
|
|
|
|
|
|
out: &mut TextReport,
|
|
|
|
|
|
max_objects: usize,
|
|
|
|
|
|
show: &DisplayFilter,
|
|
|
|
|
|
show_library_presence: bool,
|
|
|
|
|
|
options: TextReportOptions,
|
|
|
|
|
|
) {
|
|
|
|
|
|
self.comparison
|
|
|
|
|
|
.write_text_report(out, max_objects, show, show_library_presence, options);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// Render the cell changes and their ASCII hierarchy together.
|
|
|
|
|
|
pub fn render_text_with_ascii_hierarchy(
|
|
|
|
|
|
&self,
|
|
|
|
|
|
max_objects: usize,
|
|
|
|
|
|
show: &DisplayFilter,
|
|
|
|
|
|
show_library_presence: bool,
|
|
|
|
|
|
max_depth: usize,
|
|
|
|
|
|
) -> String {
|
|
|
|
|
|
self.comparison.render_text_with_ascii_hierarchy(
|
|
|
|
|
|
max_objects,
|
|
|
|
|
|
show,
|
|
|
|
|
|
show_library_presence,
|
|
|
|
|
|
max_depth,
|
|
|
|
|
|
)
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
impl Comparison {
|
|
|
|
|
|
/// Limit presentation only: the complete comparison has already been made.
|
|
|
|
|
|
pub fn text(&self, max_objects: usize) -> String {
|
|
|
|
|
|
self.text_filtered(max_objects, &DisplayFilter::default())
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
pub fn text_filtered(&self, max_objects: usize, show: &DisplayFilter) -> String {
|
|
|
|
|
|
self.render_text(max_objects, show, true)
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// Render a text report. Set `show_library_presence` to false when a file
|
|
|
|
|
|
/// header already announces the library addition or deletion.
|
|
|
|
|
|
pub fn render_text(
|
|
|
|
|
|
&self,
|
|
|
|
|
|
max_objects: usize,
|
|
|
|
|
|
show: &DisplayFilter,
|
|
|
|
|
|
show_library_presence: bool,
|
|
|
|
|
|
) -> String {
|
|
|
|
|
|
self.render_text_with_options(
|
|
|
|
|
|
max_objects,
|
|
|
|
|
|
show,
|
|
|
|
|
|
show_library_presence,
|
|
|
|
|
|
TextReportOptions::default(),
|
|
|
|
|
|
)
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// Render the cell changes and omit simple hierarchy edges already shown there.
|
|
|
|
|
|
pub fn render_text_with_ascii_hierarchy(
|
|
|
|
|
|
&self,
|
|
|
|
|
|
max_objects: usize,
|
|
|
|
|
|
show: &DisplayFilter,
|
|
|
|
|
|
show_library_presence: bool,
|
|
|
|
|
|
max_depth: usize,
|
|
|
|
|
|
) -> String {
|
|
|
|
|
|
self.render_text_with_options(
|
|
|
|
|
|
max_objects,
|
|
|
|
|
|
show,
|
|
|
|
|
|
show_library_presence,
|
|
|
|
|
|
TextReportOptions {
|
|
|
|
|
|
ascii_depth: Some(max_depth),
|
|
|
|
|
|
..TextReportOptions::default()
|
|
|
|
|
|
},
|
|
|
|
|
|
)
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// Render the selected changes with optional object details and ASCII hierarchy.
|
|
|
|
|
|
pub fn render_text_with_options(
|
|
|
|
|
|
&self,
|
|
|
|
|
|
max_objects: usize,
|
|
|
|
|
|
show: &DisplayFilter,
|
|
|
|
|
|
show_library_presence: bool,
|
|
|
|
|
|
options: TextReportOptions,
|
|
|
|
|
|
) -> String {
|
|
|
|
|
|
let mut out = TextReport::default();
|
|
|
|
|
|
self.write_text_report(&mut out, max_objects, show, show_library_presence, options);
|
|
|
|
|
|
out.into_string()
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// Append the selected changes and their presentation roles to a text report.
|
|
|
|
|
|
pub fn write_text_report(
|
|
|
|
|
|
&self,
|
|
|
|
|
|
out: &mut TextReport,
|
|
|
|
|
|
max_objects: usize,
|
|
|
|
|
|
show: &DisplayFilter,
|
|
|
|
|
|
show_library_presence: bool,
|
|
|
|
|
|
options: TextReportOptions,
|
|
|
|
|
|
) {
|
|
|
|
|
|
let selection = selection::TextSelection::new(&self.cells, show, max_objects);
|
|
|
|
|
|
let outcome = self.outcome();
|
|
|
|
|
|
let headline = out.len();
|
|
|
|
|
|
let (result, style) = match outcome {
|
|
|
|
|
|
Outcome::Equal => ("Equal", TextStyle::Success),
|
|
|
|
|
|
Outcome::Different => ("Different", TextStyle::Warning),
|
|
|
|
|
|
Outcome::Incomplete { .. } => ("Incomplete", TextStyle::Warning),
|
|
|
|
|
|
Outcome::Failed => ("Failed", TextStyle::Error),
|
|
|
|
|
|
};
|
|
|
|
|
|
out.push_str(result);
|
|
|
|
|
|
let has_omissions = selection.filtered_objects != 0
|
|
|
|
|
|
|| selection.limited_objects != 0
|
|
|
|
|
|
|| selection.filtered_cells != 0;
|
|
|
|
|
|
if !self.cells.is_empty()
|
|
|
|
|
|
&& (self.cells.len() > 3 || !outcome.is_complete() || has_omissions)
|
|
|
|
|
|
{
|
|
|
|
|
|
let (mut modified, mut added, mut removed) = (0, 0, 0);
|
|
|
|
|
|
for cell in &self.cells {
|
|
|
|
|
|
match cell_marker(cell.old.is_some(), cell.new.is_some()) {
|
|
|
|
|
|
'-' => removed += 1,
|
|
|
|
|
|
'+' => added += 1,
|
|
|
|
|
|
_ => modified += 1,
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
let mut counts = [
|
|
|
|
|
|
(modified, "modified"),
|
|
|
|
|
|
(added, "added"),
|
|
|
|
|
|
(removed, "removed"),
|
|
|
|
|
|
]
|
|
|
|
|
|
.into_iter()
|
|
|
|
|
|
.filter(|(count, _)| *count != 0);
|
|
|
|
|
|
if let Some((count, action)) = counts.next() {
|
|
|
|
|
|
let noun = if count == 1 { "cell" } else { "cells" };
|
|
|
|
|
|
write!(out, " · {count} {noun} {action}").unwrap();
|
|
|
|
|
|
for (count, action) in counts {
|
|
|
|
|
|
write!(out, ", {count} {action}").unwrap();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
let library_changes = self.library_changes.iter().filter(|change| {
|
|
|
|
|
|
show_library_presence || !matches!(change, LibraryChange::Presence { .. })
|
|
|
|
|
|
});
|
|
|
|
|
|
for (count, label) in [
|
|
|
|
|
|
(library_changes.clone().count(), "library change"),
|
|
|
|
|
|
(self.layer_names.len(), "layer name change"),
|
|
|
|
|
|
] {
|
|
|
|
|
|
if count != 0 {
|
|
|
|
|
|
let plural = if count == 1 { "" } else { "s" };
|
|
|
|
|
|
write!(out, " · {count} {label}{plural}").unwrap();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
out.mark(headline, style);
|
|
|
|
|
|
out.push('\n');
|
|
|
|
|
|
self.old.scope.write_restrictions(out);
|
|
|
|
|
|
if show.cell.is_some() || show.layer.is_some() {
|
|
|
|
|
|
let start = out.len();
|
|
|
|
|
|
out.push_str("Display filter");
|
|
|
|
|
|
if let Some(cell) = &show.cell {
|
|
|
|
|
|
write!(out, " cell={cell:?}").unwrap();
|
|
|
|
|
|
}
|
|
|
|
|
|
if let Some((layer, datatype)) = show.layer {
|
|
|
|
|
|
write!(out, " layer={layer}/{datatype}").unwrap();
|
|
|
|
|
|
}
|
|
|
|
|
|
out.mark(start, TextStyle::Heading);
|
|
|
|
|
|
out.push('\n');
|
|
|
|
|
|
}
|
|
|
|
|
|
if has_omissions {
|
|
|
|
|
|
let start = out.len();
|
|
|
|
|
|
out.push_str("Omitted");
|
|
|
|
|
|
for (count, label, reason) in [
|
|
|
|
|
|
(selection.filtered_objects, "object change", "filtered out"),
|
|
|
|
|
|
(selection.limited_objects, "object change", "over the limit"),
|
|
|
|
|
|
(
|
|
|
|
|
|
selection.filtered_cells,
|
|
|
|
|
|
"cell-level change",
|
|
|
|
|
|
"filtered out",
|
|
|
|
|
|
),
|
|
|
|
|
|
] {
|
|
|
|
|
|
if count != 0 {
|
|
|
|
|
|
let plural = if count == 1 { "" } else { "s" };
|
|
|
|
|
|
write!(out, " · {count} {label}{plural} {reason}").unwrap();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
out.mark(start, TextStyle::Warning);
|
|
|
|
|
|
out.push('\n');
|
|
|
|
|
|
}
|
|
|
|
|
|
for change in library_changes {
|
|
|
|
|
|
writeln!(out, "library {change}").unwrap();
|
|
|
|
|
|
}
|
|
|
|
|
|
if self.library_changes.iter().any(|change| {
|
|
|
|
|
|
matches!(
|
|
|
|
|
|
change,
|
|
|
|
|
|
LibraryChange::Record {
|
|
|
|
|
|
tag: RTAG_UNITS,
|
|
|
|
|
|
..
|
|
|
|
|
|
}
|
|
|
|
|
|
)
|
|
|
|
|
|
}) {
|
|
|
|
|
|
out.push_str("Coordinates use each file's database units\n");
|
|
|
|
|
|
}
|
|
|
|
|
|
for change in &self.layer_names {
|
|
|
|
|
|
let name = |value: Option<&str>| {
|
|
|
|
|
|
value.map_or_else(|| "absent".to_string(), |value| format!("{value:?}"))
|
|
|
|
|
|
};
|
|
|
|
|
|
writeln!(
|
|
|
|
|
|
out,
|
|
|
|
|
|
"{}/{}: name {} -> {}",
|
|
|
|
|
|
change.layer.0,
|
|
|
|
|
|
change.layer.1,
|
|
|
|
|
|
name(change.old.as_deref()),
|
|
|
|
|
|
name(change.new.as_deref())
|
|
|
|
|
|
)
|
|
|
|
|
|
.unwrap();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
let mut body = CellText::new(&self.layer_legend, &self.layer_names, out.is_styled());
|
|
|
|
|
|
let mut covered_edges = BTreeSet::new();
|
|
|
|
|
|
for selected in &selection.modified_cells {
|
|
|
|
|
|
self.write_cell_details(
|
|
|
|
|
|
&mut body,
|
|
|
|
|
|
selected,
|
|
|
|
|
|
options.details,
|
|
|
|
|
|
(options.ascii_depth.is_some() && outcome.is_complete())
|
|
|
|
|
|
.then_some(&mut covered_edges),
|
|
|
|
|
|
);
|
|
|
|
|
|
}
|
|
|
|
|
|
body.write_legend(out);
|
|
|
|
|
|
if !selection.modified_cells.is_empty()
|
|
|
|
|
|
|| !selection.removed_cells.is_empty()
|
|
|
|
|
|
|| !selection.added_cells.is_empty()
|
|
|
|
|
|
{
|
|
|
|
|
|
out.write_styled(TextStyle::Heading, format_args!("Cells:"));
|
|
|
|
|
|
out.push('\n');
|
|
|
|
|
|
for name in selection.removed_cells {
|
|
|
|
|
|
out.write_styled(TextStyle::Removed, format_args!("- {}", cell_label(name)));
|
|
|
|
|
|
out.push('\n');
|
|
|
|
|
|
}
|
|
|
|
|
|
for name in selection.added_cells {
|
|
|
|
|
|
out.write_styled(TextStyle::Added, format_args!("+ {}", cell_label(name)));
|
|
|
|
|
|
out.push('\n');
|
|
|
|
|
|
}
|
|
|
|
|
|
body.write_body(out);
|
|
|
|
|
|
}
|
|
|
|
|
|
// General comparison errors precede revision-specific errors in text.
|
|
|
|
|
|
if !self.diagnostics.is_empty() {
|
|
|
|
|
|
out.write_styled(TextStyle::Heading, format_args!("Diagnostics"));
|
|
|
|
|
|
out.push('\n');
|
|
|
|
|
|
for diagnostic in self
|
|
|
|
|
|
.diagnostics
|
|
|
|
|
|
.iter()
|
|
|
|
|
|
.filter(|d| d.side.is_none())
|
|
|
|
|
|
.chain(self.diagnostics.iter().filter(|d| d.side.is_some()))
|
|
|
|
|
|
{
|
|
|
|
|
|
writeln!(out, " {diagnostic}").unwrap();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
if let Some(max_depth) = options.ascii_depth {
|
|
|
|
|
|
write_hierarchy(
|
|
|
|
|
|
out,
|
|
|
|
|
|
&self.old,
|
|
|
|
|
|
&self.new,
|
|
|
|
|
|
Some(&self.cells),
|
|
|
|
|
|
false,
|
|
|
|
|
|
max_depth,
|
|
|
|
|
|
Some(&covered_edges),
|
|
|
|
|
|
);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
fn write_cell_details(
|
|
|
|
|
|
&self,
|
|
|
|
|
|
out: &mut CellText<'_>,
|
|
|
|
|
|
selected: &selection::TextCellSelection<'_>,
|
|
|
|
|
|
details: bool,
|
|
|
|
|
|
mut covered_edges: Option<&mut BTreeSet<(String, String)>>,
|
|
|
|
|
|
) {
|
|
|
|
|
|
let cell = selected.cell;
|
|
|
|
|
|
let name = cell_label(&cell.name);
|
|
|
|
|
|
let note = if selected.attributes_changed {
|
|
|
|
|
|
" (attributes changed)"
|
|
|
|
|
|
} else {
|
|
|
|
|
|
""
|
|
|
|
|
|
};
|
|
|
|
|
|
out.style(Some(TextStyle::Changed));
|
|
|
|
|
|
writeln!(out, "* {name}{note}").unwrap();
|
|
|
|
|
|
let mut polygons = changes::PolygonChanges::default();
|
|
|
|
|
|
let mut shown_refs = BTreeMap::<&str, changes::ShownReferences>::new();
|
|
|
|
|
|
for &(a, b) in &selected.replacements {
|
|
|
|
|
|
if !details && a.layer == b.layer && is_polygon(a.kind) {
|
|
|
|
|
|
polygons.replacement(a, b);
|
|
|
|
|
|
continue;
|
|
|
|
|
|
}
|
|
|
|
|
|
out.push_str(" ");
|
|
|
|
|
|
out.style(Some(TextStyle::Changed));
|
|
|
|
|
|
out.push_str("~ ");
|
|
|
|
|
|
if a.layer != b.layer {
|
|
|
|
|
|
changes::write_layer_transition(out, a, b);
|
|
|
|
|
|
out.push('\n');
|
|
|
|
|
|
} else {
|
|
|
|
|
|
if let Some(layer) = a.layer {
|
|
|
|
|
|
out.write_layer(layer, None);
|
|
|
|
|
|
out.push_str(": ");
|
|
|
|
|
|
}
|
|
|
|
|
|
let description = changes::replacement_description(a, b, details);
|
|
|
|
|
|
let (heading, rest) = match description.split_once('\n') {
|
|
|
|
|
|
Some((heading, rest)) => (heading, Some(rest)),
|
|
|
|
|
|
None => (description.as_str(), None),
|
|
|
|
|
|
};
|
|
|
|
|
|
out.push_str(heading);
|
|
|
|
|
|
if let Some(target) = &a.target {
|
|
|
|
|
|
let placements = out.reserve_placements();
|
|
|
|
|
|
shown_refs
|
|
|
|
|
|
.entry(target)
|
|
|
|
|
|
.or_default()
|
|
|
|
|
|
.replacement(a, b, placements);
|
|
|
|
|
|
}
|
|
|
|
|
|
out.push('\n');
|
|
|
|
|
|
if let Some(rest) = rest {
|
|
|
|
|
|
writeln!(out, "{rest}").unwrap();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
if details {
|
|
|
|
|
|
changes::write_replacement_objects(out, a, b);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
let mut removed_refs = BTreeMap::new();
|
|
|
|
|
|
let mut added_refs = BTreeMap::new();
|
|
|
|
|
|
for (removed, objects, references) in [
|
|
|
|
|
|
(true, &selected.removed, &mut removed_refs),
|
|
|
|
|
|
(false, &selected.added, &mut added_refs),
|
|
|
|
|
|
] {
|
|
|
|
|
|
let sign = if removed { '-' } else { '+' };
|
|
|
|
|
|
let mut unmatched: Vec<(&ObjectChange, usize)> = Vec::new();
|
|
|
|
|
|
for &object in objects {
|
|
|
|
|
|
if !details && is_polygon(object.kind) {
|
|
|
|
|
|
polygons.unmatched(object, removed);
|
|
|
|
|
|
} else if !details && let Some(target) = object.target.as_deref() {
|
|
|
|
|
|
let (_, counts) = references
|
|
|
|
|
|
.entry(target)
|
|
|
|
|
|
.or_insert_with(|| (object, changes::ReferenceCounts::default()));
|
|
|
|
|
|
counts.add(object);
|
|
|
|
|
|
} else if let Some((last, count)) = unmatched.last_mut()
|
|
|
|
|
|
&& last.kind == object.kind
|
|
|
|
|
|
&& last.fields == object.fields
|
|
|
|
|
|
&& last.properties == object.properties
|
|
|
|
|
|
{
|
|
|
|
|
|
*count += 1;
|
|
|
|
|
|
} else {
|
|
|
|
|
|
unmatched.push((object, 1));
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
// The comparison orders these objects by kind, fields, and properties.
|
|
|
|
|
|
for (object, count) in unmatched {
|
|
|
|
|
|
out.push_str(" ");
|
|
|
|
|
|
out.style(Some(TextStyle::change(sign)));
|
|
|
|
|
|
write!(out, "{sign} ").unwrap();
|
|
|
|
|
|
if count > 1 {
|
|
|
|
|
|
write!(out, "{count}× ").unwrap();
|
|
|
|
|
|
}
|
|
|
|
|
|
changes::write_unmatched(out, object, details);
|
|
|
|
|
|
if let Some(target) = object.target.as_deref() {
|
|
|
|
|
|
let placements = out.reserve_placements();
|
|
|
|
|
|
shown_refs
|
|
|
|
|
|
.entry(target)
|
|
|
|
|
|
.or_default()
|
|
|
|
|
|
.individual(object, removed, count, placements);
|
|
|
|
|
|
}
|
|
|
|
|
|
out.push('\n');
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
let no_refs = changes::ReferenceCounts::default();
|
|
|
|
|
|
for (target, (first, counts)) in removed_refs {
|
|
|
|
|
|
if let Some((_, added)) = added_refs.remove(target) {
|
|
|
|
|
|
let placements = counts.write_change(out, target, &added);
|
|
|
|
|
|
shown_refs
|
|
|
|
|
|
.entry(target)
|
|
|
|
|
|
.or_default()
|
|
|
|
|
|
.unmatched(&counts, &added, placements);
|
|
|
|
|
|
} else {
|
|
|
|
|
|
let placements = counts.write(out, '-', target, first);
|
|
|
|
|
|
shown_refs
|
|
|
|
|
|
.entry(target)
|
|
|
|
|
|
.or_default()
|
|
|
|
|
|
.unmatched(&counts, &no_refs, placements);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
for (target, (first, counts)) in added_refs {
|
|
|
|
|
|
let placements = counts.write(out, '+', target, first);
|
|
|
|
|
|
shown_refs
|
|
|
|
|
|
.entry(target)
|
|
|
|
|
|
.or_default()
|
|
|
|
|
|
.unmatched(&no_refs, &counts, placements);
|
|
|
|
|
|
}
|
|
|
|
|
|
if !shown_refs.is_empty() {
|
|
|
|
|
|
for target in cell
|
|
|
|
|
|
.removed
|
|
|
|
|
|
.iter()
|
|
|
|
|
|
.chain(&cell.added)
|
|
|
|
|
|
.filter_map(|o| o.target.as_deref())
|
|
|
|
|
|
{
|
|
|
|
|
|
if let Some(shown) = shown_refs.get_mut(target) {
|
|
|
|
|
|
shown.count_change();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
for (target, shown) in shown_refs {
|
|
|
|
|
|
if shown.complete() {
|
|
|
|
|
|
let edge = (cell.name.clone(), target.to_owned());
|
|
|
|
|
|
let old = self.old.edges.get(&edge).copied().unwrap_or(0);
|
|
|
|
|
|
let new = self.new.edges.get(&edge).copied().unwrap_or(0);
|
|
|
|
|
|
shown.write_placements(out, old, new);
|
|
|
|
|
|
if let Some(covered) = covered_edges.as_deref_mut() {
|
|
|
|
|
|
covered.insert(edge);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
polygons.write(out);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|