# `Minga.Frontend.Adapter.GUI.WindowEncoder`
[🔗](https://github.com/jsmestad/minga/blob/main/lib/minga/frontend/adapter/gui/window_encoder.ex#L1)

Binary protocol encoder for the `gui_window_content` opcode (0x80).

Encodes a `RenderWindow` struct into the wire format for GUI frontends.
This replaces draw_text commands for buffer windows, sending pre-resolved
semantic data that Swift renders directly via CoreText.

## Wire Format

```
opcode:               u8 = 0x80
window_id:            u16
flags:                u8       (bit 0 = full_refresh, bit 1 = cursor_visible)
cursor_row:           u16      (display row, fold/wrap adjusted)
cursor_col:           u16      (display col, virtual text adjusted)
cursor_shape:         u8
scroll_left:          u16      (horizontal scroll offset in display cols)
visible_row_count:    u16

per visible row:
  row_type:           u8       (0=normal, 1=fold_start, 2=virtual_line,
                                3=block, 4=wrap_continuation)
  row_id:             u64      (stable retained-render identity)
  buf_line:           u32
  content_hash:       u32      (for CTLine cache invalidation)
  text_len:           u32
  text:               [text_len]  UTF-8
  span_count:         u16
  per span:
    start_col:        u16
    end_col:          u16
    fg:               u24
    bg:               u24
    attrs:            u8
    font_weight:      u8
    font_id:          u8

selection_type:       u8       0=none, 1=char, 2=line, 3=block
if != 0: start_row(u16), start_col(u16), end_row(u16), end_col(u16)

match_count:          u16
per match: row(u16), start_col(u16), end_col(u16), is_current(u8)

diag_range_count:     u16
per range: start_row(u16), start_col(u16), end_row(u16), end_col(u16),
           severity(u8)

highlight_count:      u16
per highlight: start_row(u16), start_col(u16), end_row(u16), end_col(u16),
               kind(u8)
Kind: 1=text, 2=read, 3=write

annotation_count:     u16
per annotation:
  row:                u16      (display row)
  kind:               u8       (0=inline_pill, 1=inline_text, 2=gutter_icon)
  fg:                 u24
  bg:                 u24
  text_len:           u16
  text:               [text_len] UTF-8
```

# `metrics`

```elixir
@type metrics() :: %{
  row_bytes: non_neg_integer(),
  overlay_bytes: non_neg_integer(),
  gutter_bytes: non_neg_integer(),
  annotation_bytes: non_neg_integer(),
  metadata_bytes: non_neg_integer()
}
```

Per-section byte metrics for encoded window content.

# `encode`

```elixir
@spec encode(Minga.RenderModel.Window.t()) :: [binary()]
```

Encodes a `RenderWindow` into the 0x80 wire format (sectioned).

Returns a single binary suitable for sending via `MingaEditor.Frontend.send_commands/2`.

# `encode_frame_metadata`

```elixir
@spec encode_frame_metadata(Minga.RenderModel.Window.t()) :: [binary()]
```

Encodes per-frame window metadata that the GUI clears and rebuilds every batch.

# `encode_frame_metadata_with_metrics`

```elixir
@spec encode_frame_metadata_with_metrics(Minga.RenderModel.Window.t()) ::
  {[binary()], metrics()}
```

Encodes per-frame window metadata with byte metrics.

# `encode_overlay_delta`

```elixir
@spec encode_overlay_delta(Minga.RenderModel.Window.t()) :: binary()
```

Encodes a cursor and cursorline overlay delta for a retained GUI window.

# `encode_rows_delta`

```elixir
@spec encode_rows_delta(Minga.RenderModel.Window.t(), %{
  required(non_neg_integer()) =&gt; non_neg_integer()
}) :: {binary(), boolean()}
```

Encodes a retained rows delta with ordered ref-or-full row entries.

# `encode_viewport_delta`

```elixir
@spec encode_viewport_delta(Minga.RenderModel.Window.t(), %{
  required(non_neg_integer()) =&gt; non_neg_integer()
}) :: {binary(), boolean()}
```

Encodes a retained viewport delta with ordered ref-or-full row entries.

# `encode_window_content`

```elixir
@spec encode_window_content(Minga.RenderModel.Window.t()) :: binary()
```

# `encode_window_content_with_metrics`

```elixir
@spec encode_window_content_with_metrics(Minga.RenderModel.Window.t()) ::
  {binary(), metrics()}
```

Encodes window content with per-section byte metrics.

# `opcode`

```elixir
@spec opcode() :: non_neg_integer()
```

Returns the opcode constant for gui_window_content.

---

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