Sprites.Command (Sprites v0.1.0)
View SourceRepresents a running command on a sprite.
Uses a GenServer to manage the WebSocket connection via gun. Messages are sent to the owner process:
{:stdout, command, data}- stdout data received{:stderr, command, data}- stderr data received{:exit, command, exit_code}- command completed{:error, command, reason}- error occurred
Supports two execution modes:
- Direct mode (default) — opens a new WebSocket per command to
/exec - Control mode — multiplexes over a persistent WebSocket to
/control
Summary
Functions
Waits for command completion.
Returns a specification to start this module under a supervisor.
Closes stdin (sends EOF).
Resizes the TTY.
Runs a command synchronously (blocking).
Returns {output, exit_code}.
Starts a command asynchronously.
Writes to stdin.
Types
@type t() :: %Sprites.Command{ owner: pid(), pid: pid(), ref: reference(), sprite: Sprites.Sprite.t(), tty_mode: boolean() }
Functions
@spec await(t(), timeout()) :: {:ok, non_neg_integer()} | {:error, term()}
Waits for command completion.
Returns a specification to start this module under a supervisor.
See Supervisor.
@spec close_stdin(t()) :: :ok
Closes stdin (sends EOF).
@spec resize(t(), pos_integer(), pos_integer()) :: :ok
Resizes the TTY.
@spec run(Sprites.Sprite.t(), String.t(), [String.t()], keyword()) :: {binary(), non_neg_integer()}
Runs a command synchronously (blocking).
Returns {output, exit_code}.
@spec start(Sprites.Sprite.t(), String.t(), [String.t()], keyword()) :: {:ok, t()} | {:error, term()}
Starts a command asynchronously.
Writes to stdin.