TERMTOSVG-TEMPLATES(5)
β¨ TERMTOSVG-TEMPLATES β¨
okay bestie, so this is the manual for termtosvg-templates β the 5 file section, meaning it's about file formats and conventions, not a command you run π
. This is the whole tea on SVG templates for termtosvg. Grab a snack, we're going in π
πΈ NAME πΈ
termtosvg-templates β SVG templates for termtosvg π
π¦ DESCRIPTION π¦
so templates are just SVG files, right? and termtosvg embeds animations inside them. that's the whole vibe. and using templates means you can, like:
- have user defined terminal color themes and fonts π¨
- add a terminal UI or window frame to the animation πͺ
- have interactive animations (for example play/pause buttons) π
the default templates live locally under the /usr/share/termtosvg/data/templates directory, and there's also an online gallery on the upstream homepage at https://nbedos.github.io/termtosvg/pages/templates.html β obsessed, honestly π
π TEMPLATE STRUCTURE π
here's the basic structure of a template, no cap:
<?xml version="1.0" encoding="utf-8"?>
<svg id="terminal" baseProfile="full" viewBox="0 0 656 325" width="656" version="1.1"
xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<defs>
<termtosvg:template_settings xmlns:termtosvg="https://github.com/nbedos/termtosvg">
<termtosvg:screen_geometry columns="82" rows="19"/>
<termtosvg:animation type="css"/>
</termtosvg:template_settings>
<style type="text/css" id="generated-style">
<!-- [snip!] -->
</style>
<style type="text/css" id="user-style">
<!-- [snip!] -->
</style>
</defs>
<svg id="screen" width="656" viewBox="0 0 656 323" preserveAspectRatio="xMidYMin meet">
<!-- [snip!] -->
</svg>
<script type="text/javascript" id="generated-js">
<!-- [snip!] -->
</script>
</svg>
overall, you can identify these pieces π
- an
svgelement with id "terminal" - a
defselement which includes:- a
termtosvgspecifictemplate_settingselement that specifies:- the terminal size (number of columns and rows) for which the template is made
- the animation rendering methods to be used by
termtosvg("css" for CSS or "waapi" for Web Animations API)
- a
styleelement with id "generated-style" that will be overwritten bytermtosvg - another
styleelement with id "user-style" that should contain at least the terminal color theme. this element is defined by the template creator and won't be overwritten bytermtosvgπ βοΈ
- a
- an inner
svgelement with id "screen" which will contain the animation produced bytermtosvg - a
scriptelement with id "generated-js" that will be overwritten bytermtosvg("waapi" rendering method only)
π TEMPLATE CUSTOMIZATION π
the basic idea behind template customization is that termtosvg will preserve elements of the template that it does not modify. hence it is possible to:
- customize the style of the animation by modifying the content of the
styleelement with id "user-style" - add a new
scriptelement to embed JavaScript code in the animation - add other SVG elements, as long as they are not children of the
svgelement with id "screen"
i hope that the information provided here together with the code for the default templates is enough to get started with template customization, but feel free to open an issue if you need some help π«Ά
πΈ Custom color theme or font πΈ
terminal color themes must be specified in the style element with id "user-style" and must define all the following classes: foreground, background, color0, color1, ..., color15. font related attributes can also be specified together with the color theme. see below for an example π
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" id="terminal" baseProfile="full" viewBox="0 0 656 325" width="656" version="1.1">
<defs>
<termtosvg:template_settings xmlns:termtosvg="https://github.com/nbedos/termtosvg">
<termtosvg:screen_geometry columns="82" rows="19"/>
</termtosvg:template_settings>
<style type="text/css" id="generated-style">
/* ... Snip! ... */
</style>
<style type="text/css" id="user-style">
.foreground {fill: #c5c5c5;}
.background {fill: #1c1c1c;}
.color0 {fill: #1c1c1c;}
.color1 {fill: #ff005b;}
/* ... Snip! ... */
.color15 {fill: #e5e5e5;}
font-family: Monaco, monospace;
</style>
</defs>
<svg id="screen" width="656" viewBox="0 0 656 323" preserveAspectRatio="xMidYMin meet">
</svg>
</svg>
complete example here: /usr/share/termtosvg/data/templates/gjm8.svg β¨
πͺ Custom terminal UI πͺ
complete example here: /usr/share/termtosvg/data/templates/window_frame.svg
π¨ CSS progress bar π¨
complete example here: /usr/share/termtosvg/data/templates/colors_progress_bar.svg
β‘ Embedding JavaScript β‘
just add your code in a new script element. simple as that π
complete example here: /usr/share/termtosvg/data/templates/window_frame_js.svg
π Restricting the animation to a single loop π
for a template using CSS, simply add a custom style element specifying the number of loops, like so:
<style type="text/css" id="user-style">
#screen_view {
animation-iteration-count:1;
}
</style>
complete example here: /usr/share/termtosvg/data/templates/gjm8_single_loop.svg
π termtosvg internal template usage π
in order to produce the final animation, termtosvg will modify the template in a number of ways. the knowledge of this internal behavior might turn out useful when writing custom templates. lowkey important, ngl π
π Template scaling π
the first step is to scale the template to the right size based on the size of the terminal being recorded and the size of the template specified by the screen_geometry element. for this, termtosvg will update the viewBox, width and height attributes of the svg elements with ids "terminal" and "screen". the height and width attributes of these elements must use pixel units π«‘
termtosvg will also update the columns and rows attributes of the screen_geometry to match the values of the current terminal session and keep things consistent.
π Style update π
next, termtosvg will override the content of the style element with id "generated-style" with its own style sheet. this sheet specifies a few text related attributes. see example below π
<style type="text/css" id="generated-style"><![CDATA[
#screen {
font-family: 'DejaVu Sans Mono', monospace;
font-style: normal;
font-size: 14px;
}
text {
dominant-baseline: text-before-edge;
}]]>
</style>
when set to use CSS animations, termtosvg also defines a single CSS animation for the element with id screen_view. in this case the stylesheet might look like this:
<style type="text/css" id="generated-style"><![CDATA[
#screen {
font-family: 'DejaVu Sans Mono', monospace;
font-style: normal;
font-size: 14px;
}
text {
dominant-baseline: text-before-edge;
}
@keyframes roll {
0.000%{transform:translateY(0px)}
1.426%{transform:translateY(-323px)}
1.953%{transform:translateY(-646px)}
/* Snip! */
96.344%{transform:translateY(-29393px)}
}
#screen_view {
animation-duration: var(--animation-duration);
animation-iteration-count:infinite;
animation-name:roll;
animation-timing-function: steps(1,end);
}
]]></style>
π Script update π
when set to use Web Animations API, termtosvg adds a script element to the SVG that defines the object termtosvg_vars. this object has two attributes named transforms and timings as shown below π
<script type="text/javascript" id="generated-js"><![CDATA[
var termtosvg_vars = {
transforms: [
{transform: 'translate3D(0, 0px, 0)', easing: 'steps(1, end)'},
{transform: 'translate3D(0, -323px, 0)', easing: 'steps(1, end)', offset: 0.014},
{transform: 'translate3D(0, -646px, 0)', easing: 'steps(1, end)', offset: 0.020},
/* Snip! */
{transform: 'translate3D(0, -29393px, 0)', easing: 'steps(1, end)'}
],
timings: {
duration: 27349,
iterations: Infinity
}
};]]></script>
these two attributes should be used in another user-defined script element to create an animation for the element with id "screen_view". here is an abridged example taken from the window_frame_js template:
<script type="text/javascript">
var animation = document.getElementById("screen_view").animate(
termtosvg_vars.transforms,
termtosvg_vars.timings
)
</script>
π Animation update π
finally, termtosvg will overwrite the content of the element svg with id "screen" with the code produced by rendering the terminal session.
in the end, the animation produced by termtosvg has the same structure as the initial template which makes it possible to use an animation as a template (provided the animation was created with termtosvg >= 0.5.0). iconic behavior, truly ππ
π AUTHORS π
Nicolas Bedos.
and that's the whole page bestie β this one's from July 2019, part of termtosvg-templates(5) π go forth and make the prettiest terminal animations, you've got this, periodt π β¨π¦
π¦ where this page comes from
- debian trixie: termtosvg 1.1.0+dfsg-5 Β· BSD-3-Clause
- ubuntu resolute: termtosvg 1.1.0+dfsg-5 Β· BSD-3-Clause
- ubuntu stonking: termtosvg 1.1.0+dfsg-5 Β· BSD-3-Clause
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms