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


Python pygments.styles方法代码示例

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


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

示例1: style_factory_output

# 需要导入模块: import pygments [as 别名]
# 或者: from pygments import styles [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

示例2: prompt

# 需要导入模块: import pygments [as 别名]
# 或者: from pygments import styles [as 别名]
def prompt(self, msg):
        """Get input using prompt_toolkit."""
        try:
            # prompt_toolkit v2
            prompt = prompt_toolkit.PromptSession(history=self.history).prompt
        except AttributeError:
            # prompt_toolkit v1
            prompt = partial(prompt_toolkit.prompt, history=self.history)
        return prompt(
            msg,
            multiline=self.multiline,
            vi_mode=self.vi_mode,
            wrap_lines=self.wrap_lines,
            enable_history_search=self.history_search,
            lexer=PygmentsLexer(CoconutLexer),
            style=style_from_pygments_cls(
                pygments.styles.get_style_by_name(self.style),
            ),
        ) 
开发者ID:evhub,项目名称:coconut,代码行数:21,代码来源:util.py

示例3: style_factory_output

# 需要导入模块: import pygments [as 别名]
# 或者: from pygments import styles [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: style_factory_output

# 需要导入模块: import pygments [as 别名]
# 或者: from pygments import styles [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

示例5: parse_pygments_style

# 需要导入模块: import pygments [as 别名]
# 或者: from pygments import styles [as 别名]
def parse_pygments_style(token_name, style_object, style_dict):
    """Parse token type and style string.

    :param token_name: str name of Pygments token. Example: "Token.String"
    :param style_object: pygments.style.Style instance to use as base
    :param style_dict: dict of token names and their styles, customized to this cli

    """
    token_type = string_to_tokentype(token_name)
    try:
        other_token_type = string_to_tokentype(style_dict[token_name])
        return token_type, style_object.styles[other_token_type]
    except AttributeError:
        return token_type, style_dict[token_name] 
开发者ID:dbcli,项目名称:pgcli,代码行数:16,代码来源:pgstyle.py

示例6: style_factory

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

    prompt_styles = []
    # prompt-toolkit used pygments tokens for styling before, switched to style
    # names in 2.0. Convert old token types to new style names, for backwards compatibility.
    for token in cli_style:
        if token.startswith("Token."):
            # treat as pygments token (1.0)
            token_type, style_value = parse_pygments_style(token, style, cli_style)
            if token_type in TOKEN_TO_PROMPT_STYLE:
                prompt_style = TOKEN_TO_PROMPT_STYLE[token_type]
                prompt_styles.append((prompt_style, style_value))
            else:
                # we don't want to support tokens anymore
                logger.error("Unhandled style / class name: %s", token)
        else:
            # treat as prompt style name (2.0). See default style names here:
            # https://github.com/jonathanslenders/python-prompt-toolkit/blob/master/prompt_toolkit/styles/defaults.py
            prompt_styles.append((token, cli_style[token]))

    override_style = Style([("bottom-toolbar", "noreverse")])
    return merge_styles(
        [style_from_pygments_cls(style), override_style, Style(prompt_styles)]
    ) 
开发者ID:dbcli,项目名称:pgcli,代码行数:30,代码来源:pgstyle.py

示例7: set_style

# 需要导入模块: import pygments [as 别名]
# 或者: from pygments import styles [as 别名]
def set_style(self, style):
        """Set pygments syntax highlighting style."""
        if style == "none":
            self.style = None
        elif prompt_toolkit is None:
            raise CoconutException("syntax highlighting is not supported on this Python version")
        elif style == "list":
            print("Coconut Styles: none, " + ", ".join(pygments.styles.get_all_styles()))
            sys.exit(0)
        elif style in pygments.styles.get_all_styles():
            self.style = style
        else:
            raise CoconutException("unrecognized pygments style", style, extra="use '--style list' to show all valid styles") 
开发者ID:evhub,项目名称:coconut,代码行数:15,代码来源:util.py

示例8: parse_pygments_style

# 需要导入模块: import pygments [as 别名]
# 或者: from pygments import styles [as 别名]
def parse_pygments_style(token_name, style_object, style_dict):
    """Parse token type and style string.

    :param token_name: str name of Pygments token. Example: "Token.String"
    :param style_object: pygments.style.Style instance to use as base
    :param style_dict: dict of token names and their styles, customized to this cli

    """
    token_type = string_to_tokentype(token_name)
    try:
        other_token_type = string_to_tokentype(style_dict[token_name])
        return token_type, style_object.styles[other_token_type]
    except AttributeError as err:
        return token_type, style_dict[token_name] 
开发者ID:dbcli,项目名称:litecli,代码行数:16,代码来源:clistyle.py

示例9: parse_pygments_style

# 需要导入模块: import pygments [as 别名]
# 或者: from pygments import styles [as 别名]
def parse_pygments_style(token_name, style_object, style_dict):
    """Parse token type and style string.
    :param token_name: str name of Pygments token. Example: "Token.String"
    :param style_object: pygments.style.Style instance to use as base
    :param style_dict: dict of token names and their styles, customized to this cli
    """
    token_type = string_to_tokentype(token_name)
    try:
        other_token_type = string_to_tokentype(style_dict[token_name])
        return token_type, style_object.styles[other_token_type]
    except AttributeError as err:
        return token_type, style_dict[token_name] 
开发者ID:dbcli,项目名称:athenacli,代码行数:14,代码来源:clistyle.py

示例10: style_factory

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

    prompt_styles = []
    # prompt-toolkit used pygments tokens for styling before, switched to style
    # names in 2.0. Convert old token types to new style names, for backwards compatibility.
    for token in cli_style:
        if token.startswith('Token.'):
            # treat as pygments token (1.0)
            token_type, style_value = parse_pygments_style(
                token, style, cli_style)
            if token_type in TOKEN_TO_PROMPT_STYLE:
                prompt_style = TOKEN_TO_PROMPT_STYLE[token_type]
                prompt_styles.append((prompt_style, style_value))
            else:
                # we don't want to support tokens anymore
                logger.error('Unhandled style / class name: %s', token)
        else:
            # treat as prompt style name (2.0). See default style names here:
            # https://github.com/jonathanslenders/python-prompt-toolkit/blob/master/prompt_toolkit/styles/defaults.py
            prompt_styles.append((token, cli_style[token]))

    override_style = Style([('bottom-toolbar', 'noreverse')])
    return merge_styles([
        style_from_pygments_cls(style),
        override_style,
        Style(prompt_styles)
    ]) 
开发者ID:dbcli,项目名称:athenacli,代码行数:33,代码来源:clistyle.py

示例11: parse_pygments_style

# 需要导入模块: import pygments [as 别名]
# 或者: from pygments import styles [as 别名]
def parse_pygments_style(token_name, style_object, style_dict):
    """Parse token type and style string.
    :param token_name: str name of Pygments token. Example: "Token.String"
    :param style_object: pygments.style.Style instance to use as base
    :param style_dict: dict of token names and their styles, customized to this cli
    """
    token_type = string_to_tokentype(token_name)
    try:
        other_token_type = string_to_tokentype(style_dict[token_name])
        return token_type, style_object.styles[other_token_type]
    except AttributeError:
        return token_type, style_dict[token_name] 
开发者ID:dbcli,项目名称:mssql-cli,代码行数:14,代码来源:mssqlstyle.py

示例12: process_cli

# 需要导入模块: import pygments [as 别名]
# 或者: from pygments import styles [as 别名]
def process_cli(self, args):
        if not PYGMENTS:
            self.error = MissingDependencyException('pygments is not available')
            return
        if not self.content:
            if not args.plugindata:
                if not args.plugininfile:
                    self.content = self.read_content_from_file('-')
                else:
                    self.content = self.read_content_from_file(args.plugininfile)
            else:
                self.content = args.plugindata
        if not self.content:
            return
        style = pygments.styles.get_style_by_name('colorful')
        if args.lexer:
            lexer = pygments.lexers.get_lexer_by_name(args.lexer)
        else:
            lexer = pygments.lexers.guess_lexer(self.content.decode())
        if args.formatter:
            self.log.info('Guessing formatter')
            formatter = pygments.formatters.get_formatter_by_name(args.formatter)
        else:
            import curses
            curses.setupterm()
            if curses.tigetnum('colors') >= 256:
                formatter = pygments.formatters.Terminal256Formatter(style=style, linenos=args.numbers)
            else:
                formatter = pygments.formatters.TerminalFormatter(linenos=args.numbers)
        return self.process(self.content, lexer=lexer, formatter=formatter) 
开发者ID:takeshixx,项目名称:deen,代码行数:32,代码来源:plugin_highlight.py


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