# `Drafter.Terminal.RawMode`
[🔗](https://github.com/jaman/drafter/blob/v0.6.1/lib/drafter/terminal/raw_mode.ex#L1)

Puts the controlling terminal into raw mode and takes it out again.

`enter/0` returns how raw mode was entered, and `leave/1` takes that value back to
undo it:

    {:ok, mode} = Drafter.Terminal.RawMode.enter()
    Drafter.Terminal.RawMode.leave(mode)

The termios NIF is used where it loads and `stty` otherwise. Off unix neither runs,
`enter/0` returns `{:ok, nil}`, and the terminal mode is left alone.

In raw mode input arrives unbuffered and unechoed, control characters such as
`Ctrl+C` arrive as input instead of raising signals, and a line feed written to the
terminal no longer returns the cursor to the first column.

# `mode`

```elixir
@type mode() :: :nif | {:stty, binary()} | nil
```

How raw mode was entered: by the NIF, by `stty` with the saved settings, or not at all.

# `enter`

```elixir
@spec enter() :: {:ok, mode()} | {:error, term()}
```

Enter raw mode.

`{:error, :not_a_terminal}` means standard input is not a terminal, and
`{:error, {:stty_failed, output}}` that `stty` refused.

# `leave`

```elixir
@spec leave(mode()) :: :ok
```

Restore the terminal settings saved by the `enter/0` that returned `mode`.

---

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