2 pygments.formatters.terminal
3 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
5 Formatter for terminal output with ANSI sequences.
7 :copyright: Copyright 2006-2023 by the Pygments team, see AUTHORS.
8 :license: BSD, see LICENSE for details.
13 Number, Operator, Generic, Token, Whitespace
18__all__ = [
'TerminalFormatter']
26 Whitespace: (
'gray',
'brightblack'),
27 Comment: (
'gray',
'brightblack'),
29 Keyword: (
'blue',
'brightblue'),
41 Name.Tag: (
'brightblue',
'brightblue'),
42 String: (
'yellow',
'yellow'),
43 Number: (
'blue',
'brightblue'),
52 Error: (
'_brightred_',
'_brightred_'),
58 Format tokens with ANSI color sequences, for output in a text console.
59 Color sequences are terminated at newlines, so that paging the output
62 The `get_style_defs()` method doesn't do anything special since there is
63 no support for common styles.
68 Set to ``"light"`` or ``"dark"`` depending on the terminal's background
69 (default: ``"light"``).
72 A dictionary mapping token types to (lightbg, darkbg) color names or
73 ``None`` (default: ``None`` = use builtin colorscheme).
76 Set to ``True`` to have line numbers on the terminal output as well
77 (default: ``False`` = no line numbers).
80 aliases = [
'terminal',
'console']
85 self.
darkbg = get_choice_opt(options,
'bg',
86 [
'light',
'dark'],
'light') ==
'dark'
91 def format(self, tokensource, outfile):
103 while colors
is None:
106 return colors[self.
darkbg]
112 for ttype, value
in tokensource: