Resetting asciinema with Scroll Stacking
Obsah
Your asciinema recording looks broken: newlines don’t work, old text gets overwritten, or the screen fills with garbage. This simple tutorial shows how to reset the terminal screen mid-recording using scroll stacking. Fix messy casts without starting over - just edit the file!
Why You Need This #
Newlines fail and text overwrites because terminals have scrollback limits and state corruption during long recordings. Commands like ls or cat print without proper line wrapping, leaving a cluttered screen that ruins playback. Scroll stacking resets the terminal to a clean state at any point (like 12.5 seconds) so your demo continues fresh.
Common problems this fixes:
- Lost newlines: Output stacks on one line instead of wrapping
- Scrollback overflow: Old commands stay visible when they shouldn’t
- State corruption: Colors, cursor position, or margins get messed up
- Multi-step demos: Want clean breaks between sections in one file
How Scroll Stacking Works #
Instead of clear (which only erases visible screen), ESC c (\u001bc) does a full terminal reset - clears screen, resets margins, cursor, colors, everything. The [12.5, “o”, “\u001bc”] event injects this at timestamp 12.5 seconds during playback.
Quick Fix Steps #
- Backup your
demo.castfile - Open in any text editor (VS Code, nano, etc.)
- Find where mess starts (check timestamps)
- Add this exact line on its own:
[12.5, "o", "\u001bc"]
- Save and play:
asciinema play -s=10 demo.cast(increase speed ten fold)
Before/After Example #
Broken cast (newlines lost, text overwritten):
[0.0, "o", "dir1/"]
[1.2, "o", "file1 file2 file3"] // Should be new line!
[2.1, "o", "pwd"] // Overwrites above
Fixed with reset:
[0.0, "o", "dir1/"]
[1.2, "o", "file1 file2 file3"]
[12.5, "o", "\u001bc"] // ← Screen resets here
[13.0, "o", "pwd"] // Fresh clean screen