# `MingaEditor.Frontend`
[🔗](https://github.com/jsmestad/minga/blob/main/lib/minga_editor/frontend.ex#L1)

Frontend communication domain facade.

External callers tell the frontend WHAT to do through semantic
operations. The Frontend domain handles HOW (binary encoding,
batching, protocol versioning) internally.

## Render frames

The Editor builds a `Frame` struct (display list of styled text
runs). `send_render_frame/2` encodes and sends it to the frontend.

## Parser commands

Tree-sitter parsing runs in a separate Zig process. Parser commands
(setup_buffer, update_buffer, set_queries) encode the appropriate
wire messages and send them to the parser port.

## Configuration

Font, title, theme, and window background are set through
individual semantic operations.

# `capabilities`

```elixir
@spec capabilities(GenServer.server()) :: MingaEditor.Frontend.Capabilities.t()
```

Returns the frontend capabilities struct.

# `clipboard_write`

```elixir
@spec clipboard_write(GenServer.server(), String.t(), atom()) :: :ok
```

Sends a clipboard write command to the GUI frontend.

# `close_parser_buffer`

```elixir
@spec close_parser_buffer(GenServer.server(), non_neg_integer()) :: :ok
```

Closes a parser buffer.

# `configure_font`

```elixir
@spec configure_font(
  GenServer.server(),
  String.t(),
  pos_integer(),
  boolean(),
  atom(),
  [String.t()]
) ::
  :ok
```

Configures the editor font.

# `decode_event`

```elixir
@spec decode_event(binary()) ::
  {:ok, MingaEditor.Frontend.Protocol.input_event()}
  | {:error, :unknown_opcode | :malformed}
```

Decodes a binary event from the frontend or parser process.

# `default_capabilities`

```elixir
@spec default_capabilities() :: MingaEditor.Frontend.Capabilities.t()
```

Returns the default capabilities struct.

# `edit_buffer`

```elixir
@spec edit_buffer(GenServer.server(), non_neg_integer(), non_neg_integer(), [map()]) ::
  :ok
```

Sends an incremental edit to a buffer.

# `gui?`

```elixir
@spec gui?(MingaEditor.Frontend.Capabilities.t()) :: boolean()
```

Returns true if the frontend supports GUI chrome opcodes.

# `load_grammar`

```elixir
@spec load_grammar(GenServer.server(), String.t(), String.t()) :: :ok
```

Loads a tree-sitter grammar from a shared library.

# `parse_buffer`

```elixir
@spec parse_buffer(
  GenServer.server(),
  non_neg_integer(),
  non_neg_integer(),
  String.t()
) :: :ok
```

Sends a full reparse of a buffer's content.

# `ready?`

```elixir
@spec ready?(GenServer.server()) :: boolean()
```

Returns true if the frontend is ready to receive commands.

# `request_textobject`

```elixir
@spec request_textobject(
  GenServer.server(),
  non_neg_integer(),
  non_neg_integer(),
  non_neg_integer(),
  non_neg_integer(),
  String.t()
) :: :ok
```

Requests textobject positions for a buffer location.

# `semantic_ui?`

```elixir
@spec semantic_ui?(MingaEditor.Frontend.Capabilities.t()) :: boolean()
```

Returns true if the frontend supports semantic render-model opcodes.

# `send_commands`

```elixir
@spec send_commands(GenServer.server(), [binary()]) :: :ok
```

Sends a list of pre-encoded commands to the frontend process.

# `send_frame_boundary`

```elixir
@spec send_frame_boundary(
  GenServer.server(),
  non_neg_integer(),
  non_neg_integer(),
  non_neg_integer()
) :: :ok
```

Sends a bare, content-free frame transaction to the frontend (#2219).

Used by frame-synchronization contracts that must emit a frame boundary without
re-rendering (the operator-pending no-op optimization). Brackets nothing with
`begin_frame ++ commit_frame`. `frame_seq` is the strictly monotonic global frame
sequence; `base_frame_seq` names the previously emitted frame (0 for the first).
`input_seq` is the echoed input correlation sequence (ticket #2215, default 0).

# `send_render_commands`

```elixir
@spec send_render_commands(GenServer.server(), [binary()]) :: :ok
```

Sends the per-frame render batch and stamps a monotonic send time so the
frontend emits a `[:minga, :render, :hop_latency]` (`hop: :send_commands`)
sample for the Renderer.Server → Port.Manager scheduling delay.

# `set_buffer_language`

```elixir
@spec set_buffer_language(GenServer.server(), non_neg_integer(), String.t()) :: :ok
```

Sets the language for a parser buffer.

# `set_parser_queries`

```elixir
@spec set_parser_queries(GenServer.server(), non_neg_integer(), keyword()) :: :ok
```

Sets tree-sitter queries for a parser buffer.

Accepts a keyword list of query types and their text:
`[highlight: "...", injection: "...", fold: "...", textobject: "..."]`

# `set_title`

```elixir
@spec set_title(GenServer.server(), String.t()) :: :ok
```

Sets the window title.

# `set_window_bg`

```elixir
@spec set_window_bg(GenServer.server(), non_neg_integer()) :: :ok
```

Sets the window background color.

# `setup_parser_buffer`

```elixir
@spec setup_parser_buffer(
  GenServer.server(),
  non_neg_integer(),
  String.t(),
  String.t(),
  non_neg_integer()
) :: :ok
```

Sets up a buffer in the parser with language and initial content.

Combines set_language + parse_buffer into a single batch.

# `subscribe`

```elixir
@spec subscribe(GenServer.server()) :: :ok
```

Subscribes the calling process to frontend events.

# `terminal_size`

```elixir
@spec terminal_size(GenServer.server()) :: {pos_integer(), pos_integer()} | nil
```

Returns the terminal dimensions {width, height}.

---

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