tenseleyflow/loader / 5946d38

Browse files

ui: improve DiffWidget to show content previews

- For Create: show preview of content being written (first 100 chars)
- For Update: show both old and new content previews with -/+ prefixes
- Makes it clearer what's being changed without expanding full diff
Authored by espadonne
SHA
5946d38c783b0de71906b65726fc779ec9ea6444
Parents
45ef0c6
Tree
618a956

1 changed file

StatusFile+-
M src/loader/ui/widgets/diff_widget.py 25 0
src/loader/ui/widgets/diff_widget.pymodified
@@ -27,6 +27,8 @@ class DiffWidget(Vertical):
2727
         self.is_new_file = not old_string  # True if creating new file
2828
 
2929
     def compose(self) -> ComposeResult:
30
+        from rich.markup import escape
31
+
3032
         # Calculate stats
3133
         old_lines = self.old_string.splitlines() if self.old_string else []
3234
         new_lines = self.new_string.splitlines()
@@ -43,6 +45,14 @@ class DiffWidget(Vertical):
4345
                 f"└ [green]+{len(new_lines)}[/green] lines",
4446
                 classes="diff-stats",
4547
             )
48
+            # Show preview of content being written
49
+            preview = self.new_string[:100].replace('\n', ' ')
50
+            if len(self.new_string) > 100:
51
+                preview += "..."
52
+            yield Static(
53
+                f"  [dim]{escape(preview)}[/dim]",
54
+                classes="diff-preview",
55
+            )
4656
         else:
4757
             added = sum(1 for line in new_lines if line not in old_lines)
4858
             removed = sum(1 for line in old_lines if line not in new_lines)
@@ -61,6 +71,21 @@ class DiffWidget(Vertical):
6171
                     f"└ {', '.join(stats_parts)} lines",
6272
                     classes="diff-stats",
6373
                 )
74
+            # Show what's being replaced
75
+            old_preview = self.old_string[:50].replace('\n', ' ')
76
+            new_preview = self.new_string[:50].replace('\n', ' ')
77
+            if len(self.old_string) > 50:
78
+                old_preview += "..."
79
+            if len(self.new_string) > 50:
80
+                new_preview += "..."
81
+            yield Static(
82
+                f"  [red]-[/red] [dim]{escape(old_preview)}[/dim]",
83
+                classes="diff-preview-old",
84
+            )
85
+            yield Static(
86
+                f"  [green]+[/green] [dim]{escape(new_preview)}[/dim]",
87
+                classes="diff-preview-new",
88
+            )
6489
 
6590
         # Diff content
6691
         yield Static(