How TermGIF works
How a recording becomes a GIF, the script syntax, and how to shrink the file.
How is the GIF made?
The recording output goes into the xterm.js screen model in order. It follows where each character, color and the cursor sit at every moment.
At a fixed interval the screen state is read and drawn on a canvas. A frame equal to the one before is merged and only its time is added.
The frames are reduced to a 256 color palette and packed as a GIF. Only the changed area is rewritten, so the file stays small.
How do I record a .cast file?
Install asciinema and run asciinema rec demo.cast. A shell opens. Work as usual and end with exit.
Drop the demo.cast file into this tool. It reads v2 and v3 and uses the output events only.
Input keys, markers and resize events are skipped. The size at the start is used to the end.
How do I write a script?
A line starting with $ is typed after the prompt one key at a time, then Enter is pressed. Any other line prints as output.
@size 80x16 sets columns and rows. @type 45 sets milliseconds per key. @wait 800 sets a pause.
@prompt changes the prompt and @clear wipes the screen. Write color as \e[32m in the text and reset it with \e[0m.
How do I shrink the file?
An idle limit of 2 seconds cuts long waits down to 2 seconds. A higher speed shortens the whole clip.
Fewer columns and rows give a smaller picture. A wide screen shrinks the font to fit the width.
Bursts of output add frames. Recording only the part you need saves the most.
How do I put it in a README?
Commit the downloaded GIF to your repository and point to its path with the Markdown image syntax.
On a blog, upload it as an image. This tool only makes the GIF and does not host it.
What it cannot do
It cannot carry sound, the mouse or input key overlays. A recording that resizes mid-run is drawn at the starting size.
It uses a monospace font on your device, so glyph shapes differ a little between machines.
A GIF has 256 colors, so gradients can look rough. Terminal text is usually fine.