# pan menu — Interactive Tree Menu

Displays a hierarchical menu from JSON input and lets the user navigate, expand/collapse branches, and select a leaf node.

## Usage

```
pan menu [OPTIONS] [FILE]
```

## Arguments

| Argument | Description                             |
|----------|-----------------------------------------|
| `FILE`   | Path to input file (reads stdin if empty)|

## Options

| Flag               | Default              | Description                        |
|--------------------|----------------------|------------------------------------|
| `-f`, `--format`   | `auto`               | Input format: auto, json, plano    |
| `-t`, `--title`    | `"Menú"`             | Title in the popup header          |
| `-W`, `--width`    | `0` (auto)           | Popup width                        |
| `-H`, `--height`   | `0` (auto)           | Popup height                       |
| `--guide`          |                      | Show this guide                    |

## Format detection

When `--format auto` (default), the format is detected from the file extension:

| Extension | Format |
|-----------|--------|
| `.json`   | json   |
| other     | plano  |

For stdin (no FILE argument), defaults to `plano`.

## Input formats

### JSON

```json
[
  {
    "id": 1,
    "text": "Option 1",
    "children": [
      { "id": 2, "text": "Sub-option 1" }
    ]
  }
]
```

| Field      | Type     | Description                              |
|------------|----------|------------------------------------------|
| `id`       | number   | Unique id (required, must be unique)     |
| `text`     | string   | Display text                             |
| `children` | array    | Optional nested nodes                    |

### Plano

One path per line, segments separated by `/`:

```
Archivo/Nuevo/Documento
Archivo/Abrir
Editar/Deshacer
```

Ids are auto-generated. No comments.

## Output

On selection, prints the full path from root to leaf, segments joined by `/`:

```
Editar/Deshacer/Deshacer escritura
```

## Exit codes

| Code | Meaning                          |
|------|----------------------------------|
| 0    | Selection made (text on stdout)  |
| 1    | User cancelled (no output)       |

## Capturing output

See [PANDORA_GUIDE.md](./PANDORA_GUIDE.md#capturing-output) for all capture patterns applicable to every interactive subcommand.

## Examples

```bash
# JSON file (auto-detected)
pan menu menu.json

# Plano file (auto-detected from .txt)
pan menu menu.txt

# Explicit format
pan menu -f plano menu.txt

# Pipe stdin (defaults to plano)
printf 'Archivo/Nuevo\nArchivo/Abrir\n' | pan menu

# Custom title
pan menu menu.json -t "Projects"

# Explicit size
pan menu menu.json -W 60 -H 20
```

## Mouse

- **Click item**: select that item
- **Drag**: click and hold the border or title bar to move the popup

## Keyboard

| Key              | Action                          |
|------------------|---------------------------------|
| `↑` / `k`        | Navigate up                     |
| `↓` / `j`        | Navigate down                   |
| `Tab`            | Navigate down                   |
| `Shift+Tab`      | Navigate up                     |
| `Enter`          | Expand/collapse branch, or select leaf |
| `→` / `Space`    | Expand branch                   |
| `←`              | Collapse branch                 |
| `gg`             | Go to first item                |
| `G`              | Go to last item                 |
| `Esc` / `q`      | Cancel                          |
| `Ctrl` + `c`     | Emergency exit                  |
