TermUI.Terminal.InputReader (TermUI v0.2.0)

View Source

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

Uses a port to read from stdin in a non-blocking way. Parses escape sequences and emits Event.Key structs to the configured target process.

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.