Skip to main content

render_diff

Function render_diff 

Source
pub fn render_diff(
    current: &Buffer,
    next: &Buffer,
    dirty_rects: &[Rect],
    output: &mut Vec<u8>,
    state: &mut DiffState,
) -> DiffResult
Expand description

Render the difference between two buffers into an ANSI sequence buffer.

This is the core diffing function. It compares current and next buffers, generating minimal ANSI escape sequences for only the cells that changed.

§Optimizations

  1. Cursor movement: Skips explicit moves when writing adjacent cells
  2. Color tracking: Only emits color changes when fg/bg actually differ
  3. Modifier tracking: Only emits modifier changes when needed
  4. Dirty rectangles: Only iterates over specified dirty regions

§Arguments

  • current - The currently displayed buffer
  • next - The buffer to transition to
  • dirty_rects - Regions to check for changes (empty = full buffer)
  • output - Buffer to write ANSI sequences to
  • state - Mutable state tracking cursor/color positions

§Returns

Statistics about the diff operation.