# `Drafter.Terminal.Stdin`
[🔗](https://github.com/jaman/drafter/blob/v0.6.0/lib/drafter/terminal/stdin.ex#L1)

The one reader of standard input on this node.

Reading starts at the first `subscribe/2` and continues for the life of the node.
Each chunk read is sent to the subscriber as `{:stdin, binary}`, and `:stdin_closed`
is sent when standard input ends. One process is subscribed at a time, and a new
subscription replaces the previous one. A subscriber that exits is unsubscribed.

Bytes read while no process is subscribed are held. The next subscriber receives
them as one `{:stdin, binary}` when it subscribes with `:keep`, and they are dropped
when it subscribes with `:discard`.

    Drafter.Terminal.Stdin.subscribe()

    receive do
      {:stdin, bytes} -> bytes
    end

Once reading has started, every byte of standard input passes through this process.
A process that reads standard input another way after that point competes with it.

# `held`

```elixir
@type held() :: :keep | :discard
```

# `child_spec`

Returns a specification to start this module under a supervisor.

See `Supervisor`.

# `start_link`

```elixir
@spec start_link(keyword()) :: GenServer.on_start()
```

Start the reader's owner and register it under this module's name.

# `subscribe`

```elixir
@spec subscribe(pid(), held()) :: :ok
```

Send standard input to `subscriber` from now on, replacing any other subscriber.

`held` says what happens to bytes read while nobody was subscribed: `:keep` (the
default) delivers them first, `:discard` drops them. A subscriber that joins after
standard input ended is sent `:stdin_closed` at once.

# `unsubscribe`

```elixir
@spec unsubscribe(pid()) :: :ok
```

Stop sending standard input to `subscriber`.

Does nothing when `subscriber` is not the current subscriber. Reading continues and
what is read is held for the next subscriber.

---

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