> ## Documentation Index
> Fetch the complete documentation index at: https://docs.declaw.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Visual effects showcase

> Rainbow banner, truecolor gradients, spinner, progress bar, and Matrix rain — all rendered inside the sandbox and streamed to your terminal.

A sequence of seven visual effects generated entirely inside a
sandbox VM and streamed byte-for-byte through the PTY to your local
terminal. The script uses nothing but Python stdlib and raw ANSI
escape codes — no curses, no ncurses, no external deps.

## Use case

Stress-test the PTY stream with rapid output, truecolor sequences,
cursor movement, and full-screen rewrites. If every effect renders
cleanly, you can trust the SSE pipe for any TUI workload an agent
might produce.

## What you'll learn

* Uploading a program with `sbx.files.write()` to avoid stdin echo
* 256-colour and 24-bit truecolor rendering via ANSI escapes
* Animated spinner and progress bar with `\r` line replacement
* Box-drawing table output
* Matrix-style rain with cursor-up rewriting (`\e[8A`)
* Combining `python3 /tmp/show.py && exit` in a single PTY send

## Prerequisites

<Snippet file="snippets/env-setup.mdx" />

```bash theme={null}
pip install declaw
```

## Code walkthrough

The driver uploads a show program and runs it through one PTY
session:

```python theme={null}
with Sandbox.create(template="python") as sbx:
    sbx.files.write("/tmp/show.py", SHOW_PROGRAM)

    handle = sbx.pty.create(
        size=PtySize(cols=100, rows=32),
        on_data=lambda b: (
            sys.stdout.buffer.write(b),
            sys.stdout.buffer.flush(),
        ),
        timeout=120,
    )
    handle.send_stdin("python3 /tmp/show.py && exit\n")
    result = handle.wait(timeout=60)
```

The `SHOW_PROGRAM` (embedded in the source file) runs seven acts:

| # | Effect                | Technique                             |
| - | --------------------- | ------------------------------------- |
| 1 | Rainbow DECLAW banner | 256-colour `\e[38;5;Nm` per character |
| 2 | Horizontal gradient   | 24-bit truecolor `\e[48;2;R;G;Bm`     |
| 3 | Braille spinner       | `\r` line replace, 40 frames          |
| 4 | Progress bar          | `\r` overwrite with `%` counter       |
| 5 | Box-drawing table     | `+--+` style with colour              |
| 6 | Matrix rain           | 8-row 60-frame animation via `\e[8A`  |
| 7 | Sign-off message      | Plain truecolor text                  |

## Running it

Run in an **xterm-compatible** terminal (iTerm2, Alacritty, Kitty,
modern Terminal.app, or any tmux pane):

```bash theme={null}
export DECLAW_API_KEY="your-api-key"
export DECLAW_DOMAIN="api.declaw.ai"
python cookbook/examples/pty-showcase/main.py
```

The full show takes about 8 seconds. You will see the banner paint
character by character, the gradient fill, the spinner tick through
its braille frames, the progress bar crawl to 100%, a stats table
render, and finally Matrix-style green rain scroll down for a few
seconds.

The closing message reads:

```
 every byte you just saw was generated inside a declaw sandbox,
 streamed over SSE, and rendered by your local terminal.
```

## Full source

See `cookbook/examples/pty-showcase/main.py` in the repo.
