MCPcopy Index your code
hub / github.com/dbcli/pgcli / style_factory

Function style_factory

pgcli/pgstyle.py:65–90  ·  view source on GitHub ↗
(name, cli_style)

Source from the content-addressed store, hash-verified

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

Callers 1

_build_cliMethod · 0.85

Calls 1

parse_pygments_styleFunction · 0.85

Tested by

no test coverage detected