Linx.Tty.Native (Linx v0.1.0)

Copy Markdown View Source

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.

Summary

Types

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.

Functions

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

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.

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

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

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

Types

error()

@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.

Functions

open_controlling_raw()

@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(fd, saved)

@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(fd, ws)

@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()

@spec version() :: binary()

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

window_size(fd)

@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.