feat(diff): Add diff rendering helpers for GUI
- Add get_line_color() to classify diff lines - Add render_diff_text_immediate() for immediate mode rendering - Add tests for rendering functions
This commit is contained in:
@@ -126,4 +126,24 @@ def format_diff_for_display(diff_files: List[DiffFile]) -> str:
|
||||
output.append(f" {hunk.header}")
|
||||
for line in hunk.lines:
|
||||
output.append(f" {line}")
|
||||
return "\n".join(output)
|
||||
return "\n".join(output)
|
||||
|
||||
def get_line_color(line: str) -> Optional[str]:
|
||||
if line.startswith("+"):
|
||||
return "green"
|
||||
elif line.startswith("-"):
|
||||
return "red"
|
||||
elif line.startswith("@@"):
|
||||
return "cyan"
|
||||
return None
|
||||
|
||||
def render_diff_text_immediate(diff_files: List[DiffFile]) -> List[tuple[str, Optional[str]]]:
|
||||
output: List[tuple[str, Optional[str]]] = []
|
||||
for df in diff_files:
|
||||
output.append((f"File: {df.old_path}", "white"))
|
||||
for hunk in df.hunks:
|
||||
output.append((hunk.header, "cyan"))
|
||||
for line in hunk.lines:
|
||||
color = get_line_color(line)
|
||||
output.append((line, color))
|
||||
return output
|
||||
Reference in New Issue
Block a user