diff options
author | shadchin <shadchin@yandex-team.ru> | 2022-02-10 16:44:30 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:44:30 +0300 |
commit | 2598ef1d0aee359b4b6d5fdd1758916d5907d04f (patch) | |
tree | 012bb94d777798f1f56ac1cec429509766d05181 /contrib/python/prompt-toolkit/py3/prompt_toolkit/styles/pygments.py | |
parent | 6751af0b0c1b952fede40b19b71da8025b5d8bcf (diff) | |
download | ydb-2598ef1d0aee359b4b6d5fdd1758916d5907d04f.tar.gz |
Restoring authorship annotation for <shadchin@yandex-team.ru>. Commit 1 of 2.
Diffstat (limited to 'contrib/python/prompt-toolkit/py3/prompt_toolkit/styles/pygments.py')
-rw-r--r-- | contrib/python/prompt-toolkit/py3/prompt_toolkit/styles/pygments.py | 134 |
1 files changed, 67 insertions, 67 deletions
diff --git a/contrib/python/prompt-toolkit/py3/prompt_toolkit/styles/pygments.py b/contrib/python/prompt-toolkit/py3/prompt_toolkit/styles/pygments.py index 382e5e315b..d3d0024b7c 100644 --- a/contrib/python/prompt-toolkit/py3/prompt_toolkit/styles/pygments.py +++ b/contrib/python/prompt-toolkit/py3/prompt_toolkit/styles/pygments.py @@ -1,67 +1,67 @@ -""" -Adaptor for building prompt_toolkit styles, starting from a Pygments style. - -Usage:: - - from pygments.styles.tango import TangoStyle - style = style_from_pygments_cls(pygments_style_cls=TangoStyle) -""" -from typing import TYPE_CHECKING, Dict, Type - -from .style import Style - -if TYPE_CHECKING: - from pygments.style import Style as PygmentsStyle - from pygments.token import Token - - -__all__ = [ - "style_from_pygments_cls", - "style_from_pygments_dict", - "pygments_token_to_classname", -] - - -def style_from_pygments_cls(pygments_style_cls: Type["PygmentsStyle"]) -> Style: - """ - 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_cls - from pygments.styles import get_style_by_name - style = style_from_pygments_cls(get_style_by_name('monokai')) - - :param pygments_style_cls: Pygments style class to start from. - """ - # Import inline. - from pygments.style import Style as PygmentsStyle - - assert issubclass(pygments_style_cls, PygmentsStyle) - - return style_from_pygments_dict(pygments_style_cls.styles) - - -def style_from_pygments_dict(pygments_dict: Dict["Token", str]) -> Style: - """ - Create a :class:`.Style` instance from a Pygments style dictionary. - (One that maps Token objects to style strings.) - """ - pygments_style = [] - - for token, style in pygments_dict.items(): - pygments_style.append((pygments_token_to_classname(token), style)) - - return Style(pygments_style) - - -def pygments_token_to_classname(token: "Token") -> str: - """ - Turn e.g. `Token.Name.Exception` into `'pygments.name.exception'`. - - (Our Pygments lexer will also turn the tokens that pygments produces in a - prompt_toolkit list of fragments that match these styling rules.) - """ - parts = ("pygments",) + token - return ".".join(parts).lower() +""" +Adaptor for building prompt_toolkit styles, starting from a Pygments style. + +Usage:: + + from pygments.styles.tango import TangoStyle + style = style_from_pygments_cls(pygments_style_cls=TangoStyle) +""" +from typing import TYPE_CHECKING, Dict, Type + +from .style import Style + +if TYPE_CHECKING: + from pygments.style import Style as PygmentsStyle + from pygments.token import Token + + +__all__ = [ + "style_from_pygments_cls", + "style_from_pygments_dict", + "pygments_token_to_classname", +] + + +def style_from_pygments_cls(pygments_style_cls: Type["PygmentsStyle"]) -> Style: + """ + 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_cls + from pygments.styles import get_style_by_name + style = style_from_pygments_cls(get_style_by_name('monokai')) + + :param pygments_style_cls: Pygments style class to start from. + """ + # Import inline. + from pygments.style import Style as PygmentsStyle + + assert issubclass(pygments_style_cls, PygmentsStyle) + + return style_from_pygments_dict(pygments_style_cls.styles) + + +def style_from_pygments_dict(pygments_dict: Dict["Token", str]) -> Style: + """ + Create a :class:`.Style` instance from a Pygments style dictionary. + (One that maps Token objects to style strings.) + """ + pygments_style = [] + + for token, style in pygments_dict.items(): + pygments_style.append((pygments_token_to_classname(token), style)) + + return Style(pygments_style) + + +def pygments_token_to_classname(token: "Token") -> str: + """ + Turn e.g. `Token.Name.Exception` into `'pygments.name.exception'`. + + (Our Pygments lexer will also turn the tokens that pygments produces in a + prompt_toolkit list of fragments that match these styling rules.) + """ + parts = ("pygments",) + token + return ".".join(parts).lower() |