Sprites.Command (Sprites v0.1.0)

View Source

Represents 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

t()

@type t() :: %Sprites.Command{
  owner: pid(),
  pid: pid(),
  ref: reference(),
  sprite: Sprites.Sprite.t(),
  tty_mode: boolean()
}

Functions

await(command, timeout \\ :infinity)

@spec await(t(), timeout()) :: {:ok, non_neg_integer()} | {:error, term()}

Waits for command completion.

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

close_stdin(command)

@spec close_stdin(t()) :: :ok

Closes stdin (sends EOF).

resize(command, rows, cols)

@spec resize(t(), pos_integer(), pos_integer()) :: :ok

Resizes the TTY.

run(sprite, command, args, opts \\ [])

@spec run(Sprites.Sprite.t(), String.t(), [String.t()], keyword()) ::
  {binary(), non_neg_integer()}

Runs a command synchronously (blocking). Returns {output, exit_code}.

start(sprite, command, args, opts \\ [])

@spec start(Sprites.Sprite.t(), String.t(), [String.t()], keyword()) ::
  {:ok, t()} | {:error, term()}

Starts a command asynchronously.

write_stdin(command, data)

@spec write_stdin(t(), iodata()) :: :ok | {:error, term()}

Writes to stdin.