.\" Automatically generated by Pandoc 2.17.1.1 .\" .\" Define V font for inline verbatim, using C font in formats .\" that render this, and otherwise B font. .ie "\f[CB]x\f[]"x" \{\ . ftr V B . ftr VI BI . ftr VB B . ftr VBI BI .\} .el \{\ . ftr V CR . ftr VI CI . ftr VB CB . ftr VBI CBI .\} .TH "TERMTOSVG-TEMPLATES" "5" "July 2019" "" "" .hy .SS NAME .PP termtosvg-templates - SVG templates for termtosvg .SS DESCRIPTION .PP templates are SVG files in which termtosvg embeds animations. Using templates makes it possible to: .IP \[bu] 2 Have user defined terminal color themes and fonts .IP \[bu] 2 Add a terminal UI or window frame to the animation .IP \[bu] 2 Have interactive animations (for example play/pause buttons) .PP Default templates can be found locally under the /usr/share/termtosvg/data/templates directory. An online gallery is also available on the upstream homepage at https://nbedos.github.io/termtosvg/pages/templates.html .SS TEMPLATE STRUCTURE .PP Here is the basic structure of a template: .IP .nf \f[C] \f[R] .fi .PP Overall, one can identify: .IP \[bu] 2 An \f[V]svg\f[R] element with id \[lq]terminal\[rq] .IP \[bu] 2 A \f[V]defs\f[R] element which includes: .RS 2 .IP \[bu] 2 A termtosvg specific \f[V]template_settings\f[R] element that specifies: .RS 2 .IP \[bu] 2 the terminal size (number of columns and rows) for which the template is made .IP \[bu] 2 the animation rendering methods to be used by termtosvg (\[lq]css\[rq] for CSS or \[lq]waapi\[rq] for Web Animations API) .RE .IP \[bu] 2 A \f[V]style\f[R] element with id \[lq]generated-style\[rq] that will be overwritten by termtosvg .IP \[bu] 2 Another \f[V]style\f[R] element with id \[lq]user-style\[rq] that should contain at least the terminal color theme. This element is defined by the template creator and won\[cq]t be overwritten by termtosvg .RE .IP \[bu] 2 An inner \f[V]svg\f[R] element with id \[lq]screen\[rq] which will contain the animation produced by termtosvg .IP \[bu] 2 A script element with id \[lq]generated-js\[rq] that will be overwritten by termtosvg (\[lq]waapi\[rq] rendering method only) .SS TEMPLATE CUSTOMIZATION .PP 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 .IP \[bu] 2 Customize the style of the animation by modifying the content of the \f[V]style\f[R] element with id \[lq]user-style\[rq] .IP \[bu] 2 Add a new \f[V]script\f[R] element to embed JavaScript code in the animation .IP \[bu] 2 Add other SVG elements, as long as they are not children of the \f[V]svg\f[R] element with id \[lq]screen\[rq] .PP 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 (https://github.com/nbedos/termtosvg/issues/new) if you need some help. .SS Custom color theme or font .PP Terminal color themes must be specified in the \f[V]style\f[R] element with id \[lq]user-style\[rq] and must define all the following classes: \f[V]foreground\f[R], \f[V]background\f[R], \f[V]color0\f[R], \f[V]color1\f[R], \&..., \f[V]color15\f[R]. Font related attributes can also be specified together with the color theme. See below for an example. .IP .nf \f[C] \f[R] .fi .PP Complete example here: /usr/share/termtosvg/data/templates/gjm8.svg .SS Custom terminal UI .PP Complete example here: /usr/share/termtosvg/data/templates/window_frame.svg .SS CSS progress bar .PP Complete example here: /usr/share/termtosvg/data/templates/colors_progress_bar.svg .SS Embedding JavaScript .PP Just add your code in a new \f[V]script\f[R] element. .PP Complete example here: /usr/share/termtosvg/data/templates/window_frame_js.svg .SS Restricting the animation to a single loop .PP For a template using CSS, simply add a custom style element specifying the number of loops like so: .IP .nf \f[C] \f[R] .fi .PP Complete example here: /usr/share/termtosvg/data/templates/gjm8_single_loop.svg .SS termtosvg internal template usage .PP 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. .SS Template scaling .PP 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 \f[V]screen_geometry\f[R] element. For this, termtosvg will update the \f[V]viewBox\f[R], \f[V]width\f[R] and \f[V]height\f[R] attributes of the \f[V]svg\f[R] elements with ids \[lq]terminal\[rq] and \[lq]screen\[rq]. The \f[V]height\f[R] and \f[V]width\f[R] attributes of these elements must use pixel units. .PP termtosvg will also update the \f[V]columns\f[R] and \f[V]rows\f[R] attributes of the \f[V]screen_geometry\f[R] to match the values of the current terminal session and keep things consistent. .SS Style update .PP Next, termtosvg will override the content of the \f[V]style\f[R] element with id \[lq]generated-style\[rq] with its own style sheet. This sheet specifies a few text related attributes. See example below. .IP .nf \f[C] \f[R] .fi .PP When set to use CSS animations, termtosvg also defines a single CSS animation for the element with id \f[V]screen_view\f[R]. In this case the stylesheet might look like this: .IP .nf \f[C] \f[R] .fi .SS Script update .PP When set to use Web Animations API, termtosvg adds a script element to the SVG that defines the object \f[V]termtosvg_vars\f[R]. This object has two attributes named \f[V]transforms\f[R] and \f[V]timings\f[R] as shown below. .IP .nf \f[C] \f[R] .fi .PP These two attributes should be used in another user-defined script element to create an animation for the element with id \[lq]screen_view\[rq]. Here is an abridged example taken from the window_frame_js template: .IP .nf \f[C] \f[R] .fi .SS Animation update .PP Finally, termtosvg will overwrite the content of the element \f[V]svg\f[R] with id \[lq]screen\[rq] with the code produced by rendering the terminal session. .PP 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). .SH AUTHORS Nicolas Bedos.