Skip to main content

render_diff

Function render_diff 

Source
pub fn render_diff(diff_text: &str, theme: &dyn Theme) -> Vec<String>
Expand description

Render a diff string with colored lines and intra-line change highlighting. Matches pi’s renderDiff() in diff.ts.

Input format (pi-compatible): +{lineNum} {content} / -{lineNum} {content} / {lineNum} {content} / ... Also handles simple format without line numbers: -{content} / +{content} / {content}

Output: ANSI-styled lines with:

  • - lines: toolDiffRemoved (red), with inverse on changed tokens for single-line changes
  • + lines: toolDiffAdded (green), with inverse on changed tokens for single-line changes
  • lines: toolDiffContext (gray)

Multi-line changes show all removed lines first, then all added lines (no intra-line diff). Single-line changes (1 removed + 1 added) render intra-line word-diff with inverse.

Takes a &dyn Theme parameter to avoid calling current_theme() which would deadlock if the theme lock is already held by a caller.