|
| 1 | +# CLAUDE.md |
| 2 | + |
| 3 | +This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository. |
| 4 | + |
| 5 | +## Commands |
| 6 | + |
| 7 | +```bash |
| 8 | +make install # create .venv and install dependencies |
| 9 | +make test # full test suite |
| 10 | +make test-<name> # single module, e.g. make test-stack or make test-stack-app |
| 11 | +make run-<name> # import a non-TUI demo module (verifies clean import) |
| 12 | +make run-<name>-app # launch a TUI interactively |
| 13 | +make demo-<name> # produce dark + light mp4s for one TUI (requires vhs, ffmpeg, imagemagick) |
| 14 | +make demo-all # produce all demo videos |
| 15 | +``` |
| 16 | + |
| 17 | +Valid short `<name>` aliases: `bst`, `deque`, `dict`, `dll`, `graph`, `heap`, `list`, `networkx`, `queue`, `set`, `sll`, `stack`, `trie`. App variants: `stack-app`, `queue-app`, `deque-app`, `list-app`, `sll-app`, `dll-app`. |
| 18 | + |
| 19 | +Single test without make: `.venv/bin/pytest tests/test_stack_demo.py -v` |
| 20 | + |
| 21 | +Font override for demo videos: `VHS_FONT_FAMILY="SF Mono" make demo-stack` |
| 22 | + |
| 23 | +## Architecture |
| 24 | + |
| 25 | +### Data structure modules (`data_structures/`) |
| 26 | + |
| 27 | +One module per topic, named `<topic>_demo.py` or `<topic>.py`. Modules contain only class definitions — no `__main__` block — so `make run-<name>` just verifies a clean import. The exception is TUI apps under `data_structures/tui/`, which are runnable as `python -m data_structures.tui.<app>`. |
| 28 | + |
| 29 | +### TUI layer (`data_structures/tui/`) |
| 30 | + |
| 31 | +Two patterns exist side by side: |
| 32 | + |
| 33 | +- **`stack_app.py`** — standalone, self-contained. Defines its own model, panel widget, and command dispatcher. Does not inherit from the shared base. |
| 34 | +- **All other TUI apps** — inherit from `BaseLinearStructureTUI` in `common.py`. The base provides the Textual widget layout, shared command dispatcher (`/random`, `/clear`, `/save`, `/load`, `/undo`, `/redo`, `/show`, `/type`, scroll, `/help`), undo/redo snapshots, and type-constraint enforcement. Subclasses override `STRUCTURE_NAME`, `START_LABEL`/`END_LABEL`, `get_items()`, `append_values()`, `clear_structure()`, `replace_items()`, `handle_structure_command()`, `help_lines()`, and `placeholder_text()`. |
| 35 | + |
| 36 | +`/help` output convention: structure-specific commands first under `--- <Name> ---`, then common commands under `--- Common ---`. Command verbs use `[cyan]...[/cyan]` Rich markup; argument placeholders stay outside the markup span. |
| 37 | + |
| 38 | +All TUIs support `/search VALUE`. Linked-list TUIs additionally expose positional and node-id–based insert/remove commands. |
| 39 | + |
| 40 | +### Demo video pipeline (`scripts/run_vhs.py`) |
| 41 | + |
| 42 | +Two-stage process: |
| 43 | +1. `vhs` renders the raw terminal interaction from a `.tape` file in `demos/`. |
| 44 | +2. `run_vhs.py` post-processes the raw video: selects a platform-appropriate font (macOS → `Menlo`, Linux → `DejaVu Sans Mono`), overrides the output path, trims the slow launch, adds an opening title card and ending card (via ImageMagick), and burns lower-right captions from `# CAPTION:` comments in the tape. |
| 45 | + |
| 46 | +Caption pipeline: `parse_commands()` → `scale_commands()` → `build_command_caption_cues()` → `burn_captions_into_video()`. |
| 47 | + |
| 48 | +The timing constants near the top of `run_vhs.py` (`INTRO_SECONDS`, `OUTRO_SECONDS`, `LAUNCH_TRIM_SECONDS`) are the main levers for video pacing. `INTERTITLE_SECONDS` and `LIVE_HOLD_SECONDS` are legacy knobs not currently active. |
| 49 | + |
| 50 | +Each TUI has a single canonical tape file: `demos/<name>.tape`. The `--mode dark|light` flag on `run_vhs.py` injects the appropriate theme and appends `-dark` or `-light` to the output filename. Dark theme: `TokyoNight`. Light theme: `Catppuccin Latte`. |
| 51 | + |
| 52 | +### Tests (`tests/`) |
| 53 | + |
| 54 | +One `test_<module>.py` per source module. `conftest.py` adds a `temporary_recursion_limit` fixture and a post-collection summary of test counts per file. `pytest.ini` sets `pythonpath = .` so `data_structures` and `scripts` are importable without installation. |
0 commit comments