(name, cli_style)
| 59 | |
| 60 | |
| 61 | def style_factory(name, cli_style): |
| 62 | try: |
| 63 | style = pygments.styles.get_style_by_name(name) |
| 64 | except ClassNotFound: |
| 65 | style = pygments.styles.get_style_by_name('native') |
| 66 | |
| 67 | prompt_styles = [] |
| 68 | # prompt-toolkit used pygments tokens for styling before, switched to style |
| 69 | # names in 2.0. Convert old token types to new style names, for backwards compatibility. |
| 70 | for token in cli_style: |
| 71 | if token.startswith('Token.'): |
| 72 | # treat as pygments token (1.0) |
| 73 | token_type, style_value = parse_pygments_style( |
| 74 | token, style, cli_style) |
| 75 | if token_type in TOKEN_TO_PROMPT_STYLE: |
| 76 | prompt_style = TOKEN_TO_PROMPT_STYLE[token_type] |
| 77 | prompt_styles.append((prompt_style, style_value)) |
| 78 | else: |
| 79 | # we don't want to support tokens anymore |
| 80 | logger.error('Unhandled style / class name: %s', token) |
| 81 | else: |
| 82 | # treat as prompt style name (2.0). See default style names here: |
| 83 | # https://github.com/jonathanslenders/python-prompt-toolkit/blob/master/prompt_toolkit/styles/defaults.py |
| 84 | prompt_styles.append((token, cli_style[token])) |
| 85 | |
| 86 | override_style = Style([('bottom-toolbar', 'noreverse')]) |
| 87 | return merge_styles([ |
| 88 | style_from_pygments_cls(style), |
| 89 | override_style, |
| 90 | Style(prompt_styles) |
| 91 | ]) |
| 92 | |
| 93 | |
| 94 | def style_factory_output(name, cli_style): |
no test coverage detected