(name: str, cli_style: dict[str, str])
| 138 | |
| 139 | |
| 140 | def style_factory_ptoolkit(name: str, cli_style: dict[str, str]) -> _MergedStyle: |
| 141 | try: |
| 142 | style: PygmentsStyle = pygments.styles.get_style_by_name(name) |
| 143 | except ClassNotFound: |
| 144 | style = pygments.styles.get_style_by_name("native") |
| 145 | |
| 146 | prompt_styles: list[tuple[str, str]] = [] |
| 147 | # prompt-toolkit used pygments tokens for styling before, switched to style |
| 148 | # names in 2.0. Convert old token types to new style names, for backwards compatibility. |
| 149 | for token in cli_style: |
| 150 | if token.startswith("Token."): |
| 151 | # treat as pygments token (1.0) |
| 152 | token_type, style_value = parse_pygments_style(token, style, cli_style) |
| 153 | if token_type in TOKEN_TO_PROMPT_STYLE: |
| 154 | prompt_style = TOKEN_TO_PROMPT_STYLE[token_type] |
| 155 | if is_valid_ptoolkit(style_value): |
| 156 | prompt_styles.append((prompt_style, style_value)) |
| 157 | else: |
| 158 | # we don't want to support tokens anymore |
| 159 | logger.error("Unhandled style / class name: %s", token) |
| 160 | else: |
| 161 | # treat as prompt style name (2.0). See default style names here: |
| 162 | # https://github.com/jonathanslenders/python-prompt-toolkit/blob/master/prompt_toolkit/styles/defaults.py |
| 163 | if is_valid_ptoolkit(cli_style[token]): |
| 164 | prompt_styles.append((token, cli_style[token])) |
| 165 | |
| 166 | override_style: Style = Style([("bottom-toolbar", "noreverse")]) |
| 167 | return merge_styles([style_from_pygments_cls(style), override_style, Style(prompt_styles)]) |
| 168 | |
| 169 | |
| 170 | def style_factory_helpers( |
no test coverage detected