Debian Codegraph @

doc/docs/terminal-sessions.rst

raw
1 =================
2 Terminal sessions
3 =================
4
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>`_.
8
9 They are typically command lines or code, mixed with generic output.
10
11 Examples for each can be found in the :doc:`lexer <lexers>` documentation.
12
13
14 Operating system shells
15 -----------------------
16
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.
19
20 They are typically named ``<shell> Session``.
21
22
23 Interactive consoles
24 --------------------
25
26 Similarly to systems shells, Pygments recognize a variety of interactive
27 language sessions.
28
29 Their IDs typically follow the ``<language>-console`` or
30 ``<language>-repl`` pattern.
31
32
33 Generic output
34 --------------
35
36 To display standalone terminal output and keep styling consistent, you can use
37 the generic ``output`` lexer.
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.