MCPcopy Create free account
hub / github.com/dbcli/mycli / style_factory_helpers

Function style_factory_helpers

mycli/clistyle.py:170–210  ·  view source on GitHub ↗
(
    name: str,
    cli_style: dict[str, str],
    warnings: bool = False,
)

Source from the content-addressed store, hash-verified

168
169
170def style_factory_helpers(
171 name: str,
172 cli_style: dict[str, str],
173 warnings: bool = False,
174) -> PygmentsStyle:
175 try:
176 style: dict[PygmentsStyle | str, str] = pygments.styles.get_style_by_name(name).styles
177 except ClassNotFound:
178 style = pygments.styles.get_style_by_name("native").styles
179
180 for token in cli_style:
181 if token.startswith("Token."):
182 token_type, style_value = parse_pygments_style(token, style, cli_style)
183 if is_valid_pygments(style_value):
184 style.update({token_type: style_value})
185 elif token in PROMPT_STYLE_TO_TOKEN:
186 token_type = PROMPT_STYLE_TO_TOKEN[token]
187 if is_valid_pygments(cli_style[token]):
188 style.update({token_type: cli_style[token]})
189 elif token in OVERRIDE_STYLE_TO_TOKEN:
190 token_type = OVERRIDE_STYLE_TO_TOKEN[token]
191 if is_valid_pygments(cli_style[token]):
192 style.update({token_type: cli_style[token]})
193 else:
194 # TODO: cli helpers will have to switch to ptk.Style
195 logger.error("Unhandled style / class name: %s", token)
196
197 if warnings:
198 for warning_token in list(style.keys()):
199 if 'Warnings' not in str(warning_token):
200 continue
201 warning_str = str(warning_token)
202 output_str = warning_str.replace('Warnings', 'Output')
203 output_token = string_to_tokentype(output_str)
204 style[output_token] = style[warning_token]
205
206 class OutputStyle(PygmentsStyle):
207 default_style = ""
208 styles = style
209
210 return OutputStyle

Callers 1

__init__Method · 0.90

Calls 3

parse_pygments_styleFunction · 0.85
is_valid_pygmentsFunction · 0.85
errorMethod · 0.45

Tested by

no test coverage detected