Use termtosvg to screencast your terminal

Posted by Fabrice on Wednesday, April 24, 2019 Updated on Monday, July 10, 2023 Translation: fr

A terminal contains only text information (if we except exploits such as w3m). Therefore, it is common to just paste those term information when it comes to show some CLI behaviour.

However, once the Pandora box of terminals is opened, yet another world reveals itself: ncurse. It is common to represent static elements with it using a screenshot, however as I already complained about it in another post. It is not a fully satisfactory solution as we also loose all the text information, and it is thus impossible to copy a part of the screen content without typing it again (or OCRise the screenshot?).

Nicolas Bedos comes with a solution for this named termtosvg. This small python program is available on pip as well as github.

It’s quite straighforward to use, just invoke it in your favorite terminal emulator:


and it will save the resulting image in your temporary folder. You can also specify a target file, the geometry of the terminal you want to save, the template, etc.

A simple example:

termtosvg -g "82x19" -t progress_bar


termtosvg: sl

Then you can simply embed it on your webpage as an example:

<object data="/examples/termtosvg-sl.svg">replacement text</object>  

Warning: The resulting file is saved with read rights only to the owner of the file. Don’t forget to fix this before uploading the file. Doing otherwise may lead you to some surprises.

Remark: tested on firefox: you can also embed it as an image, but then you loose interactions and the possibility to select text, as you can see in the following example I used in this post produces by

termtosvg -g "82x30" -t window_frame_js

Image embedding
An example of broken decorations

To conclude, this method is still young and not yet perfect (especially, web browsers are not optimized for it yet, and firefox is showing me some reluctance to render those animations sometimes), but it is an interesting way to show some interactive contents in a terminal (which is not just a text game). It seems to be doable to synchronize the content of it with sound using javascript embedding in SVGs to produce a full-fledged screencast with selectable content, but may require some works not to mess up synchronizations.

tags: termtosvg