# `Drafter.Render.Writer`
[🔗](https://github.com/jaman/drafter/blob/main/lib/drafter/render/writer.ex#L1)

The one process that writes a session's terminal, for `Drafter.Compositor`.

    {:ok, writer} = Drafter.Render.Writer.start_link(:tty)
    Drafter.Render.Writer.write(writer, frame_bytes)

Every write is one call to the sink, in the order the calls were made, so no sequence
is ever cut by another, and no call blocks the caller or is dropped. `behind?/1`
tells whether anything handed over is still unwritten, for a caller that would rather
merge its next frames into one than queue them.

The sink is a function of iodata, or `{:tty, fallback}` to write `/dev/tty` — which the
writer opens itself, since a raw file is usable only by the process that opened it —
using the `fallback` function when `/dev/tty` cannot be opened.

# `behind?`

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

Whether anything handed over by `write/2` is still waiting to be written.

# `child_spec`

Returns a specification to start this module under a supervisor.

See `Supervisor`.

# `flush`

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

Return once everything handed over so far has been written.

# `start_link`

```elixir
@spec start_link((iodata() -&gt; term()) | {:tty, (iodata() -&gt; term())}) ::
  GenServer.on_start()
```

Start a writer whose `sink` is a function of iodata, or `{:tty, fallback}`.

# `write`

```elixir
@spec write(GenServer.server(), iodata()) :: :ok
```

Write `bytes` after everything already handed over. Asynchronous, never dropped.

---

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