MCPcopy Create free account
hub / github.com/dbcli/mssql-cli / style_factory

Function style_factory

mssqlcli/mssqlstyle.py:61–91  ·  view source on GitHub ↗
(name, cli_style)

Source from the content-addressed store, hash-verified

59
60
61def 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
94def style_factory_output(name, cli_style):

Callers 1

_build_cliMethod · 0.90

Calls 1

parse_pygments_styleFunction · 0.85

Tested by

no test coverage detected