当前位置: 首页>>代码示例>>Python>>正文


Python style.Style方法代码示例

本文整理汇总了Python中pygments.style.Style方法的典型用法代码示例。如果您正苦于以下问题:Python style.Style方法的具体用法?Python style.Style怎么用?Python style.Style使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pygments.style的用法示例。


在下文中一共展示了style.Style方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: json_out

# 需要导入模块: from pygments import style [as 别名]
# 或者: from pygments.style import Style [as 别名]
def json_out(data, pretty=False, mono=False, piped_out=False):

    if not mono and not piped_out:
        # set colors
        class JcStyle(Style):
            styles = set_env_colors()

        if pretty:
            print(highlight(json.dumps(data, indent=2), JsonLexer(), Terminal256Formatter(style=JcStyle))[0:-1])
        else:
            print(highlight(json.dumps(data), JsonLexer(), Terminal256Formatter(style=JcStyle))[0:-1])
    else:
        if pretty:
            print(json.dumps(data, indent=2))
        else:
            print(json.dumps(data)) 
开发者ID:kellyjonbrazil,项目名称:jc,代码行数:18,代码来源:cli.py

示例2: style_factory_output

# 需要导入模块: from pygments import style [as 别名]
# 或者: from pygments.style import Style [as 别名]
def style_factory_output(name, cli_style):
    try:
        style = pygments.styles.get_style_by_name(name).styles
    except ClassNotFound:
        style = pygments.styles.get_style_by_name("native").styles

    for token in cli_style:
        if token.startswith("Token."):
            token_type, style_value = parse_pygments_style(token, style, cli_style)
            style.update({token_type: style_value})
        elif token in PROMPT_STYLE_TO_TOKEN:
            token_type = PROMPT_STYLE_TO_TOKEN[token]
            style.update({token_type: cli_style[token]})
        else:
            # TODO: cli helpers will have to switch to ptk.Style
            logger.error("Unhandled style / class name: %s", token)

    class OutputStyle(PygmentsStyle):
        default_style = ""
        styles = style

    return OutputStyle 
开发者ID:dbcli,项目名称:pgcli,代码行数:24,代码来源:pgstyle.py

示例3: style_factory_output

# 需要导入模块: from pygments import style [as 别名]
# 或者: from pygments.style import Style [as 别名]
def style_factory_output(name, cli_style):
    try:
        style = pygments.styles.get_style_by_name(name).styles
    except ClassNotFound:
        style = pygments.styles.get_style_by_name('native').styles

    for token in cli_style:
        if token.startswith('Token.'):
            token_type, style_value = parse_pygments_style(
                token, style, cli_style)
            style.update({token_type: style_value})
        elif token in PROMPT_STYLE_TO_TOKEN:
            token_type = PROMPT_STYLE_TO_TOKEN[token]
            style.update({token_type: cli_style[token]})
        else:
            # TODO: cli helpers will have to switch to ptk.Style
            logger.error('Unhandled style / class name: %s', token)
        
        class OutputStyle(PygmentsStyle):
            default_style = ""
            styles = style
        
        return OutputStyle 
开发者ID:dbcli,项目名称:athenacli,代码行数:25,代码来源:clistyle.py

示例4: test_get_style_defs_contains_style_specific_line_numbers_styles

# 需要导入模块: from pygments import style [as 别名]
# 或者: from pygments.style import Style [as 别名]
def test_get_style_defs_contains_style_specific_line_numbers_styles():
    class TestStyle(Style):
        line_number_color = '#ff0000'
        line_number_background_color = '#0000ff'
        line_number_special_color = '#00ff00'
        line_number_special_background_color = '#ffffff'

    style_defs = HtmlFormatter(style=TestStyle).get_style_defs().splitlines()

    assert style_defs[1] == (
        'td.linenos pre '
        '{ color: #ff0000; background-color: #0000ff; padding: 0 5px 0 5px; }'
    )
    assert style_defs[2] == (
        'span.linenos '
        '{ color: #ff0000; background-color: #0000ff; padding: 0 5px 0 5px; }'
    )
    assert style_defs[3] == (
        'td.linenos pre.special '
        '{ color: #00ff00; background-color: #ffffff; padding: 0 5px 0 5px; }'
    )
    assert style_defs[4] == (
        'span.linenos.special '
        '{ color: #00ff00; background-color: #ffffff; padding: 0 5px 0 5px; }'
    ) 
开发者ID:pygments,项目名称:pygments,代码行数:27,代码来源:test_html_formatter.py

示例5: style_from_pygments_cls

# 需要导入模块: from pygments import style [as 别名]
# 或者: from pygments.style import Style [as 别名]
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) 
开发者ID:prompt-toolkit,项目名称:python-prompt-toolkit,代码行数:21,代码来源:pygments.py

示例6: set_default_style

# 需要导入模块: from pygments import style [as 别名]
# 或者: from pygments.style import Style [as 别名]
def set_default_style(style):
    """Sets default global style to be used by ``prettyprinter.cpprint``.

    :param style: the style to set, either subclass of
                  ``pygments.styles.Style`` or one of ``'dark'``, ``'light'``
    """
    global default_style
    if style == 'dark':
        style = default_dark_style
    elif style == 'light':
        style = default_light_style

    if not issubclass(style, Style):
        raise TypeError(
            "style must be a subclass of pygments.styles.Style or "
            "one of 'dark', 'light'. Got {}".format(repr(style))
        )
    default_style = style 
开发者ID:tommikaikkonen,项目名称:prettyprinter,代码行数:20,代码来源:color.py

示例7: test_override_missing_value_with_style

# 需要导入模块: from pygments import style [as 别名]
# 或者: from pygments.style import Style [as 别名]
def test_override_missing_value_with_style():
    """Test that *override_missing_value()* styles output."""

    class NullStyle(Style):
        styles = {
            Token.Output.Null: '#0f0'
        }

    headers = ['h1', 'h2']
    data = [[None, '2'], ['abc', None]]

    expected_headers = ['h1', 'h2']
    expected_data = [
        ['\x1b[38;5;10m<null>\x1b[39m', '2'],
        ['abc', '\x1b[38;5;10m<null>\x1b[39m']
    ]
    results = override_missing_value(data, headers, 
                                     style=NullStyle, missing_value="<null>")

    assert (expected_data, expected_headers) == (list(results[0]), results[1]) 
开发者ID:dbcli,项目名称:cli_helpers,代码行数:22,代码来源:test_preprocessors.py

示例8: test_style_output

# 需要导入模块: from pygments import style [as 别名]
# 或者: from pygments.style import Style [as 别名]
def test_style_output():
    """Test that *style_output()* styles output."""

    class CliStyle(Style):
        default_style = ""
        styles = {
            Token.Output.Header: 'bold ansibrightred',
            Token.Output.OddRow: 'bg:#eee #111',
            Token.Output.EvenRow: '#0f0'
        }
    headers = ['h1', 'h2']
    data = [['观音', '2'], ['Ποσειδῶν', 'b']]

    expected_headers = ['\x1b[91;01mh1\x1b[39;00m', '\x1b[91;01mh2\x1b[39;00m']
    expected_data = [['\x1b[38;5;233;48;5;7m观音\x1b[39;49m',
                      '\x1b[38;5;233;48;5;7m2\x1b[39;49m'],
                     ['\x1b[38;5;10mΠοσειδῶν\x1b[39m', '\x1b[38;5;10mb\x1b[39m']]
    results = style_output(data, headers, style=CliStyle)

    assert (expected_data, expected_headers) == (list(results[0]), results[1]) 
开发者ID:dbcli,项目名称:cli_helpers,代码行数:22,代码来源:test_preprocessors.py

示例9: test_style_output_custom_tokens

# 需要导入模块: from pygments import style [as 别名]
# 或者: from pygments.style import Style [as 别名]
def test_style_output_custom_tokens():
    """Test that *style_output()* styles output with custom token names."""

    class CliStyle(Style):
        default_style = ""
        styles = {
            Token.Results.Headers: 'bold ansibrightred',
            Token.Results.OddRows: 'bg:#eee #111',
            Token.Results.EvenRows: '#0f0'
        }
    headers = ['h1', 'h2']
    data = [['1', '2'], ['a', 'b']]

    expected_headers = ['\x1b[91;01mh1\x1b[39;00m', '\x1b[91;01mh2\x1b[39;00m']
    expected_data = [['\x1b[38;5;233;48;5;7m1\x1b[39;49m',
                      '\x1b[38;5;233;48;5;7m2\x1b[39;49m'],
                     ['\x1b[38;5;10ma\x1b[39m', '\x1b[38;5;10mb\x1b[39m']]

    output = style_output(
        data, headers, style=CliStyle,
        header_token='Token.Results.Headers',
        odd_row_token='Token.Results.OddRows',
        even_row_token='Token.Results.EvenRows')

    assert (expected_data, expected_headers) == (list(output[0]), output[1]) 
开发者ID:dbcli,项目名称:cli_helpers,代码行数:27,代码来源:test_preprocessors.py

示例10: style_factory_output

# 需要导入模块: from pygments import style [as 别名]
# 或者: from pygments.style import Style [as 别名]
def style_factory_output(name, cli_style):
    try:
        style = pygments.styles.get_style_by_name(name).styles
    except ClassNotFound:
        style = pygments.styles.get_style_by_name('native').styles

    for token in cli_style:
        if token.startswith('Token.'):
            token_type, style_value = parse_pygments_style(
                token, style, cli_style)
            style.update({token_type: style_value})
        elif token in PROMPT_STYLE_TO_TOKEN:
            token_type = PROMPT_STYLE_TO_TOKEN[token]
            style.update({token_type: cli_style[token]})
        else:
            # TODO: cli helpers will have to switch to ptk.Style
            logger.error('Unhandled style / class name: %s', token)

    class OutputStyle(PygmentsStyle):   # pylint: disable=too-few-public-methods
        default_style = ""
        styles = style

    return OutputStyle 
开发者ID:dbcli,项目名称:mssql-cli,代码行数:25,代码来源:mssqlstyle.py

示例11: __init__

# 需要导入模块: from pygments import style [as 别名]
# 或者: from pygments.style import Style [as 别名]
def __init__(
        self,
        code: str,
        lexer_name: str,
        *,
        theme: Union[str, Type[PygmentsStyle]] = DEFAULT_THEME,
        dedent: bool = False,
        line_numbers: bool = False,
        start_line: int = 1,
        line_range: Tuple[int, int] = None,
        highlight_lines: Set[int] = None,
        code_width: Optional[int] = None,
        tab_size: int = 4,
        word_wrap: bool = False
    ) -> None:
        self.code = code
        self.lexer_name = lexer_name
        self.dedent = dedent
        self.line_numbers = line_numbers
        self.start_line = start_line
        self.line_range = line_range
        self.highlight_lines = highlight_lines or set()
        self.code_width = code_width
        self.tab_size = tab_size
        self.word_wrap = word_wrap

        self._style_cache: Dict[Any, Style] = {}

        if not isinstance(theme, str) and issubclass(theme, PygmentsStyle):
            self._pygments_style_class = theme
        else:
            try:
                self._pygments_style_class = get_style_by_name(theme)
            except ClassNotFound:
                self._pygments_style_class = get_style_by_name("default")
        self._background_color = self._pygments_style_class.background_color 
开发者ID:willmcgugan,项目名称:rich,代码行数:38,代码来源:syntax.py

示例12: style_from_dict

# 需要导入模块: from pygments import style [as 别名]
# 或者: from pygments.style import Style [as 别名]
def style_from_dict(d):
        styles = default_style_extensions.copy()
        styles.update(DefaultStyle.styles)
        styles.update(d)
        PromptStyle = type('PromptStyle', (Style,), {'styles': styles})
        return PromptStyle 
开发者ID:eonpatapon,项目名称:contrail-api-cli,代码行数:8,代码来源:style.py

示例13: test_style_factory

# 需要导入模块: from pygments import style [as 别名]
# 或者: from pygments.style import Style [as 别名]
def test_style_factory():
    """Test that a Pygments Style class is created."""
    header = "bold underline #ansired"
    cli_style = {"Token.Output.Header": header}
    style = style_factory("default", cli_style)

    assert isinstance(style(), Style)
    assert Token.Output.Header in style.styles
    assert header == style.styles[Token.Output.Header] 
开发者ID:dbcli,项目名称:litecli,代码行数:11,代码来源:test_clistyle.py

示例14: test_style_factory_unknown_name

# 需要导入模块: from pygments import style [as 别名]
# 或者: from pygments.style import Style [as 别名]
def test_style_factory_unknown_name():
    """Test that an unrecognized name will not throw an error."""
    style = style_factory("foobar", {})

    assert isinstance(style(), Style) 
开发者ID:dbcli,项目名称:litecli,代码行数:7,代码来源:test_clistyle.py

示例15: override_missing_value

# 需要导入模块: from pygments import style [as 别名]
# 或者: from pygments.style import Style [as 别名]
def override_missing_value(data, headers, style=None,
                           missing_value_token="Token.Output.Null",
                           missing_value='', **_):
    """Override missing values in the *data* with *missing_value*.

    A missing value is any value that is :data:`None`.

    :param iterable data: An :term:`iterable` (e.g. list) of rows.
    :param iterable headers: The column headers.
    :param style: Style for missing_value.
    :param missing_value_token: The Pygments token used for missing data.
    :param missing_value: The default value to use for missing data.
    :return: The processed data and headers.
    :rtype: tuple

    """
    def fields():
        for row in data:
            processed = []
            for field in row:
                if field is None and style and HAS_PYGMENTS:
                    styled = utils.style_field(missing_value_token, missing_value, style)
                    processed.append(styled)
                elif field is None:
                    processed.append(missing_value)
                else:
                    processed.append(field)
            yield processed

    return (fields(), headers) 
开发者ID:dbcli,项目名称:cli_helpers,代码行数:32,代码来源:preprocessors.py


注:本文中的pygments.style.Style方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。