Skip to content

Commit b19a0bf

Browse files
Delegate diff rendering wholesale to termflow 0.3.0
Diff parsing, syntax highlighting, backgrounds, and theme tints now live in termflow.diff; tools/common.py keeps only thin adapters. Deleted the pygments machinery (TOKEN_COLORS, EXTENSION_TO_LEXER_NAME, _get_lexer_for_extension, _get_token_color, _highlight_code_line, _extract_file_extension_from_diff, _format_diff_with_syntax_highlighting, PYGMENTS_AVAILABLE) — ~350 lines gone, and language detection upgraded for free via termflow's LANGUAGE_ALIASES. Adapters: _termflow_diff_renderer wires the termflow_highlighter theme callback (diff_line_tints contract preserved) plus the user's configured /diff colors; format_diff_with_colors keeps its signature (block mode, Text.from_ansi) so diff-menu previews are untouched; new stream_diff_ansi_lines yields rendered ANSI lines incrementally via termflow's DiffStream, and rich_renderer._render_diff now prints diffs progressively line-by-line instead of one monolithic Text block.
1 parent 4e2ce27 commit b19a0bf

6 files changed

Lines changed: 117 additions & 521 deletions

File tree

code_puppy/messaging/rich_renderer.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
get_suppress_informational_messages,
2626
get_suppress_thinking_messages,
2727
)
28-
from code_puppy.tools.common import format_diff_with_colors
28+
from code_puppy.tools.common import stream_diff_ansi_lines
2929
from code_puppy.tools.subagent_context import is_subagent
3030

3131
from .bus import MessageBus
@@ -870,7 +870,7 @@ def _render_diff(self, msg: DiffMessage) -> None:
870870
if not msg.diff_lines:
871871
return
872872

873-
# Reconstruct unified diff text from diff_lines for format_diff_with_colors
873+
# Reconstruct unified diff text from diff_lines for termflow's renderer
874874
diff_text_lines = []
875875
for line in msg.diff_lines:
876876
if line.type == "add":
@@ -887,9 +887,13 @@ def _render_diff(self, msg: DiffMessage) -> None:
887887

888888
diff_text = "\n".join(diff_text_lines)
889889

890-
# Use the beautiful syntax-highlighted diff formatter
891-
formatted_diff = format_diff_with_colors(diff_text)
892-
self._console.print(formatted_diff)
890+
# Stream through termflow's diff renderer: each line paints as soon
891+
# as it renders, so big diffs appear progressively instead of
892+
# blocking on one monolithic block.
893+
from rich.text import Text
894+
895+
for ansi_line in stream_diff_ansi_lines(diff_text):
896+
self._console.print(Text.from_ansi(ansi_line))
893897

894898
# =========================================================================
895899
# Shell Output

0 commit comments

Comments
 (0)