cssterm module

The sphinx_term.cssterm Sphinx extension implements the cssterm directive, which builds cssterm terminal windows. In this section we discuss various aspects of this directive in the context of Jupyter Book. Instructions on how to install and enable the extension are provided here. A technical documentation of this extension can be found in the README file of the so-cool/sphinx-term GitHub repository.

Note

Each example of the cssterm embedded on this page is displayed along the raw Markdown source used to generate it. To switch between the two views use the tabs – Outcome and Syntax – visible above each terminal window.

Simple terminal window

Basic cssterm windows are embedded with the cssterm directive like so:

$ uname -a Darwin MacBook-Pro 19.6.0 Darwin Kernel Version 19.6.0: Thu May 6 00:48:39 PDT 2021; root:xnu-6153.141.33~1/RELEASE_X86_64 x86_64 # dmesg | grep ioDevice + IOAudioDevice[<ptr>]::protectedCompletePowerStateChange() - current = 2 - pending = 2 - IOAudioDevice[<ptr>]::protectedCompletePowerStateChange() - current = 2 - pending = 2 returns 0x0 + IOAudioDevice[<ptr>]::protectedCompletePowerStateChange() - current = 2 - pending = 2 - IOAudioDevice[<ptr>]::protectedCompletePowerStateChange() - current = 2 - pending = 2 returns 0x0 + IOAudioDevice[<ptr>]::audioEngineStarting() - numRunningAudioEngines = 0 - IOAudioDevice[<ptr>]::audioEngineStarting() - numRunningAudioEngines = 1
```{cssterm} cssterm:local
$ uname -a
Darwin MacBook-Pro 19.6.0 Darwin Kernel Version 19.6.0: Thu May  6 00:48:39 PDT 2021; root:xnu-6153.141.33~1/RELEASE_X86_64 x86_64

# dmesg | grep ioDevice
+ IOAudioDevice[<ptr>]::protectedCompletePowerStateChange() - current = 2 - pending = 2
- IOAudioDevice[<ptr>]::protectedCompletePowerStateChange() - current = 2 - pending = 2 returns 0x0
+ IOAudioDevice[<ptr>]::protectedCompletePowerStateChange() - current = 2 - pending = 2
- IOAudioDevice[<ptr>]::protectedCompletePowerStateChange() - current = 2 - pending = 2 returns 0x0
+ IOAudioDevice[<ptr>]::audioEngineStarting() - numRunningAudioEngines = 0
- IOAudioDevice[<ptr>]::audioEngineStarting() - numRunningAudioEngines = 1
```

This approach requires you to list the terminal output directly within the cssterm directive. Additionally, each cssterm window needs to be tagged with an id prefixed with cssterm:, e.g., cssterm:local for the terminal box above.

Loading terminal window from file

Alternatively, the cssterm box can load its content from a file. To this end, the sphinx_term_cssterm_dir Sphinx configuration parameter must point to a directory holding a collection of terminal content files. These files must have .log extensions – see this directory for an example. Then, a .log file is loaded into a cssterm window with a specially formatted tag: the base name of the file prepended with the cssterm: prefix and without the .log extension. For example, for the demo.log file, the corresponding cssterm box is created like so:

$ uname -a Linux ThinkPad-X230.localdomain 3.9.6-301.fc19.x86_64 #1 SMP Mon Jun 17 14:26:26 UTC 2013 x86_64 x86_64 x86_64 GNU/Linux # dmesg | grep sd [135587.413741] sd 27:0:0:0: Attached scsi generic sg1 type 0 [135587.416697] sd 27:0:0:0: [sdb] 2007040 512-byte logical blocks: (1.02 GB/980 MiB) [135587.418130] sd 27:0:0:0: [sdb] Write Protect is off [135587.418140] sd 27:0:0:0: [sdb] Mode Sense: 03 00 00 00 [135587.418944] sd 27:0:0:0: [sdb] No Caching mode page present [135587.418947] sd 27:0:0:0: [sdb] Assuming drive cache: write through [135587.423205] sd 27:0:0:0: [sdb] No Caching mode page present [135587.423211] sd 27:0:0:0: [sdb] Assuming drive cache: write through [135587.424119] sdb: sdb1 sdb2 [135587.428088] sd 27:0:0:0: [sdb] No Caching mode page present [135587.428094] sd 27:0:0:0: [sdb] Assuming drive cache: write through [135587.428098] sd 27:0:0:0: [sdb] Attached SCSI removable disk [135588.336077] SELinux: initialized (dev sdb1, type iso9660), uses genfs_contexts # mkfs.ext4 /dev/sdb1 mke2fs 1.41.12 (17-May-2010) Filesystem label= OS type: Linux Block size=4096 (log=2) Fragment size=4096 (log=2) Stride=0 blocks, Stripe width=0 blocks 245280 inodes, 979456 blocks 48972 blocks (5.00%) reserved for the super user First data block=0 Maximum filesystem blocks=1006632960 30 block groups 32768 blocks per group, 32768 fragments per group 8176 inodes per group Superblock backups stored on blocks: 32768, 98304, 163840, 229376, 294912, 819200, 884736 Writing inode tables: done Creating journal (16384 blocks): done Writing superblocks and filesystem accounting information: done This filesystem will be automatically checked every 20 mounts or 180 days, whichever comes first. Use tune2fs -c or -i to override.
```{cssterm} cssterm:demo
```

Note that if both the terminal file exists and the terminal content is provided directly within the cssterm directive, the latter takes precedence. For example, for the overwrite.log file, the content of the terminal box tagged with cssterm:overwrite will display the explicitly listed code instead of loading its content from the overwrite.log file like so:

$ tree -d . . ├── docs │   └── src │   ├── cssterm_files │   ├── img │   └── text ├── sphinx_term │   └── _static │   ├── cssterm │   │   ├── css │   │   └── scripts │   └── termynal
```{cssterm} cssterm:overwrite
$ tree -d .
.
├── docs
│   └── src
│       ├── cssterm_files
│       ├── img
│       └── text
├── sphinx_term
│   └── _static
│       ├── cssterm
│       │   ├── css
│       │   └── scripts
│       └── termynal
```

Referencing terminal window

Finally, each terminal window can be hyper-linked using the MyST Markdown ref role. To reference a cssterm terminal box with the standard “terminal box” hyper-link use the {ref}`cssterm:tag` syntax, where cssterm:tag is the tag of the destination terminal window.

E.g., see this terminal box.

E.g., see this {ref}`cssterm:local`.

The hyper-link text can also be personalised with the {ref}`custom hyper-link text <cssterm:tag>` syntax.

E.g., see this awesome terminal log.

E.g., see this {ref}`awesome terminal log <cssterm:local>`.