# `Minga.Core.DiffView`
[🔗](https://github.com/jsmestad/minga/blob/main/lib/minga/core/diff_view.ex#L1)

Pure calculation module for building unified diff views.

Takes base (HEAD) lines and current lines with hunks, produces interleaved
text with line metadata for rendering as a read-only buffer with decorations.

# `diff_view_result`

```elixir
@type diff_view_result() :: %{
  text: String.t(),
  line_metadata: [line_meta()],
  hunk_lines: [non_neg_integer()]
}
```

Result of building a diff view: the text content and per-line metadata.

# `line_meta`

```elixir
@type line_meta() :: %{
  :type =&gt; line_type(),
  :original_line =&gt; non_neg_integer() | nil,
  :fold_count =&gt; non_neg_integer() | nil,
  :word_changes =&gt; [Minga.Core.Diff.char_range()] | nil,
  optional(:left_type) =&gt; pane_line_type(),
  optional(:right_type) =&gt; pane_line_type(),
  optional(:left_width) =&gt; pos_integer(),
  optional(:separator_col) =&gt; non_neg_integer(),
  optional(:left_word_changes) =&gt; [Minga.Core.Diff.char_range()] | nil,
  optional(:right_word_changes) =&gt; [Minga.Core.Diff.char_range()] | nil
}
```

Metadata for a single display line in the diff view.

# `line_type`

```elixir
@type line_type() :: :context | :added | :removed | :header | :fold
```

# `pane_line_type`

```elixir
@type pane_line_type() :: :context | :added | :removed | :blank | :fold
```

# `build`

```elixir
@spec build(String.t(), String.t()) :: diff_view_result()
```

Builds a unified diff view from base and current content.

Returns a map with:
- `:text` - the interleaved unified diff text to inject into a Buffer
- `:line_metadata` - per-line metadata for decorations (type, original line number)
- `:hunk_lines` - display line indices where hunks end (for hunk position and actions)

# `build_from_hunks`

```elixir
@spec build_from_hunks([String.t()], [String.t()], [Minga.Core.Diff.hunk()]) ::
  diff_view_result()
```

Builds a unified diff view from pre-computed hunks.

# `build_side_by_side`

```elixir
@spec build_side_by_side(String.t(), String.t(), pos_integer()) :: diff_view_result()
```

Builds a GUI side-by-side diff view from base and current content.

The result uses one rendered buffer line per aligned row. The left pane carries the old version, the right pane carries the new version, and blank filler rows preserve vertical alignment across additions and deletions. Metadata includes pane-local change ranges so GUI decorations can highlight each pane independently.

# `build_side_by_side_from_hunks`

```elixir
@spec build_side_by_side_from_hunks(
  [String.t()],
  [String.t()],
  [Minga.Core.Diff.hunk()],
  pos_integer()
) ::
  diff_view_result()
```

Builds a GUI side-by-side diff view from pre-computed hunks.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
