ElixirOpentui.Widgets.Diff (ElixirOpentui v0.2.0)

Copy Markdown View Source

Diff display widget with unified and split views.

Parses unified diff format and renders with line numbers, add/remove indicators, and per-line coloring. Supports both unified (single column) and split (side-by-side) view modes.

Props

  • :diff — unified diff string
  • :view — display mode :unified | :split (default: :unified)

  • :id — element id
  • :show_line_numbers — show line number gutters (default: true)
  • :scroll_offset — vertical scroll position (default: 0)
  • :visible_lines — number of visible lines (default: nil, show all)

Summary

Functions

Build display lines from parsed diff state for the current view mode.

Parse a unified diff string into a structured representation.

Functions

build_lines(state)

@spec build_lines(map()) :: [map()]

Build display lines from parsed diff state for the current view mode.

parse_diff(diff_text)

@spec parse_diff(String.t()) :: [map()]

Parse a unified diff string into a structured representation.

Returns a list of hunks, where each hunk contains:

  • :header — the @@ line
  • :old_start — starting line in old file
  • :new_start — starting line in new file
  • :lines — list of %{type, content, old_line, new_line} maps