]>
jfr.im git - dlqueue.git/blob - venv/lib/python3.11/site-packages/pip/_vendor/pygments/formatters/irc.py
2 pygments.formatters.irc
3 ~~~~~~~~~~~~~~~~~~~~~~~
5 Formatter for IRC output
7 :copyright: Copyright 2006-2023 by the Pygments team, see AUTHORS.
8 :license: BSD, see LICENSE for details.
11 from pip
._vendor
.pygments
.formatter
import Formatter
12 from pip
._vendor
.pygments
.token
import Keyword
, Name
, Comment
, String
, Error
, \
13 Number
, Operator
, Generic
, Token
, Whitespace
14 from pip
._vendor
.pygments
.util
import get_choice_opt
17 __all__
= ['IRCFormatter']
20 #: Map token types to a tuple of color values for light and dark
25 Whitespace
: ('gray', 'brightblack'),
26 Comment
: ('gray', 'brightblack'),
27 Comment
.Preproc
: ('cyan', 'brightcyan'),
28 Keyword
: ('blue', 'brightblue'),
29 Keyword
.Type
: ('cyan', 'brightcyan'),
30 Operator
.Word
: ('magenta', 'brightcyan'),
31 Name
.Builtin
: ('cyan', 'brightcyan'),
32 Name
.Function
: ('green', 'brightgreen'),
33 Name
.Namespace
: ('_cyan_', '_brightcyan_'),
34 Name
.Class
: ('_green_', '_brightgreen_'),
35 Name
.Exception: ('cyan', 'brightcyan'),
36 Name
.Decorator
: ('brightblack', 'gray'),
37 Name
.Variable
: ('red', 'brightred'),
38 Name
.Constant
: ('red', 'brightred'),
39 Name
.Attribute
: ('cyan', 'brightcyan'),
40 Name
.Tag
: ('brightblue', 'brightblue'),
41 String
: ('yellow', 'yellow'),
42 Number
: ('blue', 'brightblue'),
44 Generic
.Deleted
: ('brightred', 'brightred'),
45 Generic
.Inserted
: ('green', 'brightgreen'),
46 Generic
.Heading
: ('**', '**'),
47 Generic
.Subheading
: ('*magenta*', '*brightmagenta*'),
48 Generic
.Error
: ('brightred', 'brightred'),
50 Error
: ('_brightred_', '_brightred_'),
63 'green': 7, #compat w/ ansi
66 'brightcyan': 9, # compat w/ ansi
69 'red': 11, # compat w/ ansi
76 def ircformat(color
, text
):
80 if '_' in color
: # italic
83 color
= color
.strip('_')
84 if '*' in color
: # bold
87 color
= color
.strip('*')
88 # underline (\x1F) not supported
89 # backgrounds (\x03FF,BB) not supported
90 if len(color
) > 0: # actual color - may have issues with ircformat("red", "blah")+"10" type stuff
91 add
+= '\x03' + str(IRC_COLOR_MAP
[color
]).zfill(2)
93 return add
+ text
+ sub
94 return '<'+add
+'>'+text
+'</'+sub
+'>'
97 class IRCFormatter(Formatter
):
99 Format tokens with IRC color sequences
101 The `get_style_defs()` method doesn't do anything special since there is
102 no support for common styles.
107 Set to ``"light"`` or ``"dark"`` depending on the terminal's background
108 (default: ``"light"``).
111 A dictionary mapping token types to (lightbg, darkbg) color names or
112 ``None`` (default: ``None`` = use builtin colorscheme).
115 Set to ``True`` to have line numbers in the output as well
116 (default: ``False`` = no line numbers).
119 aliases
= ['irc', 'IRC']
122 def __init__(self
, **options
):
123 Formatter
.__init
__(self
, **options
)
124 self
.darkbg
= get_choice_opt(options
, 'bg',
125 ['light', 'dark'], 'light') == 'dark'
126 self
.colorscheme
= options
.get('colorscheme', None) or IRC_COLORS
127 self
.linenos
= options
.get('linenos', False)
130 def _write_lineno(self
, outfile
):
133 outfile
.write("%04d: " % self
._lineno
)
135 def format_unencoded(self
, tokensource
, outfile
):
136 self
._write
_lineno
(outfile
)
138 for ttype
, value
in tokensource
:
139 color
= self
.colorscheme
.get(ttype
)
142 color
= self
.colorscheme
.get(ttype
)
144 color
= color
[self
.darkbg
]
145 spl
= value
.split('\n')
146 for line
in spl
[:-1]:
148 outfile
.write(ircformat(color
, line
))
150 self
._write
_lineno
(outfile
)
152 outfile
.write(ircformat(color
, spl
[-1]))