MCPcopy Index your code
hub / github.com/dbcli/mycli / style_factory_ptoolkit

Function style_factory_ptoolkit

mycli/clistyle.py:140–167  ·  view source on GitHub ↗
(name: str, cli_style: dict[str, str])

Source from the content-addressed store, hash-verified

138
139
140def 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
170def style_factory_helpers(

Callers 2

__init__Method · 0.90
_build_prompt_sessionFunction · 0.90

Calls 3

parse_pygments_styleFunction · 0.85
is_valid_ptoolkitFunction · 0.85
errorMethod · 0.45

Tested by

no test coverage detected