From cacdfe7a77ce7ffd350e76b187fab5671bda3391 Mon Sep 17 00:00:00 2001 From: Mike Geppert Date: Sun, 4 Jan 2026 11:22:43 -0600 Subject: [PATCH] Improve --diff report output with columnar format MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Enhanced readability with table-style columnar output Changes: - Converted vertical list format to columnar table format - First column: Parameter name - Second column: Device 1 value - Third column: Device 2 value - Added header row with device names - Auto-adjusts column widths based on content - Truncates very long values (>60 chars) with "..." - Maintains section separation (Firmware, Network, MQTT, etc.) Before: SetOption32: KitchenMain = 40 KitchenBar = 8 After: Parameter KitchenMain-3040 KitchenBar-7845 --------------- -------------------- -------------------- SetOption32 40 8 Much easier to scan and compare values side-by-side! 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- device_diff.py | 42 ++++++++++++++++++++++++++++++++++-------- 1 file changed, 34 insertions(+), 8 deletions(-) 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}}")