aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/python/prompt-toolkit/py2/prompt_toolkit/styles
diff options
context:
space:
mode:
authorNikita Slyusarev <nslus@yandex-team.com>2022-02-10 16:46:52 +0300
committerDaniil Cherednik <dcherednik@yandex-team.ru>2022-02-10 16:46:52 +0300
commitcd77cecfc03a3eaf87816af28a33067c4f0cdb59 (patch)
tree1308e0bae862d52e0020d881fe758080437fe389 /contrib/python/prompt-toolkit/py2/prompt_toolkit/styles
parentcdae02d225fb5b3afbb28990e79a7ac6c9125327 (diff)
downloadydb-cd77cecfc03a3eaf87816af28a33067c4f0cdb59.tar.gz
Restoring authorship annotation for Nikita Slyusarev <nslus@yandex-team.com>. Commit 1 of 2.
Diffstat (limited to 'contrib/python/prompt-toolkit/py2/prompt_toolkit/styles')
-rw-r--r--contrib/python/prompt-toolkit/py2/prompt_toolkit/styles/__init__.py42
-rw-r--r--contrib/python/prompt-toolkit/py2/prompt_toolkit/styles/base.py172
-rw-r--r--contrib/python/prompt-toolkit/py2/prompt_toolkit/styles/defaults.py190
-rw-r--r--contrib/python/prompt-toolkit/py2/prompt_toolkit/styles/from_dict.py294
-rw-r--r--contrib/python/prompt-toolkit/py2/prompt_toolkit/styles/from_pygments.py142
-rw-r--r--contrib/python/prompt-toolkit/py2/prompt_toolkit/styles/utils.py90
6 files changed, 465 insertions, 465 deletions
diff --git a/contrib/python/prompt-toolkit/py2/prompt_toolkit/styles/__init__.py b/contrib/python/prompt-toolkit/py2/prompt_toolkit/styles/__init__.py
index 9d641f04475..4735ab21559 100644
--- a/contrib/python/prompt-toolkit/py2/prompt_toolkit/styles/__init__.py
+++ b/contrib/python/prompt-toolkit/py2/prompt_toolkit/styles/__init__.py
@@ -1,21 +1,21 @@
-"""
-Styling for prompt_toolkit applications.
-"""
-from __future__ import unicode_literals
-
-from .base import *
-from .defaults import *
-from .from_dict import *
-from .from_pygments import *
-from .utils import *
-
-
-#: The default built-in style.
-#: (For backwards compatibility, when Pygments is installed, this includes the
-#: default Pygments style.)
-try:
- import pygments
-except ImportError:
- DEFAULT_STYLE = style_from_dict(DEFAULT_STYLE_EXTENSIONS)
-else:
- DEFAULT_STYLE = style_from_pygments()
+"""
+Styling for prompt_toolkit applications.
+"""
+from __future__ import unicode_literals
+
+from .base import *
+from .defaults import *
+from .from_dict import *
+from .from_pygments import *
+from .utils import *
+
+
+#: The default built-in style.
+#: (For backwards compatibility, when Pygments is installed, this includes the
+#: default Pygments style.)
+try:
+ import pygments
+except ImportError:
+ DEFAULT_STYLE = style_from_dict(DEFAULT_STYLE_EXTENSIONS)
+else:
+ DEFAULT_STYLE = style_from_pygments()
diff --git a/contrib/python/prompt-toolkit/py2/prompt_toolkit/styles/base.py b/contrib/python/prompt-toolkit/py2/prompt_toolkit/styles/base.py
index e9ddaa524dc..d1009ba3b2a 100644
--- a/contrib/python/prompt-toolkit/py2/prompt_toolkit/styles/base.py
+++ b/contrib/python/prompt-toolkit/py2/prompt_toolkit/styles/base.py
@@ -1,86 +1,86 @@
-"""
-The base classes for the styling.
-"""
-from __future__ import unicode_literals
-from abc import ABCMeta, abstractmethod
-from collections import namedtuple
-from six import with_metaclass
-
-__all__ = (
- 'Attrs',
- 'DEFAULT_ATTRS',
- 'ANSI_COLOR_NAMES',
- 'Style',
- 'DynamicStyle',
-)
-
-
-#: Style attributes.
-Attrs = namedtuple('Attrs', 'color bgcolor bold underline italic blink reverse')
-"""
-:param color: Hexadecimal string. E.g. '000000' or Ansi color name: e.g. 'ansiblue'
-:param bgcolor: Hexadecimal string. E.g. 'ffffff' or Ansi color name: e.g. 'ansired'
-:param bold: Boolean
-:param underline: Boolean
-:param italic: Boolean
-:param blink: Boolean
-:param reverse: Boolean
-"""
-
-#: The default `Attrs`.
-DEFAULT_ATTRS = Attrs(color=None, bgcolor=None, bold=False, underline=False,
- italic=False, blink=False, reverse=False)
-
-
-#: ``Attrs.bgcolor/fgcolor`` can be in either 'ffffff' format, or can be any of
-#: the following in case we want to take colors from the 8/16 color palette.
-#: Usually, in that case, the terminal application allows to configure the RGB
-#: values for these names.
-ANSI_COLOR_NAMES = [
- 'ansiblack', 'ansiwhite', 'ansidefault',
-
- # Low intensity.
- 'ansired', 'ansigreen', 'ansiyellow', 'ansiblue', 'ansifuchsia', 'ansiturquoise', 'ansilightgray',
-
- # High intensity. (Not supported everywhere.)
- 'ansidarkgray', 'ansidarkred', 'ansidarkgreen', 'ansibrown', 'ansidarkblue',
- 'ansipurple', 'ansiteal',
-]
-
-
-class Style(with_metaclass(ABCMeta, object)):
- """
- Abstract base class for prompt_toolkit styles.
- """
- @abstractmethod
- def get_attrs_for_token(self, token):
- """
- Return :class:`.Attrs` for the given token.
- """
-
- @abstractmethod
- def invalidation_hash(self):
- """
- Invalidation hash for the style. When this changes over time, the
- renderer knows that something in the style changed, and that everything
- has to be redrawn.
- """
-
-
-class DynamicStyle(Style):
- """
- Style class that can dynamically returns an other Style.
-
- :param get_style: Callable that returns a :class:`.Style` instance.
- """
- def __init__(self, get_style):
- self.get_style = get_style
-
- def get_attrs_for_token(self, token):
- style = self.get_style()
- assert isinstance(style, Style)
-
- return style.get_attrs_for_token(token)
-
- def invalidation_hash(self):
- return self.get_style().invalidation_hash()
+"""
+The base classes for the styling.
+"""
+from __future__ import unicode_literals
+from abc import ABCMeta, abstractmethod
+from collections import namedtuple
+from six import with_metaclass
+
+__all__ = (
+ 'Attrs',
+ 'DEFAULT_ATTRS',
+ 'ANSI_COLOR_NAMES',
+ 'Style',
+ 'DynamicStyle',
+)
+
+
+#: Style attributes.
+Attrs = namedtuple('Attrs', 'color bgcolor bold underline italic blink reverse')
+"""
+:param color: Hexadecimal string. E.g. '000000' or Ansi color name: e.g. 'ansiblue'
+:param bgcolor: Hexadecimal string. E.g. 'ffffff' or Ansi color name: e.g. 'ansired'
+:param bold: Boolean
+:param underline: Boolean
+:param italic: Boolean
+:param blink: Boolean
+:param reverse: Boolean
+"""
+
+#: The default `Attrs`.
+DEFAULT_ATTRS = Attrs(color=None, bgcolor=None, bold=False, underline=False,
+ italic=False, blink=False, reverse=False)
+
+
+#: ``Attrs.bgcolor/fgcolor`` can be in either 'ffffff' format, or can be any of
+#: the following in case we want to take colors from the 8/16 color palette.
+#: Usually, in that case, the terminal application allows to configure the RGB
+#: values for these names.
+ANSI_COLOR_NAMES = [
+ 'ansiblack', 'ansiwhite', 'ansidefault',
+
+ # Low intensity.
+ 'ansired', 'ansigreen', 'ansiyellow', 'ansiblue', 'ansifuchsia', 'ansiturquoise', 'ansilightgray',
+
+ # High intensity. (Not supported everywhere.)
+ 'ansidarkgray', 'ansidarkred', 'ansidarkgreen', 'ansibrown', 'ansidarkblue',
+ 'ansipurple', 'ansiteal',
+]
+
+
+class Style(with_metaclass(ABCMeta, object)):
+ """
+ Abstract base class for prompt_toolkit styles.
+ """
+ @abstractmethod
+ def get_attrs_for_token(self, token):
+ """
+ Return :class:`.Attrs` for the given token.
+ """
+
+ @abstractmethod
+ def invalidation_hash(self):
+ """
+ Invalidation hash for the style. When this changes over time, the
+ renderer knows that something in the style changed, and that everything
+ has to be redrawn.
+ """
+
+
+class DynamicStyle(Style):
+ """
+ Style class that can dynamically returns an other Style.
+
+ :param get_style: Callable that returns a :class:`.Style` instance.
+ """
+ def __init__(self, get_style):
+ self.get_style = get_style
+
+ def get_attrs_for_token(self, token):
+ style = self.get_style()
+ assert isinstance(style, Style)
+
+ return style.get_attrs_for_token(token)
+
+ def invalidation_hash(self):
+ return self.get_style().invalidation_hash()
diff --git a/contrib/python/prompt-toolkit/py2/prompt_toolkit/styles/defaults.py b/contrib/python/prompt-toolkit/py2/prompt_toolkit/styles/defaults.py
index 5357eaa111b..f280dd46468 100644
--- a/contrib/python/prompt-toolkit/py2/prompt_toolkit/styles/defaults.py
+++ b/contrib/python/prompt-toolkit/py2/prompt_toolkit/styles/defaults.py
@@ -1,95 +1,95 @@
-"""
-The default styling.
-"""
-from __future__ import unicode_literals
-
-from prompt_toolkit.token import Token
-
-__all__ = (
- 'DEFAULT_STYLE_EXTENSIONS',
- 'default_style_extensions',
-)
-
-
-#: Styling of prompt-toolkit specific tokens, that are not know by the default
-#: Pygments style.
-DEFAULT_STYLE_EXTENSIONS = {
- # Highlighting of search matches in document.
- Token.SearchMatch: 'noinherit reverse',
- Token.SearchMatch.Current: 'noinherit #ffffff bg:#448844 underline',
-
- # Highlighting of select text in document.
- Token.SelectedText: 'reverse',
-
- Token.CursorColumn: 'bg:#dddddd',
- Token.CursorLine: 'underline',
- Token.ColorColumn: 'bg:#ccaacc',
-
- # Highlighting of matching brackets.
- Token.MatchingBracket: '',
- Token.MatchingBracket.Other: '#000000 bg:#aacccc',
- Token.MatchingBracket.Cursor: '#ff8888 bg:#880000',
-
- Token.MultipleCursors.Cursor: '#000000 bg:#ccccaa',
-
- # Line numbers.
- Token.LineNumber: '#888888',
- Token.LineNumber.Current: 'bold',
- Token.Tilde: '#8888ff',
-
- # Default prompt.
- Token.Prompt: '',
- Token.Prompt.Arg: 'noinherit',
- Token.Prompt.Search: 'noinherit',
- Token.Prompt.Search.Text: '',
-
- # Search toolbar.
- Token.Toolbar.Search: 'bold',
- Token.Toolbar.Search.Text: 'nobold',
-
- # System toolbar
- Token.Toolbar.System: 'bold',
- Token.Toolbar.System.Text: 'nobold',
-
- # "arg" toolbar.
- Token.Toolbar.Arg: 'bold',
- Token.Toolbar.Arg.Text: 'nobold',
-
- # Validation toolbar.
- Token.Toolbar.Validation: 'bg:#550000 #ffffff',
- Token.WindowTooSmall: 'bg:#550000 #ffffff',
-
- # Completions toolbar.
- Token.Toolbar.Completions: 'bg:#bbbbbb #000000',
- Token.Toolbar.Completions.Arrow: 'bg:#bbbbbb #000000 bold',
- Token.Toolbar.Completions.Completion: 'bg:#bbbbbb #000000',
- Token.Toolbar.Completions.Completion.Current: 'bg:#444444 #ffffff',
-
- # Completions menu.
- Token.Menu.Completions: 'bg:#bbbbbb #000000',
- Token.Menu.Completions.Completion: '',
- Token.Menu.Completions.Completion.Current: 'bg:#888888 #ffffff',
- Token.Menu.Completions.Meta: 'bg:#999999 #000000',
- Token.Menu.Completions.Meta.Current: 'bg:#aaaaaa #000000',
- Token.Menu.Completions.MultiColumnMeta: 'bg:#aaaaaa #000000',
-
- # Scrollbars.
- Token.Scrollbar: 'bg:#888888',
- Token.Scrollbar.Button: 'bg:#444444',
- Token.Scrollbar.Arrow: 'bg:#222222 #888888 bold',
-
- # Auto suggestion text.
- Token.AutoSuggestion: '#666666',
-
- # Trailing whitespace and tabs.
- Token.TrailingWhiteSpace: '#999999',
- Token.Tab: '#999999',
-
- # When Control-C has been pressed. Grayed.
- Token.Aborted: '#888888',
-
- # Entering a Vi digraph.
- Token.Digraph: '#4444ff',
-}
-
-default_style_extensions = DEFAULT_STYLE_EXTENSIONS # Old name.
+"""
+The default styling.
+"""
+from __future__ import unicode_literals
+
+from prompt_toolkit.token import Token
+
+__all__ = (
+ 'DEFAULT_STYLE_EXTENSIONS',
+ 'default_style_extensions',
+)
+
+
+#: Styling of prompt-toolkit specific tokens, that are not know by the default
+#: Pygments style.
+DEFAULT_STYLE_EXTENSIONS = {
+ # Highlighting of search matches in document.
+ Token.SearchMatch: 'noinherit reverse',
+ Token.SearchMatch.Current: 'noinherit #ffffff bg:#448844 underline',
+
+ # Highlighting of select text in document.
+ Token.SelectedText: 'reverse',
+
+ Token.CursorColumn: 'bg:#dddddd',
+ Token.CursorLine: 'underline',
+ Token.ColorColumn: 'bg:#ccaacc',
+
+ # Highlighting of matching brackets.
+ Token.MatchingBracket: '',
+ Token.MatchingBracket.Other: '#000000 bg:#aacccc',
+ Token.MatchingBracket.Cursor: '#ff8888 bg:#880000',
+
+ Token.MultipleCursors.Cursor: '#000000 bg:#ccccaa',
+
+ # Line numbers.
+ Token.LineNumber: '#888888',
+ Token.LineNumber.Current: 'bold',
+ Token.Tilde: '#8888ff',
+
+ # Default prompt.
+ Token.Prompt: '',
+ Token.Prompt.Arg: 'noinherit',
+ Token.Prompt.Search: 'noinherit',
+ Token.Prompt.Search.Text: '',
+
+ # Search toolbar.
+ Token.Toolbar.Search: 'bold',
+ Token.Toolbar.Search.Text: 'nobold',
+
+ # System toolbar
+ Token.Toolbar.System: 'bold',
+ Token.Toolbar.System.Text: 'nobold',
+
+ # "arg" toolbar.
+ Token.Toolbar.Arg: 'bold',
+ Token.Toolbar.Arg.Text: 'nobold',
+
+ # Validation toolbar.
+ Token.Toolbar.Validation: 'bg:#550000 #ffffff',
+ Token.WindowTooSmall: 'bg:#550000 #ffffff',
+
+ # Completions toolbar.
+ Token.Toolbar.Completions: 'bg:#bbbbbb #000000',
+ Token.Toolbar.Completions.Arrow: 'bg:#bbbbbb #000000 bold',
+ Token.Toolbar.Completions.Completion: 'bg:#bbbbbb #000000',
+ Token.Toolbar.Completions.Completion.Current: 'bg:#444444 #ffffff',
+
+ # Completions menu.
+ Token.Menu.Completions: 'bg:#bbbbbb #000000',
+ Token.Menu.Completions.Completion: '',
+ Token.Menu.Completions.Completion.Current: 'bg:#888888 #ffffff',
+ Token.Menu.Completions.Meta: 'bg:#999999 #000000',
+ Token.Menu.Completions.Meta.Current: 'bg:#aaaaaa #000000',
+ Token.Menu.Completions.MultiColumnMeta: 'bg:#aaaaaa #000000',
+
+ # Scrollbars.
+ Token.Scrollbar: 'bg:#888888',
+ Token.Scrollbar.Button: 'bg:#444444',
+ Token.Scrollbar.Arrow: 'bg:#222222 #888888 bold',
+
+ # Auto suggestion text.
+ Token.AutoSuggestion: '#666666',
+
+ # Trailing whitespace and tabs.
+ Token.TrailingWhiteSpace: '#999999',
+ Token.Tab: '#999999',
+
+ # When Control-C has been pressed. Grayed.
+ Token.Aborted: '#888888',
+
+ # Entering a Vi digraph.
+ Token.Digraph: '#4444ff',
+}
+
+default_style_extensions = DEFAULT_STYLE_EXTENSIONS # Old name.
diff --git a/contrib/python/prompt-toolkit/py2/prompt_toolkit/styles/from_dict.py b/contrib/python/prompt-toolkit/py2/prompt_toolkit/styles/from_dict.py
index b50325710f8..e000aceb93f 100644
--- a/contrib/python/prompt-toolkit/py2/prompt_toolkit/styles/from_dict.py
+++ b/contrib/python/prompt-toolkit/py2/prompt_toolkit/styles/from_dict.py
@@ -1,151 +1,151 @@
-"""
-Tool for creating styles from a dictionary.
-
-This is very similar to the Pygments style dictionary, with some additions:
-- Support for reverse and blink.
-- Support for ANSI color names. (These will map directly to the 16 terminal
- colors.)
-"""
+"""
+Tool for creating styles from a dictionary.
+
+This is very similar to the Pygments style dictionary, with some additions:
+- Support for reverse and blink.
+- Support for ANSI color names. (These will map directly to the 16 terminal
+ colors.)
+"""
try:
from collections.abc import Mapping
except ImportError:
from collections import Mapping
-
-from .base import Style, DEFAULT_ATTRS, ANSI_COLOR_NAMES
-from .defaults import DEFAULT_STYLE_EXTENSIONS
-from .utils import merge_attrs, split_token_in_parts
-from six.moves import range
-
-__all__ = (
- 'style_from_dict',
-)
-
-
-def _colorformat(text):
- """
- Parse/validate color format.
-
- Like in Pygments, but also support the ANSI color names.
- (These will map to the colors of the 16 color palette.)
- """
- if text[0:1] == '#':
- col = text[1:]
- if col in ANSI_COLOR_NAMES:
- return col
- elif len(col) == 6:
- return col
- elif len(col) == 3:
- return col[0]*2 + col[1]*2 + col[2]*2
- elif text == '':
- return text
-
- raise ValueError('Wrong color format %r' % text)
-
-
-def style_from_dict(style_dict, include_defaults=True):
- """
- Create a ``Style`` instance from a dictionary or other mapping.
-
- The dictionary is equivalent to the ``Style.styles`` dictionary from
- pygments, with a few additions: it supports 'reverse' and 'blink'.
-
- Usage::
-
- style_from_dict({
- Token: '#ff0000 bold underline',
- Token.Title: 'blink',
- Token.SomethingElse: 'reverse',
- })
-
- :param include_defaults: Include the defaults (built-in) styling for
- selected text, etc...)
- """
- assert isinstance(style_dict, Mapping)
-
- if include_defaults:
- s2 = {}
- s2.update(DEFAULT_STYLE_EXTENSIONS)
- s2.update(style_dict)
- style_dict = s2
-
- # Expand token inheritance and turn style description into Attrs.
- token_to_attrs = {}
-
- # (Loop through the tokens in order. Sorting makes sure that
- # we process the parent first.)
- for ttype, styledef in sorted(style_dict.items()):
- # Start from parent Attrs or default Attrs.
- attrs = DEFAULT_ATTRS
-
- if 'noinherit' not in styledef:
- for i in range(1, len(ttype) + 1):
- try:
- attrs = token_to_attrs[ttype[:-i]]
- except KeyError:
- pass
- else:
- break
-
- # Now update with the given attributes.
- for part in styledef.split():
- if part == 'noinherit':
- pass
- elif part == 'bold':
- attrs = attrs._replace(bold=True)
- elif part == 'nobold':
- attrs = attrs._replace(bold=False)
- elif part == 'italic':
- attrs = attrs._replace(italic=True)
- elif part == 'noitalic':
- attrs = attrs._replace(italic=False)
- elif part == 'underline':
- attrs = attrs._replace(underline=True)
- elif part == 'nounderline':
- attrs = attrs._replace(underline=False)
-
- # prompt_toolkit extensions. Not in Pygments.
- elif part == 'blink':
- attrs = attrs._replace(blink=True)
- elif part == 'noblink':
- attrs = attrs._replace(blink=False)
- elif part == 'reverse':
- attrs = attrs._replace(reverse=True)
- elif part == 'noreverse':
- attrs = attrs._replace(reverse=False)
-
- # Pygments properties that we ignore.
- elif part in ('roman', 'sans', 'mono'):
- pass
- elif part.startswith('border:'):
- pass
-
- # Colors.
-
- elif part.startswith('bg:'):
- attrs = attrs._replace(bgcolor=_colorformat(part[3:]))
- else:
- attrs = attrs._replace(color=_colorformat(part))
-
- token_to_attrs[ttype] = attrs
-
- return _StyleFromDict(token_to_attrs)
-
-
-class _StyleFromDict(Style):
- """
- Turn a dictionary that maps `Token` to `Attrs` into a style class.
-
- :param token_to_attrs: Dictionary that maps `Token` to `Attrs`.
- """
- def __init__(self, token_to_attrs):
- self.token_to_attrs = token_to_attrs
-
- def get_attrs_for_token(self, token):
- # Split Token.
- list_of_attrs = []
- for token in split_token_in_parts(token):
- list_of_attrs.append(self.token_to_attrs.get(token, DEFAULT_ATTRS))
- return merge_attrs(list_of_attrs)
-
- def invalidation_hash(self):
- return id(self.token_to_attrs)
+
+from .base import Style, DEFAULT_ATTRS, ANSI_COLOR_NAMES
+from .defaults import DEFAULT_STYLE_EXTENSIONS
+from .utils import merge_attrs, split_token_in_parts
+from six.moves import range
+
+__all__ = (
+ 'style_from_dict',
+)
+
+
+def _colorformat(text):
+ """
+ Parse/validate color format.
+
+ Like in Pygments, but also support the ANSI color names.
+ (These will map to the colors of the 16 color palette.)
+ """
+ if text[0:1] == '#':
+ col = text[1:]
+ if col in ANSI_COLOR_NAMES:
+ return col
+ elif len(col) == 6:
+ return col
+ elif len(col) == 3:
+ return col[0]*2 + col[1]*2 + col[2]*2
+ elif text == '':
+ return text
+
+ raise ValueError('Wrong color format %r' % text)
+
+
+def style_from_dict(style_dict, include_defaults=True):
+ """
+ Create a ``Style`` instance from a dictionary or other mapping.
+
+ The dictionary is equivalent to the ``Style.styles`` dictionary from
+ pygments, with a few additions: it supports 'reverse' and 'blink'.
+
+ Usage::
+
+ style_from_dict({
+ Token: '#ff0000 bold underline',
+ Token.Title: 'blink',
+ Token.SomethingElse: 'reverse',
+ })
+
+ :param include_defaults: Include the defaults (built-in) styling for
+ selected text, etc...)
+ """
+ assert isinstance(style_dict, Mapping)
+
+ if include_defaults:
+ s2 = {}
+ s2.update(DEFAULT_STYLE_EXTENSIONS)
+ s2.update(style_dict)
+ style_dict = s2
+
+ # Expand token inheritance and turn style description into Attrs.
+ token_to_attrs = {}
+
+ # (Loop through the tokens in order. Sorting makes sure that
+ # we process the parent first.)
+ for ttype, styledef in sorted(style_dict.items()):
+ # Start from parent Attrs or default Attrs.
+ attrs = DEFAULT_ATTRS
+
+ if 'noinherit' not in styledef:
+ for i in range(1, len(ttype) + 1):
+ try:
+ attrs = token_to_attrs[ttype[:-i]]
+ except KeyError:
+ pass
+ else:
+ break
+
+ # Now update with the given attributes.
+ for part in styledef.split():
+ if part == 'noinherit':
+ pass
+ elif part == 'bold':
+ attrs = attrs._replace(bold=True)
+ elif part == 'nobold':
+ attrs = attrs._replace(bold=False)
+ elif part == 'italic':
+ attrs = attrs._replace(italic=True)
+ elif part == 'noitalic':
+ attrs = attrs._replace(italic=False)
+ elif part == 'underline':
+ attrs = attrs._replace(underline=True)
+ elif part == 'nounderline':
+ attrs = attrs._replace(underline=False)
+
+ # prompt_toolkit extensions. Not in Pygments.
+ elif part == 'blink':
+ attrs = attrs._replace(blink=True)
+ elif part == 'noblink':
+ attrs = attrs._replace(blink=False)
+ elif part == 'reverse':
+ attrs = attrs._replace(reverse=True)
+ elif part == 'noreverse':
+ attrs = attrs._replace(reverse=False)
+
+ # Pygments properties that we ignore.
+ elif part in ('roman', 'sans', 'mono'):
+ pass
+ elif part.startswith('border:'):
+ pass
+
+ # Colors.
+
+ elif part.startswith('bg:'):
+ attrs = attrs._replace(bgcolor=_colorformat(part[3:]))
+ else:
+ attrs = attrs._replace(color=_colorformat(part))
+
+ token_to_attrs[ttype] = attrs
+
+ return _StyleFromDict(token_to_attrs)
+
+
+class _StyleFromDict(Style):
+ """
+ Turn a dictionary that maps `Token` to `Attrs` into a style class.
+
+ :param token_to_attrs: Dictionary that maps `Token` to `Attrs`.
+ """
+ def __init__(self, token_to_attrs):
+ self.token_to_attrs = token_to_attrs
+
+ def get_attrs_for_token(self, token):
+ # Split Token.
+ list_of_attrs = []
+ for token in split_token_in_parts(token):
+ list_of_attrs.append(self.token_to_attrs.get(token, DEFAULT_ATTRS))
+ return merge_attrs(list_of_attrs)
+
+ def invalidation_hash(self):
+ return id(self.token_to_attrs)
diff --git a/contrib/python/prompt-toolkit/py2/prompt_toolkit/styles/from_pygments.py b/contrib/python/prompt-toolkit/py2/prompt_toolkit/styles/from_pygments.py
index 0af8c53cf2d..9be932f2e03 100644
--- a/contrib/python/prompt-toolkit/py2/prompt_toolkit/styles/from_pygments.py
+++ b/contrib/python/prompt-toolkit/py2/prompt_toolkit/styles/from_pygments.py
@@ -1,77 +1,77 @@
-"""
-Adaptor for building prompt_toolkit styles, starting from a Pygments style.
-
-Usage::
-
- from pygments.styles.tango import TangoStyle
- style = style_from_pygments(pygments_style_cls=TangoStyle)
-"""
-from __future__ import unicode_literals
-
-from .base import Style
-from .from_dict import style_from_dict
-
-__all__ = (
- 'PygmentsStyle',
- 'style_from_pygments',
-)
-
-
-# Following imports are only needed when a ``PygmentsStyle`` class is used.
-try:
- from pygments.style import Style as pygments_Style
- from pygments.styles.default import DefaultStyle as pygments_DefaultStyle
-except ImportError:
- pygments_Style = None
- pygments_DefaultStyle = None
-
-
-def style_from_pygments(style_cls=pygments_DefaultStyle,
- style_dict=None,
- include_defaults=True):
- """
- Shortcut to create a :class:`.Style` instance from a Pygments style class
- and a style dictionary.
-
+"""
+Adaptor for building prompt_toolkit styles, starting from a Pygments style.
+
+Usage::
+
+ from pygments.styles.tango import TangoStyle
+ style = style_from_pygments(pygments_style_cls=TangoStyle)
+"""
+from __future__ import unicode_literals
+
+from .base import Style
+from .from_dict import style_from_dict
+
+__all__ = (
+ 'PygmentsStyle',
+ 'style_from_pygments',
+)
+
+
+# Following imports are only needed when a ``PygmentsStyle`` class is used.
+try:
+ from pygments.style import Style as pygments_Style
+ from pygments.styles.default import DefaultStyle as pygments_DefaultStyle
+except ImportError:
+ pygments_Style = None
+ pygments_DefaultStyle = None
+
+
+def style_from_pygments(style_cls=pygments_DefaultStyle,
+ style_dict=None,
+ include_defaults=True):
+ """
+ Shortcut to create a :class:`.Style` instance from a Pygments style class
+ and a style dictionary.
+
Example::
from prompt_toolkit.styles.from_pygments import style_from_pygments
from pygments.styles import get_style_by_name
style = style_from_pygments(get_style_by_name('monokai'))
- :param style_cls: Pygments style class to start from.
- :param style_dict: Dictionary for this style. `{Token: style}`.
- :param include_defaults: (`bool`) Include prompt_toolkit extensions.
- """
- assert style_dict is None or isinstance(style_dict, dict)
- assert style_cls is None or issubclass(style_cls, pygments_Style)
-
- styles_dict = {}
-
- if style_cls is not None:
- styles_dict.update(style_cls.styles)
-
- if style_dict is not None:
- styles_dict.update(style_dict)
-
- return style_from_dict(styles_dict, include_defaults=include_defaults)
-
-
-class PygmentsStyle(Style):
- " Deprecated. "
- def __new__(cls, pygments_style_cls):
- assert issubclass(pygments_style_cls, pygments_Style)
- return style_from_dict(pygments_style_cls.styles)
-
- def invalidation_hash(self):
- pass
-
- @classmethod
- def from_defaults(cls, style_dict=None,
- pygments_style_cls=pygments_DefaultStyle,
- include_extensions=True):
- " Deprecated. "
- return style_from_pygments(
- style_cls=pygments_style_cls,
- style_dict=style_dict,
- include_defaults=include_extensions)
+ :param style_cls: Pygments style class to start from.
+ :param style_dict: Dictionary for this style. `{Token: style}`.
+ :param include_defaults: (`bool`) Include prompt_toolkit extensions.
+ """
+ assert style_dict is None or isinstance(style_dict, dict)
+ assert style_cls is None or issubclass(style_cls, pygments_Style)
+
+ styles_dict = {}
+
+ if style_cls is not None:
+ styles_dict.update(style_cls.styles)
+
+ if style_dict is not None:
+ styles_dict.update(style_dict)
+
+ return style_from_dict(styles_dict, include_defaults=include_defaults)
+
+
+class PygmentsStyle(Style):
+ " Deprecated. "
+ def __new__(cls, pygments_style_cls):
+ assert issubclass(pygments_style_cls, pygments_Style)
+ return style_from_dict(pygments_style_cls.styles)
+
+ def invalidation_hash(self):
+ pass
+
+ @classmethod
+ def from_defaults(cls, style_dict=None,
+ pygments_style_cls=pygments_DefaultStyle,
+ include_extensions=True):
+ " Deprecated. "
+ return style_from_pygments(
+ style_cls=pygments_style_cls,
+ style_dict=style_dict,
+ include_defaults=include_extensions)
diff --git a/contrib/python/prompt-toolkit/py2/prompt_toolkit/styles/utils.py b/contrib/python/prompt-toolkit/py2/prompt_toolkit/styles/utils.py
index 6087e76abe7..75982af3aba 100644
--- a/contrib/python/prompt-toolkit/py2/prompt_toolkit/styles/utils.py
+++ b/contrib/python/prompt-toolkit/py2/prompt_toolkit/styles/utils.py
@@ -1,45 +1,45 @@
-from __future__ import unicode_literals
-from .base import DEFAULT_ATTRS, Attrs
-
-__all__ = (
- 'split_token_in_parts',
- 'merge_attrs',
-)
-
-
-def split_token_in_parts(token):
- """
- Take a Token, and turn it in a list of tokens, by splitting
- it on ':' (taking that as a separator.)
- """
- result = []
- current = []
- for part in token + (':', ):
- if part == ':':
- if current:
- result.append(tuple(current))
- current = []
- else:
- current.append(part)
-
- return result
-
-
-def merge_attrs(list_of_attrs):
- """
- Take a list of :class:`.Attrs` instances and merge them into one.
- Every `Attr` in the list can override the styling of the previous one.
- """
- result = DEFAULT_ATTRS
-
- for attr in list_of_attrs:
- result = Attrs(
- color=attr.color or result.color,
- bgcolor=attr.bgcolor or result.bgcolor,
- bold=attr.bold or result.bold,
- underline=attr.underline or result.underline,
- italic=attr.italic or result.italic,
- blink=attr.blink or result.blink,
- reverse=attr.reverse or result.reverse)
-
- return result
+from __future__ import unicode_literals
+from .base import DEFAULT_ATTRS, Attrs
+
+__all__ = (
+ 'split_token_in_parts',
+ 'merge_attrs',
+)
+
+
+def split_token_in_parts(token):
+ """
+ Take a Token, and turn it in a list of tokens, by splitting
+ it on ':' (taking that as a separator.)
+ """
+ result = []
+ current = []
+ for part in token + (':', ):
+ if part == ':':
+ if current:
+ result.append(tuple(current))
+ current = []
+ else:
+ current.append(part)
+
+ return result
+
+
+def merge_attrs(list_of_attrs):
+ """
+ Take a list of :class:`.Attrs` instances and merge them into one.
+ Every `Attr` in the list can override the styling of the previous one.
+ """
+ result = DEFAULT_ATTRS
+
+ for attr in list_of_attrs:
+ result = Attrs(
+ color=attr.color or result.color,
+ bgcolor=attr.bgcolor or result.bgcolor,
+ bold=attr.bold or result.bold,
+ underline=attr.underline or result.underline,
+ italic=attr.italic or result.italic,
+ blink=attr.blink or result.blink,
+ reverse=attr.reverse or result.reverse)
+
+ return result