diff options
author | orivej <orivej@yandex-team.ru> | 2022-02-10 16:45:01 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:45:01 +0300 |
commit | 2d37894b1b037cf24231090eda8589bbb44fb6fc (patch) | |
tree | be835aa92c6248212e705f25388ebafcf84bc7a1 /contrib/python/Pygments/py3/pygments/formatters | |
parent | 718c552901d703c502ccbefdfc3c9028d608b947 (diff) | |
download | ydb-2d37894b1b037cf24231090eda8589bbb44fb6fc.tar.gz |
Restoring authorship annotation for <orivej@yandex-team.ru>. Commit 2 of 2.
Diffstat (limited to 'contrib/python/Pygments/py3/pygments/formatters')
8 files changed, 220 insertions, 220 deletions
diff --git a/contrib/python/Pygments/py3/pygments/formatters/__init__.py b/contrib/python/Pygments/py3/pygments/formatters/__init__.py index 3e4766d163..66c9e9d404 100644 --- a/contrib/python/Pygments/py3/pygments/formatters/__init__.py +++ b/contrib/python/Pygments/py3/pygments/formatters/__init__.py @@ -19,7 +19,7 @@ from pygments.plugin import find_plugin_formatters from pygments.util import ClassNotFound __all__ = ['get_formatter_by_name', 'get_formatter_for_filename', - 'get_all_formatters', 'load_formatter_from_file'] + list(FORMATTERS) + 'get_all_formatters', 'load_formatter_from_file'] + list(FORMATTERS) _formatter_cache = {} # classes by name _pattern_cache = {} @@ -78,42 +78,42 @@ def get_formatter_by_name(_alias, **options): return cls(**options) -def load_formatter_from_file(filename, formattername="CustomFormatter", - **options): - """Load a formatter from a file. - - This method expects a file located relative to the current working - directory, which contains a class named CustomFormatter. By default, - it expects the Formatter to be named CustomFormatter; you can specify - your own class name as the second argument to this function. - - Users should be very careful with the input, because this method - is equivalent to running eval on the input file. - - Raises ClassNotFound if there are any problems importing the Formatter. - - .. versionadded:: 2.2 - """ - try: - # This empty dict will contain the namespace for the exec'd file - custom_namespace = {} - with open(filename, 'rb') as f: - exec(f.read(), custom_namespace) - # Retrieve the class `formattername` from that namespace - if formattername not in custom_namespace: - raise ClassNotFound('no valid %s class found in %s' % - (formattername, filename)) - formatter_class = custom_namespace[formattername] - # And finally instantiate it with the options - return formatter_class(**options) +def load_formatter_from_file(filename, formattername="CustomFormatter", + **options): + """Load a formatter from a file. + + This method expects a file located relative to the current working + directory, which contains a class named CustomFormatter. By default, + it expects the Formatter to be named CustomFormatter; you can specify + your own class name as the second argument to this function. + + Users should be very careful with the input, because this method + is equivalent to running eval on the input file. + + Raises ClassNotFound if there are any problems importing the Formatter. + + .. versionadded:: 2.2 + """ + try: + # This empty dict will contain the namespace for the exec'd file + custom_namespace = {} + with open(filename, 'rb') as f: + exec(f.read(), custom_namespace) + # Retrieve the class `formattername` from that namespace + if formattername not in custom_namespace: + raise ClassNotFound('no valid %s class found in %s' % + (formattername, filename)) + formatter_class = custom_namespace[formattername] + # And finally instantiate it with the options + return formatter_class(**options) except OSError as err: raise ClassNotFound('cannot read %s: %s' % (filename, err)) except ClassNotFound: - raise - except Exception as err: - raise ClassNotFound('error when loading custom formatter: %s' % err) - - + raise + except Exception as err: + raise ClassNotFound('error when loading custom formatter: %s' % err) + + def get_formatter_for_filename(fn, **options): """Lookup and instantiate a formatter by filename pattern. diff --git a/contrib/python/Pygments/py3/pygments/formatters/_mapping.py b/contrib/python/Pygments/py3/pygments/formatters/_mapping.py index 9d4d37764c..8b5e478e39 100644 --- a/contrib/python/Pygments/py3/pygments/formatters/_mapping.py +++ b/contrib/python/Pygments/py3/pygments/formatters/_mapping.py @@ -76,7 +76,7 @@ if __name__ == '__main__': # pragma: no cover footer = content[content.find("if __name__ == '__main__':"):] # write new file - with open(__file__, 'w') as fp: + with open(__file__, 'w') as fp: fp.write(header) fp.write('FORMATTERS = {\n %s\n}\n\n' % ',\n '.join(found_formatters)) fp.write(footer) diff --git a/contrib/python/Pygments/py3/pygments/formatters/html.py b/contrib/python/Pygments/py3/pygments/formatters/html.py index 11e4e6e128..f3a77a2ddf 100644 --- a/contrib/python/Pygments/py3/pygments/formatters/html.py +++ b/contrib/python/Pygments/py3/pygments/formatters/html.py @@ -40,11 +40,11 @@ def escape_html(text, table=_escape_html_table): return text.translate(table) -def webify(color): - if color.startswith('calc') or color.startswith('var'): - return color - else: - return '#' + color +def webify(color): + if color.startswith('calc') or color.startswith('var'): + return color + else: + return '#' + color def _get_ttype_class(ttype): @@ -60,22 +60,22 @@ def _get_ttype_class(ttype): CSSFILE_TEMPLATE = '''\ -/* +/* generated by Pygments <https://pygments.org/> Copyright 2006-2021 by the Pygments team. -Licensed under the BSD license, see LICENSE for details. -*/ +Licensed under the BSD license, see LICENSE for details. +*/ %(styledefs)s ''' DOC_HEADER = '''\ <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> -<!-- +<!-- generated by Pygments <https://pygments.org/> Copyright 2006-2021 by the Pygments team. -Licensed under the BSD license, see LICENSE for details. ---> +Licensed under the BSD license, see LICENSE for details. +--> <html> <head> <title>%(title)s</title> @@ -336,23 +336,23 @@ class HtmlFormatter(Formatter): .. versionadded:: 1.6 `filename` - A string used to generate a filename when rendering ``<pre>`` blocks, + A string used to generate a filename when rendering ``<pre>`` blocks, for example if displaying source code. If `linenos` is set to ``'table'`` then the filename will be rendered in an initial row containing a single `<th>` which spans both columns. .. versionadded:: 2.1 - `wrapcode` - Wrap the code inside ``<pre>`` blocks using ``<code>``, as recommended - by the HTML5 specification. + `wrapcode` + Wrap the code inside ``<pre>`` blocks using ``<code>``, as recommended + by the HTML5 specification. + + .. versionadded:: 2.4 - .. versionadded:: 2.4 - `debug_token_types` Add ``title`` attributes to all token ``<span>`` tags that show the name of the token. - + .. versionadded:: 2.10 @@ -423,7 +423,7 @@ class HtmlFormatter(Formatter): self.tagsfile = self._decodeifneeded(options.get('tagsfile', '')) self.tagurlformat = self._decodeifneeded(options.get('tagurlformat', '')) self.filename = self._decodeifneeded(options.get('filename', '')) - self.wrapcode = get_bool_opt(options, 'wrapcode', False) + self.wrapcode = get_bool_opt(options, 'wrapcode', False) self.span_element_openers = {} self.debug_token_types = get_bool_opt(options, 'debug_token_types', False) @@ -489,7 +489,7 @@ class HtmlFormatter(Formatter): name = self._get_css_class(ttype) style = '' if ndef['color']: - style += 'color: %s; ' % webify(ndef['color']) + style += 'color: %s; ' % webify(ndef['color']) if ndef['bold']: style += 'font-weight: bold; ' if ndef['italic']: @@ -497,9 +497,9 @@ class HtmlFormatter(Formatter): if ndef['underline']: style += 'text-decoration: underline; ' if ndef['bgcolor']: - style += 'background-color: %s; ' % webify(ndef['bgcolor']) + style += 'background-color: %s; ' % webify(ndef['bgcolor']) if ndef['border']: - style += 'border: 1px solid %s; ' % webify(ndef['border']) + style += 'border: 1px solid %s; ' % webify(ndef['border']) if style: t2c[ttype] = name # save len(ttype) to enable ordering the styles by @@ -635,9 +635,9 @@ class HtmlFormatter(Formatter): # write CSS file only if noclobber_cssfile isn't given as an option. try: if not os.path.exists(cssfilename) or not self.noclobber_cssfile: - with open(cssfilename, "w") as cf: - cf.write(CSSFILE_TEMPLATE % - {'styledefs': self.get_style_defs('body')}) + with open(cssfilename, "w") as cf: + cf.write(CSSFILE_TEMPLATE % + {'styledefs': self.get_style_defs('body')}) except OSError as err: err.strerror = 'Error writing CSS file: ' + err.strerror raise @@ -812,17 +812,17 @@ class HtmlFormatter(Formatter): if self.filename and self.linenos != 1: yield 0, ('<span class="filename">' + self.filename + '</span>') - # the empty span here is to keep leading empty lines from being - # ignored by HTML parsers - yield 0, ('<pre' + (style and ' style="%s"' % style) + '><span></span>') + # the empty span here is to keep leading empty lines from being + # ignored by HTML parsers + yield 0, ('<pre' + (style and ' style="%s"' % style) + '><span></span>') yield from inner yield 0, '</pre>' - def _wrap_code(self, inner): - yield 0, '<code>' + def _wrap_code(self, inner): + yield 0, '<code>' yield from inner - yield 0, '</code>' - + yield 0, '</code>' + @functools.lru_cache(maxsize=100) def _translate_parts(self, value): """HTML-escape a value and split it by newlines.""" @@ -939,10 +939,10 @@ class HtmlFormatter(Formatter): individual lines, in custom generators. See docstring for `format`. Can be overridden. """ - if self.wrapcode: - return self._wrap_div(self._wrap_pre(self._wrap_code(source))) - else: - return self._wrap_div(self._wrap_pre(source)) + if self.wrapcode: + return self._wrap_div(self._wrap_pre(self._wrap_code(source))) + else: + return self._wrap_div(self._wrap_pre(source)) def format_unencoded(self, tokensource, outfile): """ diff --git a/contrib/python/Pygments/py3/pygments/formatters/img.py b/contrib/python/Pygments/py3/pygments/formatters/img.py index 9b9a93c161..f481afc4a4 100644 --- a/contrib/python/Pygments/py3/pygments/formatters/img.py +++ b/contrib/python/Pygments/py3/pygments/formatters/img.py @@ -8,7 +8,7 @@ :license: BSD, see LICENSE for details. """ -import os +import os import sys from pygments.formatter import Formatter @@ -72,10 +72,10 @@ class FontManager: if not font_name: self.font_name = DEFAULT_FONT_NAME_WIN self._create_win() - elif sys.platform.startswith('darwin'): - if not font_name: - self.font_name = DEFAULT_FONT_NAME_MAC - self._create_mac() + elif sys.platform.startswith('darwin'): + if not font_name: + self.font_name = DEFAULT_FONT_NAME_MAC + self._create_mac() else: if not font_name: self.font_name = DEFAULT_FONT_NAME_NIX @@ -87,13 +87,13 @@ class FontManager: stdout, _ = proc.communicate() if proc.returncode == 0: lines = stdout.splitlines() - for line in lines: - if line.startswith(b'Fontconfig warning:'): - continue - path = line.decode().strip().strip(':') - if path: - return path - return None + for line in lines: + if line.startswith(b'Fontconfig warning:'): + continue + path = line.decode().strip().strip(':') + if path: + return path + return None def _create_nix(self): for name in STYLES['NORMAL']: @@ -116,38 +116,38 @@ class FontManager: else: self.fonts[style] = self.fonts['NORMAL'] - def _get_mac_font_path(self, font_map, name, style): - return font_map.get((name + ' ' + style).strip().lower()) - - def _create_mac(self): - font_map = {} - for font_dir in (os.path.join(os.getenv("HOME"), 'Library/Fonts/'), - '/Library/Fonts/', '/System/Library/Fonts/'): - font_map.update( + def _get_mac_font_path(self, font_map, name, style): + return font_map.get((name + ' ' + style).strip().lower()) + + def _create_mac(self): + font_map = {} + for font_dir in (os.path.join(os.getenv("HOME"), 'Library/Fonts/'), + '/Library/Fonts/', '/System/Library/Fonts/'): + font_map.update( (os.path.splitext(f)[0].lower(), os.path.join(font_dir, f)) for f in os.listdir(font_dir) if f.lower().endswith(('ttf', 'ttc'))) - - for name in STYLES['NORMAL']: - path = self._get_mac_font_path(font_map, self.font_name, name) - if path is not None: - self.fonts['NORMAL'] = ImageFont.truetype(path, self.font_size) - break - else: - raise FontNotFound('No usable fonts named: "%s"' % - self.font_name) - for style in ('ITALIC', 'BOLD', 'BOLDITALIC'): - for stylename in STYLES[style]: - path = self._get_mac_font_path(font_map, self.font_name, stylename) - if path is not None: - self.fonts[style] = ImageFont.truetype(path, self.font_size) - break - else: - if style == 'BOLDITALIC': - self.fonts[style] = self.fonts['BOLD'] - else: - self.fonts[style] = self.fonts['NORMAL'] - + + for name in STYLES['NORMAL']: + path = self._get_mac_font_path(font_map, self.font_name, name) + if path is not None: + self.fonts['NORMAL'] = ImageFont.truetype(path, self.font_size) + break + else: + raise FontNotFound('No usable fonts named: "%s"' % + self.font_name) + for style in ('ITALIC', 'BOLD', 'BOLDITALIC'): + for stylename in STYLES[style]: + path = self._get_mac_font_path(font_map, self.font_name, stylename) + if path is not None: + self.fonts[style] = ImageFont.truetype(path, self.font_size) + break + else: + if style == 'BOLDITALIC': + self.fonts[style] = self.fonts['BOLD'] + else: + self.fonts[style] = self.fonts['NORMAL'] + def _lookup_win(self, key, basename, styles, fail=False): for suffix in ('', ' (TrueType)'): for style in styles: diff --git a/contrib/python/Pygments/py3/pygments/formatters/irc.py b/contrib/python/Pygments/py3/pygments/formatters/irc.py index 5367b08e12..d8da7a39de 100644 --- a/contrib/python/Pygments/py3/pygments/formatters/irc.py +++ b/contrib/python/Pygments/py3/pygments/formatters/irc.py @@ -22,55 +22,55 @@ __all__ = ['IRCFormatter'] IRC_COLORS = { Token: ('', ''), - Whitespace: ('gray', 'brightblack'), - Comment: ('gray', 'brightblack'), - Comment.Preproc: ('cyan', 'brightcyan'), - Keyword: ('blue', 'brightblue'), - Keyword.Type: ('cyan', 'brightcyan'), - Operator.Word: ('magenta', 'brightcyan'), - Name.Builtin: ('cyan', 'brightcyan'), - Name.Function: ('green', 'brightgreen'), - Name.Namespace: ('_cyan_', '_brightcyan_'), - Name.Class: ('_green_', '_brightgreen_'), - Name.Exception: ('cyan', 'brightcyan'), - Name.Decorator: ('brightblack', 'gray'), - Name.Variable: ('red', 'brightred'), - Name.Constant: ('red', 'brightred'), - Name.Attribute: ('cyan', 'brightcyan'), - Name.Tag: ('brightblue', 'brightblue'), - String: ('yellow', 'yellow'), - Number: ('blue', 'brightblue'), - - Generic.Deleted: ('brightred', 'brightred'), - Generic.Inserted: ('green', 'brightgreen'), + Whitespace: ('gray', 'brightblack'), + Comment: ('gray', 'brightblack'), + Comment.Preproc: ('cyan', 'brightcyan'), + Keyword: ('blue', 'brightblue'), + Keyword.Type: ('cyan', 'brightcyan'), + Operator.Word: ('magenta', 'brightcyan'), + Name.Builtin: ('cyan', 'brightcyan'), + Name.Function: ('green', 'brightgreen'), + Name.Namespace: ('_cyan_', '_brightcyan_'), + Name.Class: ('_green_', '_brightgreen_'), + Name.Exception: ('cyan', 'brightcyan'), + Name.Decorator: ('brightblack', 'gray'), + Name.Variable: ('red', 'brightred'), + Name.Constant: ('red', 'brightred'), + Name.Attribute: ('cyan', 'brightcyan'), + Name.Tag: ('brightblue', 'brightblue'), + String: ('yellow', 'yellow'), + Number: ('blue', 'brightblue'), + + Generic.Deleted: ('brightred', 'brightred'), + Generic.Inserted: ('green', 'brightgreen'), Generic.Heading: ('**', '**'), - Generic.Subheading: ('*magenta*', '*brightmagenta*'), - Generic.Error: ('brightred', 'brightred'), + Generic.Subheading: ('*magenta*', '*brightmagenta*'), + Generic.Error: ('brightred', 'brightred'), - Error: ('_brightred_', '_brightred_'), + Error: ('_brightred_', '_brightred_'), } IRC_COLOR_MAP = { 'white': 0, 'black': 1, - 'blue': 2, - 'brightgreen': 3, - 'brightred': 4, - 'yellow': 5, - 'magenta': 6, + 'blue': 2, + 'brightgreen': 3, + 'brightred': 4, + 'yellow': 5, + 'magenta': 6, 'orange': 7, - 'green': 7, #compat w/ ansi - 'brightyellow': 8, + 'green': 7, #compat w/ ansi + 'brightyellow': 8, 'lightgreen': 9, - 'brightcyan': 9, # compat w/ ansi - 'cyan': 10, + 'brightcyan': 9, # compat w/ ansi + 'cyan': 10, 'lightblue': 11, - 'red': 11, # compat w/ ansi - 'brightblue': 12, - 'brightmagenta': 13, - 'brightblack': 14, - 'gray': 15, + 'red': 11, # compat w/ ansi + 'brightblue': 12, + 'brightmagenta': 13, + 'brightblack': 14, + 'gray': 15, } def ircformat(color, text): diff --git a/contrib/python/Pygments/py3/pygments/formatters/latex.py b/contrib/python/Pygments/py3/pygments/formatters/latex.py index 474092129e..e32fcebc5a 100644 --- a/contrib/python/Pygments/py3/pygments/formatters/latex.py +++ b/contrib/python/Pygments/py3/pygments/formatters/latex.py @@ -411,18 +411,18 @@ class LatexFormatter(Formatter): outfile.write('\\end{' + self.envname + '}\n') if self.full: - encoding = self.encoding or 'utf8' - # map known existings encodings from LaTeX distribution - encoding = { - 'utf_8': 'utf8', - 'latin_1': 'latin1', - 'iso_8859_1': 'latin1', - }.get(encoding.replace('-', '_'), encoding) + encoding = self.encoding or 'utf8' + # map known existings encodings from LaTeX distribution + encoding = { + 'utf_8': 'utf8', + 'latin_1': 'latin1', + 'iso_8859_1': 'latin1', + }.get(encoding.replace('-', '_'), encoding) realoutfile.write(DOC_TEMPLATE % dict(docclass = self.docclass, preamble = self.preamble, title = self.title, - encoding = encoding, + encoding = encoding, styledefs = self.get_style_defs(), code = outfile.getvalue())) diff --git a/contrib/python/Pygments/py3/pygments/formatters/terminal.py b/contrib/python/Pygments/py3/pygments/formatters/terminal.py index f0132b562e..a27594d0df 100644 --- a/contrib/python/Pygments/py3/pygments/formatters/terminal.py +++ b/contrib/python/Pygments/py3/pygments/formatters/terminal.py @@ -23,33 +23,33 @@ __all__ = ['TerminalFormatter'] TERMINAL_COLORS = { Token: ('', ''), - Whitespace: ('gray', 'brightblack'), - Comment: ('gray', 'brightblack'), - Comment.Preproc: ('cyan', 'brightcyan'), - Keyword: ('blue', 'brightblue'), - Keyword.Type: ('cyan', 'brightcyan'), - Operator.Word: ('magenta', 'brightmagenta'), - Name.Builtin: ('cyan', 'brightcyan'), - Name.Function: ('green', 'brightgreen'), - Name.Namespace: ('_cyan_', '_brightcyan_'), - Name.Class: ('_green_', '_brightgreen_'), - Name.Exception: ('cyan', 'brightcyan'), - Name.Decorator: ('brightblack', 'gray'), - Name.Variable: ('red', 'brightred'), - Name.Constant: ('red', 'brightred'), - Name.Attribute: ('cyan', 'brightcyan'), - Name.Tag: ('brightblue', 'brightblue'), - String: ('yellow', 'yellow'), - Number: ('blue', 'brightblue'), - - Generic.Deleted: ('brightred', 'brightred'), - Generic.Inserted: ('green', 'brightgreen'), + Whitespace: ('gray', 'brightblack'), + Comment: ('gray', 'brightblack'), + Comment.Preproc: ('cyan', 'brightcyan'), + Keyword: ('blue', 'brightblue'), + Keyword.Type: ('cyan', 'brightcyan'), + Operator.Word: ('magenta', 'brightmagenta'), + Name.Builtin: ('cyan', 'brightcyan'), + Name.Function: ('green', 'brightgreen'), + Name.Namespace: ('_cyan_', '_brightcyan_'), + Name.Class: ('_green_', '_brightgreen_'), + Name.Exception: ('cyan', 'brightcyan'), + Name.Decorator: ('brightblack', 'gray'), + Name.Variable: ('red', 'brightred'), + Name.Constant: ('red', 'brightred'), + Name.Attribute: ('cyan', 'brightcyan'), + Name.Tag: ('brightblue', 'brightblue'), + String: ('yellow', 'yellow'), + Number: ('blue', 'brightblue'), + + Generic.Deleted: ('brightred', 'brightred'), + Generic.Inserted: ('green', 'brightgreen'), Generic.Heading: ('**', '**'), - Generic.Subheading: ('*magenta*', '*brightmagenta*'), + Generic.Subheading: ('*magenta*', '*brightmagenta*'), Generic.Prompt: ('**', '**'), - Generic.Error: ('brightred', 'brightred'), + Generic.Error: ('brightred', 'brightred'), - Error: ('_brightred_', '_brightred_'), + Error: ('_brightred_', '_brightred_'), } diff --git a/contrib/python/Pygments/py3/pygments/formatters/terminal256.py b/contrib/python/Pygments/py3/pygments/formatters/terminal256.py index 60add14f9c..be6f890f44 100644 --- a/contrib/python/Pygments/py3/pygments/formatters/terminal256.py +++ b/contrib/python/Pygments/py3/pygments/formatters/terminal256.py @@ -24,8 +24,8 @@ # to "white background, black foreground", etc... from pygments.formatter import Formatter -from pygments.console import codes -from pygments.style import ansicolors +from pygments.console import codes +from pygments.style import ansicolors __all__ = ['Terminal256Formatter', 'TerminalTrueColorFormatter'] @@ -47,21 +47,21 @@ class EscapeSequence: def color_string(self): attrs = [] if self.fg is not None: - if self.fg in ansicolors: - esc = codes[self.fg.replace('ansi','')] - if ';01m' in esc: - self.bold = True - # extract fg color code. - attrs.append(esc[2:4]) - else: - attrs.extend(("38", "5", "%i" % self.fg)) + if self.fg in ansicolors: + esc = codes[self.fg.replace('ansi','')] + if ';01m' in esc: + self.bold = True + # extract fg color code. + attrs.append(esc[2:4]) + else: + attrs.extend(("38", "5", "%i" % self.fg)) if self.bg is not None: - if self.bg in ansicolors: - esc = codes[self.bg.replace('ansi','')] - # extract fg color code, add 10 for bg. - attrs.append(str(int(esc[2:4])+10)) - else: - attrs.extend(("48", "5", "%i" % self.bg)) + if self.bg in ansicolors: + esc = codes[self.bg.replace('ansi','')] + # extract fg color code, add 10 for bg. + attrs.append(str(int(esc[2:4])+10)) + else: + attrs.extend(("48", "5", "%i" % self.bg)) if self.bold: attrs.append("01") if self.underline: @@ -107,17 +107,17 @@ class Terminal256Formatter(Formatter): .. versionadded:: 0.9 - .. versionchanged:: 2.2 - If the used style defines foreground colors in the form ``#ansi*``, then - `Terminal256Formatter` will map these to non extended foreground color. - See :ref:`AnsiTerminalStyle` for more information. - - .. versionchanged:: 2.4 - The ANSI color names have been updated with names that are easier to - understand and align with colornames of other projects and terminals. - See :ref:`this table <new-ansi-color-names>` for more information. - - + .. versionchanged:: 2.2 + If the used style defines foreground colors in the form ``#ansi*``, then + `Terminal256Formatter` will map these to non extended foreground color. + See :ref:`AnsiTerminalStyle` for more information. + + .. versionchanged:: 2.4 + The ANSI color names have been updated with names that are easier to + understand and align with colornames of other projects and terminals. + See :ref:`this table <new-ansi-color-names>` for more information. + + Options accepted: `style` @@ -204,10 +204,10 @@ class Terminal256Formatter(Formatter): def _color_index(self, color): index = self.best_match.get(color, None) - if color in ansicolors: - # strip the `ansi/#ansi` part and look up code - index = color - self.best_match[color] = index + if color in ansicolors: + # strip the `ansi/#ansi` part and look up code + index = color + self.best_match[color] = index if index is None: try: rgb = int(str(color), 16) @@ -224,14 +224,14 @@ class Terminal256Formatter(Formatter): def _setup_styles(self): for ttype, ndef in self.style: escape = EscapeSequence() - # get foreground from ansicolor if set - if ndef['ansicolor']: - escape.fg = self._color_index(ndef['ansicolor']) - elif ndef['color']: + # get foreground from ansicolor if set + if ndef['ansicolor']: + escape.fg = self._color_index(ndef['ansicolor']) + elif ndef['color']: escape.fg = self._color_index(ndef['color']) - if ndef['bgansicolor']: - escape.bg = self._color_index(ndef['bgansicolor']) - elif ndef['bgcolor']: + if ndef['bgansicolor']: + escape.bg = self._color_index(ndef['bgansicolor']) + elif ndef['bgcolor']: escape.bg = self._color_index(ndef['bgcolor']) if self.usebold and ndef['bold']: escape.bold = True |