Cmd.exec Example

Demonstrates running shell commands using Cmd.exec.

Commands in TEA produce messages, not callbacks. When a command completes, the runtime sends a tagged tuple to your update function. Pattern match on the tag to handle success and failure.

Key Concepts

Hotkeys

Usage

ruby examples/widget_cmd_exec/app.rb

How It Works

The update function handles both key presses and command results:

UPDATE = -> (msg, model) do
  case msg
  # Handle command results
  in [:got_output, {stdout:, status: 0}]
    [model.with(result: stdout.strip, loading: false), nil]
  in [:got_output, {stderr:, status:}]
    [model.with(result: "Error (exit #{status}): #{stderr.strip}", loading: false), nil]

  # Handle key presses
  in _ if msg.d?
    [model.with(loading: true), Cmd.exec("ls -la", :got_output)]
  else
    model
  end
end

All logic stays in update. The command just runs and produces a message.

Read the source code →

widget_cmd_exec