SVG & HTML exports

You may have noticed the screenshots used throughout this documentation. Fun fact: They are all generated using the module! Some code is run, and its result is then displayed in an SVG image.

To do this, we use the Termage module, which in turn uses the Terminal.record method, and then calls Recorder.export_svg on the resulting terminal.

To use the recording & export API, simply enter a Terminal.record context, run some code & save the recording output:

from pytermgui import ColorPicker, pretty, terminal, tim

tim.alias("code", "@black #auto dim")

with terminal.record() as recording:
    tim.print("[italic]Everything[/] you print will be captured!")
    tim.print()
    tim.print(
        "By default, only [code]PTG[/]'s prints functions are affected,"
        + "\nbut by overwriting [code]sys.stdout.write[/] you can capture any Python output."
    )

docs/src/exports1.py Everything  you print will be captured! By default, only  PTG 's prints functions are affected, but by overwriting  sys.stdout.write  you can capture any Python output.

You can even hide the "window"'s title bar, and get a rectangular image with just your code's output by specifying chrome=False while exporting:

Everything  you print will be captured! By default, only  PTG 's prints functions are affected, but by overwriting  sys.stdout.write  you can capture any Python output.

Note

You can also export as plain HTML! We can't easily show it here (without manually pasting it in) since Termage and its plugin only wrap the SVG API.

For more information, check out the Termage module!