Metadata-Version: 2.4
Name: ptyreel
Version: 0.3.0
Summary: Record scripted terminal sessions as self-contained animated SVGs.
Author: Paxton-Meny
License:                                  Apache License
                                   Version 2.0, January 2004
                                http://www.apache.org/licenses/
        
           TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
        
           1. Definitions.
        
              "License" shall mean the terms and conditions for use, reproduction,
              and distribution as defined by Sections 1 through 9 of this document.
        
              "Licensor" shall mean the copyright owner or entity authorized by
              the copyright owner that is granting the License.
        
              "Legal Entity" shall mean the union of the acting entity and all
              other entities that control, are controlled by, or are under common
              control with that entity. For the purposes of this definition,
              "control" means (i) the power, direct or indirect, to cause the
              direction or management of such entity, whether by contract or
              otherwise, or (ii) ownership of fifty percent (50%) or more of the
              outstanding shares, or (iii) beneficial ownership of such entity.
        
              "You" (or "Your") shall mean an individual or Legal Entity
              exercising permissions granted by this License.
        
              "Source" form shall mean the preferred form for making modifications,
              including but not limited to software source code, documentation
              source, and configuration files.
        
              "Object" form shall mean any form resulting from mechanical
              transformation or translation of a Source form, including but
              not limited to compiled object code, generated documentation,
              and conversions to other media types.
        
              "Work" shall mean the work of authorship, whether in Source or
              Object form, made available under the License, as indicated by a
              copyright notice that is included in or attached to the work
              (an example is provided in the Appendix below).
        
              "Derivative Works" shall mean any work, whether in Source or Object
              form, that is based on (or derived from) the Work and for which the
              editorial revisions, annotations, elaborations, or other modifications
              represent, as a whole, an original work of authorship. For the purposes
              of this License, Derivative Works shall not include works that remain
              separable from, or merely link (or bind by name) to the interfaces of,
              the Work and Derivative Works thereof.
        
              "Contribution" shall mean any work of authorship, including
              the original version of the Work and any modifications or additions
              to that Work or Derivative Works thereof, that is intentionally
              submitted to Licensor for inclusion in the Work by the copyright owner
              or by an individual or Legal Entity authorized to submit on behalf of
              the copyright owner. For the purposes of this definition, "submitted"
              means any form of electronic, verbal, or written communication sent
              to the Licensor or its representatives, including but not limited to
              communication on electronic mailing lists, source code control systems,
              and issue tracking systems that are managed by, or on behalf of, the
              Licensor for the purpose of discussing and improving the Work, but
              excluding communication that is conspicuously marked or otherwise
              designated in writing by the copyright owner as "Not a Contribution."
        
              "Contributor" shall mean Licensor and any individual or Legal Entity
              on behalf of whom a Contribution has been received by Licensor and
              subsequently incorporated within the Work.
        
           2. Grant of Copyright License. Subject to the terms and conditions of
              this License, each Contributor hereby grants to You a perpetual,
              worldwide, non-exclusive, no-charge, royalty-free, irrevocable
              copyright license to reproduce, prepare Derivative Works of,
              publicly display, publicly perform, sublicense, and distribute the
              Work and such Derivative Works in Source or Object form.
        
           3. Grant of Patent License. Subject to the terms and conditions of
              this License, each Contributor hereby grants to You a perpetual,
              worldwide, non-exclusive, no-charge, royalty-free, irrevocable
              (except as stated in this section) patent license to make, have made,
              use, offer to sell, sell, import, and otherwise transfer the Work,
              where such license applies only to those patent claims licensable
              by such Contributor that are necessarily infringed by their
              Contribution(s) alone or by combination of their Contribution(s)
              with the Work to which such Contribution(s) was submitted. If You
              institute patent litigation against any entity (including a
              cross-claim or counterclaim in a lawsuit) alleging that the Work
              or a Contribution incorporated within the Work constitutes direct
              or contributory patent infringement, then any patent licenses
              granted to You under this License for that Work shall terminate
              as of the date such litigation is filed.
        
           4. Redistribution. You may reproduce and distribute copies of the
              Work or Derivative Works thereof in any medium, with or without
              modifications, and in Source or Object form, provided that You
              meet the following conditions:
        
              (a) You must give any other recipients of the Work or
                  Derivative Works a copy of this License; and
        
              (b) You must cause any modified files to carry prominent notices
                  stating that You changed the files; and
        
              (c) You must retain, in the Source form of any Derivative Works
                  that You distribute, all copyright, patent, trademark, and
                  attribution notices from the Source form of the Work,
                  excluding those notices that do not pertain to any part of
                  the Derivative Works; and
        
              (d) If the Work includes a "NOTICE" text file as part of its
                  distribution, then any Derivative Works that You distribute must
                  include a readable copy of the attribution notices contained
                  within such NOTICE file, excluding those notices that do not
                  pertain to any part of the Derivative Works, in at least one
                  of the following places: within a NOTICE text file distributed
                  as part of the Derivative Works; within the Source form or
                  documentation, if provided along with the Derivative Works; or,
                  within a display generated by the Derivative Works, if and
                  wherever such third-party notices normally appear. The contents
                  of the NOTICE file are for informational purposes only and
                  do not modify the License. You may add Your own attribution
                  notices within Derivative Works that You distribute, alongside
                  or as an addendum to the NOTICE text from the Work, provided
                  that such additional attribution notices cannot be construed
                  as modifying the License.
        
              You may add Your own copyright statement to Your modifications and
              may provide additional or different license terms and conditions
              for use, reproduction, or distribution of Your modifications, or
              for any such Derivative Works as a whole, provided Your use,
              reproduction, and distribution of the Work otherwise complies with
              the conditions stated in this License.
        
           5. Submission of Contributions. Unless You explicitly state otherwise,
              any Contribution intentionally submitted for inclusion in the Work
              by You to the Licensor shall be under the terms and conditions of
              this License, without any additional terms or conditions.
              Notwithstanding the above, nothing herein shall supersede or modify
              the terms of any separate license agreement you may have executed
              with Licensor regarding such Contributions.
        
           6. Trademarks. This License does not grant permission to use the trade
              names, trademarks, service marks, or product names of the Licensor,
              except as required for reasonable and customary use in describing the
              origin of the Work and reproducing the content of the NOTICE file.
        
           7. Disclaimer of Warranty. Unless required by applicable law or
              agreed to in writing, Licensor provides the Work (and each
              Contributor provides its Contributions) on an "AS IS" BASIS,
              WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
              implied, including, without limitation, any warranties or conditions
              of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
              PARTICULAR PURPOSE. You are solely responsible for determining the
              appropriateness of using or redistributing the Work and assume any
              risks associated with Your exercise of permissions under this License.
        
           8. Limitation of Liability. In no event and under no legal theory,
              whether in tort (including negligence), contract, or otherwise,
              unless required by applicable law (such as deliberate and grossly
              negligent acts) or agreed to in writing, shall any Contributor be
              liable to You for damages, including any direct, indirect, special,
              incidental, or consequential damages of any character arising as a
              result of this License or out of the use or inability to use the
              Work (including but not limited to damages for loss of goodwill,
              work stoppage, computer failure or malfunction, or any and all
              other commercial damages or losses), even if such Contributor
              has been advised of the possibility of such damages.
        
           9. Accepting Warranty or Additional Liability. While redistributing
              the Work or Derivative Works thereof, You may choose to offer,
              and charge a fee for, acceptance of support, warranty, indemnity,
              or other liability obligations and/or rights consistent with this
              License. However, in accepting such obligations, You may act only
              on Your own behalf and on Your sole responsibility, not on behalf
              of any other Contributor, and only if You agree to indemnify,
              defend, and hold each Contributor harmless for any liability
              incurred by, or claims asserted against, such Contributor by reason
              of your accepting any such warranty or additional liability.
        
           END OF TERMS AND CONDITIONS
        
           APPENDIX: How to apply the Apache License to your work.
        
              To apply the Apache License to your work, attach the following
              boilerplate notice, with the fields enclosed by brackets "[]"
              replaced with your own identifying information. (Don't include
              the brackets!)  The text should be enclosed in the appropriate
              comment syntax for the file format. We also recommend that a
              file or class name and description of purpose be included on the
              same "printed page" as the copyright notice for easier
              identification within third-party archives.
        
           Copyright 2026 Paxton-Meny
        
           Licensed under the Apache License, Version 2.0 (the "License");
           you may not use this file except in compliance with the License.
           You may obtain a copy of the License at
        
               http://www.apache.org/licenses/LICENSE-2.0
        
           Unless required by applicable law or agreed to in writing, software
           distributed under the License is distributed on an "AS IS" BASIS,
           WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
           See the License for the specific language governing permissions and
           limitations under the License.
        
Project-URL: Homepage, https://github.com/Paxton-Meny/PtyReel
Project-URL: Changelog, https://github.com/Paxton-Meny/PtyReel/blob/main/CHANGELOG.md
Keywords: terminal,pty,svg,animation,documentation
Classifier: Development Status :: 3 - Alpha
Classifier: Environment :: Console
Classifier: License :: OSI Approved :: Apache Software License
Classifier: Operating System :: POSIX
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Topic :: Documentation
Classifier: Topic :: Terminals :: Terminal Emulators/X Terminals
Requires-Python: >=3.11
Description-Content-Type: text/markdown
License-File: LICENSE
Dynamic: license-file

# PtyReel

[![ci](https://github.com/Paxton-Meny/PtyReel/actions/workflows/ci.yml/badge.svg?branch=main)](https://github.com/Paxton-Meny/PtyReel/actions/workflows/ci.yml)
[![action self-test](https://github.com/Paxton-Meny/PtyReel/actions/workflows/action.yml/badge.svg?branch=main)](https://github.com/Paxton-Meny/PtyReel/actions/workflows/action.yml)
[![CodeQL](https://github.com/Paxton-Meny/PtyReel/actions/workflows/github-code-scanning/codeql/badge.svg)](https://github.com/Paxton-Meny/PtyReel/security/code-scanning)
[![release](https://img.shields.io/github/v/release/Paxton-Meny/PtyReel)](https://github.com/Paxton-Meny/PtyReel/releases)
[![pypi](https://img.shields.io/pypi/v/ptyreel)](https://pypi.org/project/ptyreel/)
[![python](https://img.shields.io/python/required-version-toml?tomlFilePath=https%3A%2F%2Fraw.githubusercontent.com%2FPaxton-Meny%2FPtyReel%2Fmain%2Fpyproject.toml)](https://github.com/Paxton-Meny/PtyReel/blob/main/pyproject.toml)
[![license](https://img.shields.io/github/license/Paxton-Meny/PtyReel)](LICENSE)

Record scripted terminal sessions as self-contained animated SVGs, using only
the Python standard library.

You write a `.tape` file describing a session (type this, wait, press that).
PtyReel plays it inside a real pseudo-terminal, captures the output with its
timing and colors, and renders an animated SVG you can drop straight into a
README or docs site. No browser, no GIF encoder, no dependencies: a consumer
adds the action or runs the module, and gets living documentation of their
actual CLI.

![A terminal session recorded by PtyReel](demos/out/hello.svg)

That image is the output of [demos/hello.tape](demos/hello.tape). It animates
with CSS alone, so it plays inside a README where scripts never run.

## Status

Early development, released as `v0.3.0`. The tape format and the rendered
output may change in any 0.x release, so pin a full version if that matters to
you and read the changelog before upgrading.

## Requirements

Python 3.11 or newer on a POSIX system. Linux, macOS, or WSL. There are no
dependencies: the runtime, the tests and the quality gate use only the standard
library. Windows is a development platform only, because `pty` does not exist
there.

## Use it as an action

```yaml
- uses: actions/checkout@v4
- uses: Paxton-Meny/PtyReel@v0
  with:
    tape: demos/hello.tape
```

| Input | Default | What it does |
| --- | --- | --- |
| `tape` | required | Path to the `.tape` file, relative to the workspace. |
| `output` | tape's own path | Where to write the SVG, relative to the workspace. |
| `check` | `false` | Validate the tape and stop. Nothing runs, nothing is written. |
| `workspace` | the checkout | Directory every path must stay inside. |

| Output | What it holds |
| --- | --- |
| `svg-path` | Workspace-relative path of the rendered SVG. Empty when `check` is true. |

Rendering runs the commands in the tape, so treat a tape with the same care as
a workflow file. Validating every tape on a pull request costs a second and
needs no terminal:

```yaml
- uses: Paxton-Meny/PtyReel@v0
  with:
    tape: demos/hello.tape
    check: true
```

## Use it from a shell

Install it from PyPI, ideally into its own environment with `pipx`, or with
`pip`:

```bash
pipx install ptyreel
```

```bash
pip install ptyreel
```

Then render a tape:

```bash
ptyreel demos/hello.tape
```

`python -m ptyreel` runs the same command.

```
usage: ptyreel [-h] [--workspace DIR] [--output PATH] [--check] [--version]
               TAPE [TAPE ...]
```

Each rendered path is printed on standard output. Errors go to standard error
and name the file and the line:

```
ptyreel: demos/hello.tape:7: Sleep needs a duration such as 250ms or 2s, got '500'
```

Exit codes are 0 for success, 1 for a reported error, 2 for a usage mistake,
and 130 for an interrupt.

## Use it as a git hook

Checking a tape runs nothing and takes a fraction of a second, so a hook can
catch a broken tape before it is committed. Rendering does not belong in a
hook: it runs the tape's commands and plays every pause in real time, so leave
that to a person or to the action.

With [pre-commit](https://pre-commit.com), add the `ptyreel-check` hook to
`.pre-commit-config.yaml`. It ships from 0.3.0. Pin a full version rather than
`v0`, because pre-commit caches a repository by its `rev` and would never see
the moving tag change. `pre-commit autoupdate` moves the pin to the latest
release:

```yaml
repos:
  - repo: https://github.com/Paxton-Meny/PtyReel
    rev: v0.3.0
    hooks:
      - id: ptyreel-check
```

Without it, install PtyReel and save this as `.git/hooks/pre-commit`, then make
it executable. The same script works as `.git/hooks/pre-push`:

```sh
#!/bin/sh
tapes=$(git ls-files '*.tape')
[ -z "$tapes" ] || exec ptyreel --check $tapes
```

## Tape syntax

One directive per line. Blank lines are ignored. `#` starts a comment unless it
sits inside a quoted string. `Output`, `Require` and `Set` must all come before
the first action, which is what lets a tape be checked completely before
anything runs.

### Configuration

| Directive | Argument | Default | Meaning |
| --- | --- | --- | --- |
| `Output` | relative `.svg` path | required | Where the image is written. |
| `Require` | command name | none | Fail early if this is not on the path. Repeatable. |
| `Set Shell` | `"bash"` | `bash` | Shell to run. |
| `Set FontSize` | 8 to 40 | `15` | Text size in pixels. Drives every other measurement. |
| `Set Width` | 320 to 4096 | `900` | Image width in pixels. |
| `Set Height` | 200 to 4096 | `550` | Image height in pixels. |
| `Set Padding` | 0 to 64 | `24` | Gap between the window edge and the text. |
| `Set TypingSpeed` | 1ms to 2s | `55ms` | Delay between typed characters. |
| `Set Theme` | `"github-dark"`, `"github-light"` | `github-dark` | Palette. |
| `Set Title` | quoted text | `"bash"` | Title bar text. |
| `Set Loop` | `true`, `false` | `true` | Whether the animation replays for ever. |
| `Set LoopDelay` | 0 to 30s | `2500ms` | How long the finished session rests before a replay. |
| `Set MaskSecrets` | `true`, `false` | `true` | Redact values of secret-looking environment variables. |
| `Set Anonymize` | `true`, `false` | `true` | Record as a generic machine rather than as yours. |

### Actions

| Directive | Argument | Meaning |
| --- | --- | --- |
| `Type` | quoted text | Send characters one at a time, as a person typing. |
| `Enter` `Tab` `Space` `Backspace` `Escape` | none | Send that key. |
| `Up` `Down` `Left` `Right` `Home` `End` | none | Send that key. |
| `PageUp` `PageDown` `Delete` | none | Send that key. |
| `Ctrl+<letter>` | none | Send a control character, such as `Ctrl+C`. |
| `Sleep` | 1ms to 30s | Hold still and keep reading output. |
| `Hide` / `Show` | none | Stop and resume recording without stopping the session. |

Durations always carry a unit, `ms` or `s`. Inside `Type`, the escapes `\"`,
`\\`, `\n` and `\t` resolve; anything else after a backslash is an error.

`Hide` is for setup a reader does not need to watch:

```
Hide
Type "cd example && export PAGER=cat"
Enter
Sleep 300ms
Show
```

### Limits

A tape is refused if it exceeds any of these, and the message names the line.

| Limit | Value |
| --- | --- |
| Tape file | 64 KiB |
| Instructions | 500 |
| Characters per `Type` | 1000 |
| Declared timing, typing and sleeping added up | 120 s |
| Output read from the terminal | 8 MiB |
| Rendered image | 4 MiB |

## How it works

```
tape text  ->  parse and validate      no terminal is opened until this passes
           ->  play in a pty           a real shell, a real terminal size
           ->  screen model            text, colour, cursor, scrolling
           ->  render                  one CSS animated SVG
           ->  write                   atomically, inside the workspace
```

The timeline comes from the tape, not from the clock. A tape declares how fast
it types and how long it waits, so the same tape run twice against the same
program produces the same bytes. A rendered demo is therefore something a
repository can hold and check rather than something that churns on every run.

Real time still passes and still bounds the session. It simply never reaches
the recording.

### What the screen model handles

Text, tabs, backspace, carriage return and newline. Cursor movement, erasing a
line or the screen, and colour and text attributes. Scrolling moves the window
rather than losing text, and a line that gets rewritten is replaced rather than
drawn over, so progress bars and prompt redraws come out right.

![Thirty lines of output scrolling through a nine-row window](demos/out/scroll.svg)

That one is [demos/scroll.tape](demos/scroll.tape): output taller than the
window, so the content slides up as the session runs.

Not supported, and consumed without corrupting the text around it: the
alternate screen buffer, background colours, and the 256 colour and true colour
forms of `SGR 38` and `SGR 48`. Full screen programs are out of scope.

## Security

A tape runs shell commands by design, so it carries the same trust as the
workflow that renders it. Three things follow from that, and all three are
enforced rather than advised.

The shell gets a short allowlist of environment variables. A workflow token is
not present inside a session at all, which is what keeps it out of a committed
image. Redaction is a second line, not the first.

Output paths are validated as strings, then walked one directory at a time
through open descriptors that refuse to follow a symbolic link. Nothing is
written outside the workspace, and nothing dotted, so `.git` is unreachable.

Every character that reaches the document is filtered and escaped. XML has no
representation for most control characters, so they are removed rather than
escaped. The output holds no script, no external reference and no font.

### Recording as a generic machine

A rendered image is made to be published, so by default the session is recorded
as somebody generic. `$USER`, `$HOME` and `~` read as `LocalUser` and
`/home/LocalUser`, and the answers `whoami`, `id` and `hostname` give are
substituted on the way out, because those ask the kernel and no environment
variable can change them. The session also runs with a fresh home directory of
its own, so a tape cannot leave anything behind in your real one.

The working directory is not rewritten. A demo usually runs inside the project
it is demonstrating and that path is meant to be seen, though a project living
under your home has the home part replaced like any other path. Turn the whole
thing off with `Set Anonymize false` when you want the real machine on screen.

See [SECURITY.md](SECURITY.md) to report a problem.

## Repository layout

```
action.yml              the GitHub Action interface
.pre-commit-hooks.yaml  the check-only hook for pre-commit
src/ptyreel/            tape parsing, terminal model, pty driver, renderer
tests/                  unittest suite mirroring src/
demos/                  .tape sources and their rendered output
hooks/                  plain git hooks that run the quality gate
.github/                CI, the PyPI release workflow and its pinned tools
```

## Contributing

This is a personal project and **pull requests are not accepted**, including
small ones. Issues are welcome and are the supported way to report a bug or
suggest a feature. Please do not spend your time on a change that will be
closed unmerged.

Running the gate needs nothing installed. One command is the whole of it:

```bash
python -m compileall -q src tests && python -m unittest discover -s tests
```

See [CONTRIBUTING.md](CONTRIBUTING.md) for the rest.

## License

Apache-2.0.
