|
1 | | -Interactive terminal/shell sessions |
2 | | ------------------------------------ |
| 1 | +================= |
| 2 | +Terminal sessions |
| 3 | +================= |
3 | 4 |
|
4 | | -To highlight an interactive terminal or shell session, prefix your code snippet |
5 | | -with a specially formatted prompt. |
| 5 | +Pygments support the parsing and highlighting of terminal sessions, like |
| 6 | +command-line shells, interactive consoles and language `REPL |
| 7 | +<https://en.wikipedia.org/wiki/Read–eval–print_loop>`_. |
6 | 8 |
|
7 | | -Supported shells with examples are shown below. In each example, prompt parts in |
8 | | -brackets ``[any]`` represent optional parts of the prompt, and prompt parts |
9 | | -without brackets or in parenthesis ``(any)`` represent required parts of the |
10 | | -prompt. |
| 9 | +They are typically command lines or code, mixed with generic output. |
11 | 10 |
|
12 | | -* **Bash Session** (console, shell-session): |
| 11 | +Examples for each can be found in the :doc:`lexer <lexers>` documentation. |
13 | 12 |
|
14 | | - .. code-block:: console |
15 | 13 |
|
16 | | - [any@any]$ ls -lh |
17 | | - [any@any]# ls -lh |
18 | | - [any@any]% ls -lh |
19 | | - $ ls -lh |
20 | | - # ls -lh |
21 | | - % ls -lh |
22 | | - > ls -lh |
| 14 | +Operating system shells |
| 15 | +----------------------- |
23 | 16 |
|
24 | | -* **MSDOS Session** (doscon): |
| 17 | +These lexers are expecting a prompt to identify user input. So to highlight a |
| 18 | +shell session, prefix your code snippet with a specially formatted prompt. |
25 | 19 |
|
26 | | - .. code-block:: doscon |
| 20 | +They are typically named ``<shell> Session``. |
27 | 21 |
|
28 | | - [any]> dir |
29 | | - > dir |
30 | | - More? dir |
31 | 22 |
|
32 | | -* **Tcsh Session** (tcshcon): |
| 23 | +Interactive consoles |
| 24 | +-------------------- |
33 | 25 |
|
34 | | - .. code-block:: tcshcon |
| 26 | +Similarly to systems shells, Pygments recognize a variety of interactive |
| 27 | +language sessions. |
35 | 28 |
|
36 | | - (any)> ls -lh |
37 | | - ? ls -lh |
| 29 | +Their IDs typically follow the ``<language>-console`` or |
| 30 | +``<language>-repl`` pattern. |
38 | 31 |
|
39 | | -* **PowerShell Session** (ps1con): |
40 | 32 |
|
41 | | - .. code-block:: ps1con |
| 33 | +Generic output |
| 34 | +-------------- |
42 | 35 |
|
43 | | - PS[any]> Get-ChildItem |
44 | | - PS> Get-ChildItem |
45 | | - >> Get-ChildItem |
| 36 | +To display standalone terminal output and keep styling consistent, you can use |
| 37 | +the generic ``output`` lexer. |
46 | 38 |
|
| 39 | + |
| 40 | +ANSI rendering |
| 41 | +-------------- |
| 42 | + |
| 43 | +In all the lexers above, the command results are parsed as generic output. |
| 44 | +Which means they are rendered as-is, without any styling applied, for example by ANSI codes. |
| 45 | + |
| 46 | +Here is a couple of third-party projects covering this use-case: |
| 47 | + |
| 48 | +- `pygments-ansi-color |
| 49 | + <https://github.com/chriskuehl/pygments-ansi-color>`_: implements |
| 50 | + a new lexer and formatter to parse and render pure ANSI content. |
| 51 | +- `Click Extra <https://github.com/kdeldycke/click-extra>`_: adds |
| 52 | + `ANSI-capable lexers |
| 53 | + <https://kdeldycke.github.io/click-extra/pygments.html#ansi-language-lexers>`_ |
| 54 | + for each language listed above. |
0 commit comments