termtosvg (Rust port)
THIS IS A PROTOTYPE PORT. DOCUMENTATION MAY BE INCORRECT AND API FUNCTIONALITY MAY BE DIFFERENT THAN EXPECTED. USE AT YOUR OWN RISK.
I am uploading this to crates.io as a test commit to simply see if the following SVG renders in an animated fashion there.
This is ported from the original Python code, and uses a custom test harness to verify the outputs match up.
This crate is a clean-room Rust reimplementation of the original Python termtosvg. It records an interactive terminal session and renders it to a standalone SVG animation (or a still frame) using the same SVG templates shipped with the upstream project.
Quick start
Record a session and emit an SVG in one step (defaults to the powershell
template):
Record only, keeping the asciicast for later:
Render an existing asciicast with a specific template and still frame mode:
Pipe any command into termtosvg and it will render the incoming text (ANSI
colors included) without spawning a child shell:
|
To render an asciicast streamed on stdin, pass - as the input file:
|
Rendering from stdin (examples)
You can render asciicast data streamed on stdin using the render - form:
# render an asciicast file piped to stdin
|
# or with an installed binary
|
If you pipe raw terminal output (not an asciicast) into the program without
using the render subcommand, the Rust binary will treat the bytes on stdin
as raw terminal output and render a single o event containing that data.
This is convenient for single-shot captures where you don't have a cast file:
|
To explicitly force parsing stdin as an asciicast when piping into the default
invocation, use /dev/stdin as the input filename for compatibility with the
original Python implementation:
|
--template accepts either a built-in template name (no .svg extension) or a
path to a custom SVG template.
Templates
The original templates are vendored under old.python/termtosvg/data/templates
and embedded in the binary via include_dir!. The following template names are
available out-of-the-box (all of them are pure SVG/CSS animations that remain
GitHub-safe):
base16_default_darkdraculagjm8gjm8_playgjm8_single_looppowershellprogress_barputtysolarized_darksolarized_lightterminal_appubuntuwindow_framewindow_frame_powershellxterm
The legacy window_frame_js template relied on the Web Animations API and
inline JavaScript. GitHub strips those scripts, so it is no longer bundled nor
supported by the Rust renderer.
Using a built-in template by name
Using a template from disk
Customizing a template
- Copy any SVG from
old.python/termtosvg/data/templatesto a new location. - Edit the
<style id="user-style">block for colors/fonts or add additional SVG/JS elements as described inold.python/man/termtosvg-templates.md. - Pass the path to
--templatewhen rendering.
The renderer preserves everything in the template except for the
generated-style, generated-js, and #screen subtree, so any additional UI
you add will show up in the final SVG.
Template parity tests
The parity test renders every default (GitHub-safe) template with both the Python reference renderer and this Rust binary, then compares the DOMs. Run it whenever you modify the renderer or the bundled templates:
Set TERMTOSVG_REFERENCE_BIN if your Python binary is not located at
.venv/bin/termtosvg. The test automatically sets the namespace so both
renderers produce identical SVG attributes.