|
| 1 | +# Recording PSTui GIFs with `tuirec` |
| 2 | + |
| 3 | +Use this guide to (re)generate the animated GIFs in the README and docs. The |
| 4 | +recorder is [`tui-cs/tuirec`](https://github.com/tui-cs/tuirec) — a Go CLI that |
| 5 | +spawns a process in a PTY, injects keystrokes, records an asciinema cast, and |
| 6 | +renders a GIF via `agg`. This is the PSTui-specific companion to |
| 7 | +[Terminal.Gui's `Scripts/tuirec/README.md`](https://github.com/tui-cs/Terminal.Gui/blob/main/Scripts/tuirec/README.md); |
| 8 | +read that for the full keystroke-token reference. |
| 9 | + |
| 10 | +## Install |
| 11 | + |
| 12 | +```bash |
| 13 | +# Requires Go 1.22+. agg is auto-downloaded on first use. |
| 14 | +go install github.com/tui-cs/tuirec/cmd/tuirec@latest |
| 15 | +export PATH="$(go env GOPATH)/bin:$PATH" # tuirec installs to GOPATH/bin |
| 16 | +tuirec --version |
| 17 | +``` |
| 18 | + |
| 19 | +## How PSTui differs from recording a Terminal.Gui app |
| 20 | + |
| 21 | +PSTui cmdlets are driven from a **PowerShell pipeline**, not a `ScenarioRunner` |
| 22 | +DLL. Two consequences shape every recipe here: |
| 23 | + |
| 24 | +1. **Record a script file, not `-Command`.** `tuirec --args` is **comma-split**, |
| 25 | + and PowerShell pipelines are full of commas (`Select-Object a, b, c`). So the |
| 26 | + demos live in small `*.ps1` files in this folder and are run with `-File`: |
| 27 | + |
| 28 | + ```bash |
| 29 | + --binary pwsh --args "-NoLogo,-NoProfile,-File,./Scripts/tuirec/demo-ocgv.ps1" |
| 30 | + ``` |
| 31 | + |
| 32 | +2. **The pwsh REPL does not render under a recording PTY** — only the |
| 33 | + Terminal.Gui app it launches does. So you cannot record "type a command, press |
| 34 | + Enter, watch ocgv open." Instead each demo script *is* the scenario: it imports |
| 35 | + PSTui and invokes the cmdlet(s) directly, and `tuirec` drives the resulting |
| 36 | + TUI. (This is why the F7 demo records the history picker directly — see below.) |
| 37 | + |
| 38 | +The demo scripts: |
| 39 | + |
| 40 | +| Script | Records | |
| 41 | +|--------|---------| |
| 42 | +| `demo-ocgv.ps1` | `ls \| ocgv` then the `killp` process picker → `hero.gif` | |
| 43 | +| `demo-shot.ps1` | `Get-Process \| shot` tree exploration → `shot.gif` | |
| 44 | +| `demo-f7.ps1` | the `F7` command-history picker → `f7history.gif` | |
| 45 | + |
| 46 | +## Composing keystrokes |
| 47 | + |
| 48 | +Same token syntax as Terminal.Gui (`wait:<ms>`, `CursorDown`, `Enter`, `Esc`, |
| 49 | +`Tab`, backtick-quoted `` `literal text` ``). PSTui notes: |
| 50 | + |
| 51 | +- **Type into the filter with `-Focus Filter`.** `ocgv` (and the F7 picker) take |
| 52 | + a `-Focus Filter` parameter so keystrokes land in the filter box and rows |
| 53 | + narrow *live* — the best thing to show. Then `Esc` (or `Enter` to select). |
| 54 | +- **`shot` has no `-Focus`; use `-FullScreen`.** The tree's inline render is |
| 55 | + finicky to position; `-FullScreen` gives a clean top-anchored capture. The |
| 56 | + first root is focused on open — `CursorRight` expands, `CursorDown` navigates. |
| 57 | +- **Quote the keystrokes in single quotes** (bash *and* PowerShell) so backtick |
| 58 | + literals survive: `ks='wait:1500,`src`,wait:2000,Escape'`. |
| 59 | +- **`killp` is safe in recordings** — `demo-ocgv.ps1` `Esc`s out of the picker, |
| 60 | + so no process is ever killed. |
| 61 | + |
| 62 | +## Recipes |
| 63 | + |
| 64 | +Run from the repo root. PSTui must be importable (`Install-Module PSTui`, or it |
| 65 | +auto-resolves from the built `./module`). |
| 66 | + |
| 67 | +### `hero.gif` — `ls | ocgv` + `killp` |
| 68 | + |
| 69 | +```bash |
| 70 | +export PATH="$(go env GOPATH)/bin:$PATH" |
| 71 | +ks='wait:1600,`src`,wait:2200,Escape,wait:2200,`Finder`,wait:2200,Escape,wait:1500' |
| 72 | +tuirec record --binary pwsh \ |
| 73 | + --args "-NoLogo,-NoProfile,-File,./Scripts/tuirec/demo-ocgv.ps1" \ |
| 74 | + --name hero --title "PSTui — ocgv" \ |
| 75 | + --keystrokes "$ks" \ |
| 76 | + --startup-delay 3200 --drain 1500 --cols 100 --rows 28 --keystroke-delay 140 |
| 77 | +cp artifacts/hero.gif docs/PSTui/hero.gif |
| 78 | +``` |
| 79 | + |
| 80 | +### `shot.gif` — `Get-Process | shot` |
| 81 | + |
| 82 | +```bash |
| 83 | +ks='wait:1800,CursorDown,CursorDown,CursorDown,CursorDown,CursorDown,wait:1500,CursorUp,CursorUp,CursorUp,CursorUp,CursorUp,wait:600,CursorRight,wait:1800,CursorDown,CursorDown,CursorDown,CursorDown,wait:1500,Escape,wait:1000' |
| 84 | +tuirec record --binary pwsh \ |
| 85 | + --args "-NoLogo,-NoProfile,-File,./Scripts/tuirec/demo-shot.ps1" \ |
| 86 | + --name shot --title "PSTui — Show-ObjectTree (shot)" \ |
| 87 | + --keystrokes "$ks" \ |
| 88 | + --startup-delay 3200 --drain 1200 --cols 100 --rows 28 |
| 89 | +cp artifacts/shot.gif docs/PSTui/shot.gif |
| 90 | +``` |
| 91 | + |
| 92 | +### `f7history.gif` — the F7 command-history picker |
| 93 | + |
| 94 | +```bash |
| 95 | +ks='wait:1700,`Get`,wait:2200,`-S`,wait:2000,Escape,wait:1200' |
| 96 | +tuirec record --binary pwsh \ |
| 97 | + --args "-NoLogo,-NoProfile,-File,./Scripts/tuirec/demo-f7.ps1" \ |
| 98 | + --name f7history --title "PSTui — F7 command history" \ |
| 99 | + --keystrokes "$ks" \ |
| 100 | + --startup-delay 3200 --drain 1500 --cols 100 --rows 22 --keystroke-delay 130 |
| 101 | +cp artifacts/f7history.gif docs/PSTui/f7history.gif |
| 102 | +``` |
| 103 | + |
| 104 | +## Validate |
| 105 | + |
| 106 | +`tuirec` writes to `artifacts/` (git-ignored); commit the copies under |
| 107 | +`docs/PSTui/`. |
| 108 | + |
| 109 | +```bash |
| 110 | +# No errors leaked into the cast: |
| 111 | +grep -iE "error|not recognized|exception" artifacts/<name>.cast |
| 112 | + |
| 113 | +# Not blank — eyeball a middle frame (needs python3 + Pillow): |
| 114 | +python3 -c "from PIL import Image; im=Image.open('artifacts/<name>.gif'); print(im.n_frames,'frames'); im.seek(im.n_frames//2); im.convert('RGB').save('/tmp/mid.png')" |
| 115 | +``` |
| 116 | + |
| 117 | +A good recording is **> ~20 KB** with several frames; a near-blank capture is a |
| 118 | +few KB / 2–3 frames (usually means keystrokes went to the wrong focus, or the |
| 119 | +target produced no output). |
| 120 | + |
| 121 | +## Troubleshooting |
| 122 | + |
| 123 | +| Problem | Cause | Fix | |
| 124 | +|---------|-------|-----| |
| 125 | +| "recording has no output events" / blank | Recording the bare pwsh REPL (it doesn't render in the PTY) | Record a demo `.ps1` that invokes the cmdlet directly | |
| 126 | +| Keystrokes seem ignored | Focus is on the tree/table, not the filter | `ocgv`: add `-Focus Filter`. `shot`: `Tab` to the tree, or it starts focused | |
| 127 | +| `shot` renders mid-screen / empty | Inline tree positioning | Use `-FullScreen` | |
| 128 | +| `--args` parsed into too many args | Commas in the PowerShell got split | Move the pipeline into a `-File` script (see above) | |
| 129 | +| Backtick literal text dropped | Shell ate the backticks | Single-quote the whole `ks='...'` | |
0 commit comments