TermUI.Terminal.InputReader (TermUI v1.0.0)

View Source

GenServer that reads keyboard input from stdin and sends events to a target process.

Spawns a linked blocking IO reader so its GenServer remains responsive, parses escape sequences, and emits normalized event structs to the configured target process. The port field retains its historical name but stores the reader PID in 1.0.

Usage

{:ok, reader} = InputReader.start_link(target: self())
# Events will be sent as {:input, %Event.Key{}}

Escape Sequence Handling

Some sequences are ambiguous (ESC alone vs ESC followed by another key). The reader uses a timeout (default 50ms) to disambiguate - if no more bytes arrive within the timeout, a lone ESC is emitted.

Summary

Functions

Returns a specification to start this module under a supervisor.

Starts the InputReader.

Stops the InputReader.

Types

t()

@type t() :: %TermUI.Terminal.InputReader{
  buffer: binary(),
  port: port() | nil,
  target: pid(),
  timer_ref: reference() | nil
}

Functions

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

start_link(opts)

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

Starts the InputReader.

Options

  • :target - PID to receive events (required)
  • :name - GenServer name (optional)

stop(server)

@spec stop(GenServer.server()) :: :ok

Stops the InputReader.