diff --git a/device_diff.py b/device_diff.py index f51303f..95f44b5 100644 --- a/device_diff.py +++ b/device_diff.py @@ -240,18 +240,44 @@ class DeviceComparison: def _print_differences(self, differences: List[Dict], device1_name: str, device2_name: str) -> None: """ - Print list of differences in readable format. + Print list of differences in columnar format. Args: differences: List of difference dictionaries device1_name: First device name device2_name: Second device name """ - for diff in differences: - key = diff['key'] - val1 = diff['device1_value'] - val2 = diff['device2_value'] + if not differences: + return - print(f"\n{key}:") - print(f" {device1_name:20} = {val1}") - print(f" {device2_name:20} = {val2}") + # Calculate column widths + max_key_len = max(len(str(diff['key'])) for diff in differences) + max_val1_len = max(len(str(diff['device1_value'])) for diff in differences) + max_val2_len = max(len(str(diff['device2_value'])) for diff in differences) + + # Ensure minimum column widths + key_width = max(max_key_len, 15) + val1_width = max(max_val1_len, len(device1_name), 20) + val2_width = max(max_val2_len, len(device2_name), 20) + + # Truncate device names if too long for column headers + dev1_header = device1_name[:val1_width] + dev2_header = device2_name[:val2_width] + + # Print header row + print(f"\n{'Parameter':<{key_width}} {dev1_header:<{val1_width}} {dev2_header:<{val2_width}}") + print("-" * key_width + " " + "-" * val1_width + " " + "-" * val2_width) + + # Print each difference + for diff in differences: + key = str(diff['key']) + val1 = str(diff['device1_value']) + val2 = str(diff['device2_value']) + + # Truncate values if too long + if len(val1) > 60: + val1 = val1[:57] + "..." + if len(val2) > 60: + val2 = val2[:57] + "..." + + print(f"{key:<{key_width}} {val1:<{val1_width}} {val2:<{val2_width}}")