Packages

Multi-surface application runtime for Elixir. One TEA module renders to terminal, browser (LiveView), SSH, and MCP (agents). 30+ widgets, flexbox + CSS grid, AI agent runtime, distributed swarm with CRDTs, time-travel debugging, session recording, sandboxed REPL, and agentic commerce.

Current section

Files

Jump to
raxol lib raxol headless event_builder.ex
Raw

lib/raxol/headless/event_builder.ex

defmodule Raxol.Headless.EventBuilder do
@moduledoc """
Builds `Raxol.Core.Events.Event` structs from simple inputs.
Designed for headless session interaction where callers send keystrokes
without constructing full Event structs manually.
"""
alias Raxol.Core.Events.Event
@doc """
Builds a key event from a character string or atom.
## Examples
EventBuilder.key("q")
EventBuilder.key(:tab)
EventBuilder.key("c", ctrl: true)
"""
@spec key(String.t() | atom(), keyword()) :: Event.t()
def key(key, opts \\ [])
def key(char, opts) when is_binary(char) do
data =
%{key: :char, char: char}
|> maybe_add_modifier(:ctrl, opts)
|> maybe_add_modifier(:alt, opts)
|> maybe_add_modifier(:shift, opts)
Event.new(:key, data)
end
def key(special, opts) when is_atom(special) do
data =
%{key: special}
|> maybe_add_modifier(:ctrl, opts)
|> maybe_add_modifier(:alt, opts)
|> maybe_add_modifier(:shift, opts)
Event.new(:key, data)
end
defp maybe_add_modifier(data, modifier, opts) do
if Keyword.get(opts, modifier, false) do
Map.put(data, modifier, true)
else
data
end
end
end