charmbracelet / charmbracelet/vhs

Abort recording if the shell exits

Open
#653 0 comments 0 reactions 0 assignees View on GitHub
enhancement
Dominant language
Go
Stars
20.9k
Forks
474
Avg merge
4d 1h
Merged PRs (30d)
2

Description

It would be nice if the playback of a `.tape` file could be aborted if the shell exits, e.g. due to `set -e` and a command failing, or even due to an explicit `exit`.

At the moment, the shell dies in that situation, but the TTY emulator keeps running, so you get a blinking cursor just sitting there until the tape is completed.

The only workaround I could come up with is a check like this after "critical" commands (the name is just to ensure a slightly nicer error message on failure):

```
Wait@1s /(?.)/
```

But this has to be repeated in any location where a command might fail, and if that command takes a while, then the exact lengths of timeouts become problematic.

Is there a way to detect that the shell has exited, and abort the recording with an error?

Example:

```
Type "set -e" Enter
Sleep 1000 ms
Type "echo hi" Enter
Sleep 1000 ms
Type "false" Enter
Sleep 1000 ms

Type "Hello?" Enter
Sleep 5000 ms
Type "Anybody home?" Enter
Sleep 5000 ms
Type ":("
Sleep 2000 ms
```

Produces a 15 second long result:
![Image](https://github.com/user-attachments/assets/ae8520fe-40c0-49d4-af74-11bca29fe754)

Contributor guide

Open the contributing guide

Research direction

Start by tracing how shell exit status and the TTY emulator are handled during playback of a .tape file. Reproduce the provided set -e example and determine where shell termination can be observed; done means playback aborts promptly with an error instead of waiting for the tape to finish.

Written by the indexing model from the issue text.

Assessment

Tech stack
go
Domain
cli
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.