# `Linx.Tty.Native`
[🔗](https://github.com/oshlabs/linx/blob/v0.2.0/lib/linx/tty/native.ex#L1)

NIF binding for `Linx.Tty`. Loads `priv/linx_tty.so` (built by the
`:linx_tty` Mix compiler) and exposes the small set of `termios(3)`
/ `ioctl(2)` syscalls the public `Linx.Tty` module wraps.

The functions below are placeholders until the NIF is loaded; calling
one before `__on_load__/0` runs raises `:nif_not_loaded`. Production
callers should not use this module directly — go through `Linx.Tty`.

# `error`

```elixir
@type error() :: {:error, {atom(), atom() | integer()}}
```

Error returned by every fallible NIF call. The first element of the
inner tuple names the syscall that failed; the second is a POSIX-style
atom (`:enxio`, `:enotty`, …) or the raw errno integer if the value
isn't in the C-side mapping table.

# `open_controlling_raw`

```elixir
@spec open_controlling_raw() :: {:ok, non_neg_integer(), binary()} | error()
```

Opens `/dev/tty`, saves the current `termios`, and switches it to
raw mode (`cfmakeraw`). Returns the fd integer and the saved blob.

# `restore_and_close`

```elixir
@spec restore_and_close(non_neg_integer(), binary()) :: :ok | error()
```

Writes `saved` back over `fd`'s termios and closes the fd. EBADF
from either step is swallowed so a double-restore is a no-op.

# `set_window_size`

```elixir
@spec set_window_size(
  non_neg_integer(),
  {non_neg_integer(), non_neg_integer(), non_neg_integer(), non_neg_integer()}
) :: :ok | error()
```

Sets `fd`'s window size via `TIOCSWINSZ`. The tuple is
`{rows, cols, xpixel, ypixel}`.

# `version`

```elixir
@spec version() :: binary()
```

Returns the NIF identifier string. Cheap round-trip used by tests to
confirm the native library actually loaded.

# `window_size`

```elixir
@spec window_size(non_neg_integer()) ::
  {:ok,
   {non_neg_integer(), non_neg_integer(), non_neg_integer(), non_neg_integer()}}
  | error()
```

Reads `fd`'s window size via `TIOCGWINSZ`. Returns
`{:ok, {rows, cols, xpixel, ypixel}}` on success.

---

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