Skip to main content

A Sphinx extension for rendering terminal input and output.

Project description

sphinx-terminal

sphinx-terminal allows you to display terminal input and output in your Sphinx documentation.

Basic usage

To display terminal input and output in your Sphinx document, use the terminal directive, providing input and output as follows:

.. terminal::

    input

    output

Input can span multiple lines, as long as the lines are in the same paragraph. Everything after the first blank line in the directive's body is rendered as output.

The prompt defaults to user@host:~$. To customize this, use the :user:, :host:, and :dir: options.

.. terminal::
    :user: author
    :host: canonical
    :dir: ~/path

    echo 'hello'

    hello

To render only the output of a command, include the :output-only: flag in the directive's options.

.. terminal::
    :output-only:

    This is rendered as output.

To enable a copy button for users, include the :copy: flag as a directive option. Only the input can be copied.

.. terminal::
    :copy:

    echo 'hello'

    hello

Similarly, to make the output scrollable, include the :scroll: flag as a directive option.

.. terminal::
    :scroll:

    echo 'hello'

    hello

Project setup

sphinx-terminal is published on PyPI and can be installed with:

pip install sphinx-terminal

After adding sphinx-terminal to your Python project, update Sphinx's conf.py file to include sphinx-terminal as one of its extensions:

extensions = [
    "sphinx_terminal"
]

The copy button functionality depends on sphinx-copybutton. sphinx-terminal automatically adds this extension to your Sphinx project and configures it to copy terminal input and ignore the multiline prompt.

copybutton_selector = "span.copybutton, div:not(.terminal-code) > div.highlight > pre"
copybutton_prompt_text = "> |"
copybutton_prompt_is_regexp = True

Customizing these configurations in your conf.py file overrides the defaults assigned by sphinx-terminal.

Community and support

You can report any issues or bugs on the project's GitHub repository.

If you're interested in contributing, start with the contribution guide.

sphinx-terminal is covered by the Ubuntu Code of Conduct.

License and copyright

sphinx-terminal is released under the GPL-3.0 license.

© 2025 Canonical Ltd.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

sphinx_terminal-1.0.2.tar.gz (95.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

sphinx_terminal-1.0.2-py3-none-any.whl (20.1 kB view details)

Uploaded Python 3

File details

Details for the file sphinx_terminal-1.0.2.tar.gz.

File metadata

  • Download URL: sphinx_terminal-1.0.2.tar.gz
  • Upload date:
  • Size: 95.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for sphinx_terminal-1.0.2.tar.gz
Algorithm Hash digest
SHA256 87baeaf96a5ca6454591b711990436022f2deb05d1c8388081fd2905857dc7e9
MD5 99ac54f647452c19fbe66907d4ee17b1
BLAKE2b-256 c0b1c197de61c813ab3a45bb4aa800c9fcb4956afdfebb2607aa3b629b9e0a57

See more details on using hashes here.

Provenance

The following attestation bundles were made for sphinx_terminal-1.0.2.tar.gz:

Publisher: release-publish.yaml on canonical/sphinx-terminal

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file sphinx_terminal-1.0.2-py3-none-any.whl.

File metadata

File hashes

Hashes for sphinx_terminal-1.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 c14b9a2c9ecae8b52dfdb54ba9db5642c978348c110858deca77bf9e7eafc680
MD5 8cf7b3b0dc81d7866cb6b915f27ae98e
BLAKE2b-256 e4c3c7e05aef0c40a18504efc3f0ea7c95e45c487c70f4b137000c0911c63e7b

See more details on using hashes here.

Provenance

The following attestation bundles were made for sphinx_terminal-1.0.2-py3-none-any.whl:

Publisher: release-publish.yaml on canonical/sphinx-terminal

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page