ElixirOpentui.Input (ElixirOpentui v0.2.0)

Copy Markdown View Source

Parses raw terminal input bytes into structured key and mouse events.

Handles:

  • Regular characters (UTF-8)
  • Control keys (Ctrl+A through Ctrl+Z)
  • Escape sequences (arrows, function keys, home/end, etc.)
  • SGR mouse events (\e[<...M/m)
  • Bracketed paste (\e[200~ ... \e[201~)
  • Kitty keyboard protocol CSI u sequences (\e[codepoint;modifier:event_type u)
  • xterm modifyOtherKeys (\e[27;modifier;keycode~)
  • Capability query responses (\e[?{flags}u)

Summary

Functions

Parse a chunk of raw terminal input into a list of events.

Types

capability_event()

@type capability_event() :: %{
  :type => :capability,
  :capability => atom(),
  optional(atom()) => term()
}

event()

@type event() :: key_event() | mouse_event() | paste_event() | capability_event()

key_event()

@type key_event() :: %{
  type: :key,
  key: atom() | String.t(),
  ctrl: boolean(),
  alt: boolean(),
  shift: boolean(),
  meta: boolean()
}

mouse_event()

@type mouse_event() :: %{
  type: :mouse,
  action: :press | :release | :move | :scroll_up | :scroll_down,
  button: :left | :right | :middle | :none,
  x: non_neg_integer(),
  y: non_neg_integer(),
  ctrl: boolean(),
  alt: boolean(),
  shift: boolean()
}

paste_event()

@type paste_event() :: %{type: :paste, data: String.t()}

Functions

parse(data)

@spec parse(binary()) :: [event()]

Parse a chunk of raw terminal input into a list of events.