本文整理汇总了Python中prompt_toolkit.styles.pygments.style_from_pygments_cls方法的典型用法代码示例。如果您正苦于以下问题:Python pygments.style_from_pygments_cls方法的具体用法?Python pygments.style_from_pygments_cls怎么用?Python pygments.style_from_pygments_cls使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类prompt_toolkit.styles.pygments
的用法示例。
在下文中一共展示了pygments.style_from_pygments_cls方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: prompt
# 需要导入模块: from prompt_toolkit.styles import pygments [as 别名]
# 或者: from prompt_toolkit.styles.pygments import style_from_pygments_cls [as 别名]
def prompt(self, msg):
"""Get input using prompt_toolkit."""
try:
# prompt_toolkit v2
prompt = prompt_toolkit.PromptSession(history=self.history).prompt
except AttributeError:
# prompt_toolkit v1
prompt = partial(prompt_toolkit.prompt, history=self.history)
return prompt(
msg,
multiline=self.multiline,
vi_mode=self.vi_mode,
wrap_lines=self.wrap_lines,
enable_history_search=self.history_search,
lexer=PygmentsLexer(CoconutLexer),
style=style_from_pygments_cls(
pygments.styles.get_style_by_name(self.style),
),
)
示例2: print_packets
# 需要导入模块: from prompt_toolkit.styles import pygments [as 别名]
# 或者: from prompt_toolkit.styles.pygments import style_from_pygments_cls [as 别名]
def print_packets(path: list, nodes: dict) -> None:
tokens = []
for e in path[:-1]:
node = nodes[e.dst]
p = node.render()
line = '{} = {}'.format(node.name.replace('-', '_'), repr(p))
tokens.extend(list(pygments.lex(line, lexer=Python3Lexer())))
# p = self.fuzz_node.render()
node = nodes[path[-1].dst]
p = node.render()
line = '{} = {}'.format(node.name.replace('-', '_'), repr(p))
print(pygments.highlight(line, Python3Lexer(), Terminal256Formatter(style='rrt')))
# tokens.extend(list(pygments.lex(line, lexer=Python3Lexer())))
# style = style_from_pygments_cls(get_style_by_name('colorful'))
# print_formatted_text(PygmentsTokens(tokens), style=style)
# --------------------------------------------------------------- #
示例3: style_factory
# 需要导入模块: from prompt_toolkit.styles import pygments [as 别名]
# 或者: from prompt_toolkit.styles.pygments import style_from_pygments_cls [as 别名]
def style_factory(name, cli_style):
try:
style = pygments.styles.get_style_by_name(name)
except ClassNotFound:
style = pygments.styles.get_style_by_name("native")
prompt_styles = []
# prompt-toolkit used pygments tokens for styling before, switched to style
# names in 2.0. Convert old token types to new style names, for backwards compatibility.
for token in cli_style:
if token.startswith("Token."):
# treat as pygments token (1.0)
token_type, style_value = parse_pygments_style(token, style, cli_style)
if token_type in TOKEN_TO_PROMPT_STYLE:
prompt_style = TOKEN_TO_PROMPT_STYLE[token_type]
prompt_styles.append((prompt_style, style_value))
else:
# we don't want to support tokens anymore
logger.error("Unhandled style / class name: %s", token)
else:
# treat as prompt style name (2.0). See default style names here:
# https://github.com/jonathanslenders/python-prompt-toolkit/blob/master/prompt_toolkit/styles/defaults.py
prompt_styles.append((token, cli_style[token]))
override_style = Style([("bottom-toolbar", "noreverse")])
return merge_styles(
[style_from_pygments_cls(style), override_style, Style(prompt_styles)]
)
示例4: get_all_code_styles
# 需要导入模块: from prompt_toolkit.styles import pygments [as 别名]
# 或者: from prompt_toolkit.styles.pygments import style_from_pygments_cls [as 别名]
def get_all_code_styles() -> Dict[str, BaseStyle]:
"""
Return a mapping from style names to their classes.
"""
result: Dict[str, BaseStyle] = {
name: style_from_pygments_cls(get_style_by_name(name))
for name in get_all_styles()
}
result["win32"] = Style.from_dict(win32_code_style)
return result
示例5: get_editor_style_by_name
# 需要导入模块: from prompt_toolkit.styles import pygments [as 别名]
# 或者: from prompt_toolkit.styles.pygments import style_from_pygments_cls [as 别名]
def get_editor_style_by_name(name):
"""
Get Style class.
This raises `pygments.util.ClassNotFound` when there is no style with this
name.
"""
if name == 'vim':
vim_style = Style.from_dict(default_vim_style)
else:
vim_style = style_from_pygments_cls(get_style_by_name(name))
return merge_styles([
vim_style,
Style.from_dict(style_extensions),
])
示例6: loop
# 需要导入模块: from prompt_toolkit.styles import pygments [as 别名]
# 或者: from prompt_toolkit.styles.pygments import style_from_pygments_cls [as 别名]
def loop(cmd, history_file):
buf = create_buffer(cmd, history_file)
key_bindings = KeyBindings()
bind_keys(buf, key_bindings)
layout = create_layout(
buffer=buf,
multiline=True,
lexer=PostgresLexer,
extra_input_processors=[
ConditionalProcessor(
processor=HighlightMatchingBracketProcessor(chars='[](){}'),
filter=HasFocus(DEFAULT_BUFFER) & ~IsDone())
],
get_bottom_toolbar_tokens=lambda: get_toolbar_tokens(cmd),
get_prompt_tokens=lambda: [('class:prompt', 'cr> ')]
)
output = get_default_output()
app = Application(
layout=layout,
style=style_from_pygments_cls(CrateStyle),
key_bindings=merge_key_bindings([
key_bindings,
load_open_in_editor_bindings()
]),
editing_mode=_get_editing_mode(),
output=output
)
cmd.get_num_columns = lambda: output.get_size().columns
while True:
try:
text = app.run()
if text:
cmd.process(text)
buf.reset()
except ProgrammingError as e:
if '401' in e.message:
username = cmd.username
password = cmd.password
cmd.username = input('Username: ')
cmd.password = getpass()
try:
cmd.process(text)
except ProgrammingError as ex:
# fallback to existing user/pw
cmd.username = username
cmd.password = password
cmd.logger.warn(str(ex))
else:
cmd.logger.warn(str(e))
except KeyboardInterrupt:
if isinstance(app.layout.current_control, SearchBufferControl):
app.layout.current_control = app.layout.previous_control
else:
cmd.logger.warn("Query not cancelled. Run KILL <jobId> to cancel it")
buf.reset()
except EOFError:
cmd.logger.warn('Bye!')
return
示例7: main
# 需要导入模块: from prompt_toolkit.styles import pygments [as 别名]
# 或者: from prompt_toolkit.styles.pygments import style_from_pygments_cls [as 别名]
def main():
history = FileHistory(os.path.expanduser('~/.gsheetsdb_history'))
arguments = docopt(__doc__, version=__version__.__version__)
auth = {
'service_account_file': arguments['--service-account-file'],
'subject': arguments['--subject'],
}
credentials = get_credentials_from_auth(**auth)
connection = connect(credentials)
headers = int(arguments['--headers'])
cursor = connection.cursor()
lexer = PygmentsLexer(SqlLexer)
words = keywords + aggregate_functions + scalar_functions
completer = WordCompleter(words, ignore_case=True)
style = style_from_pygments_cls(get_style_by_name('manni'))
while True:
try:
query = prompt(
'sql> ', lexer=lexer, completer=completer,
style=style, history=history)
except (EOFError, KeyboardInterrupt):
break # Control-D pressed.
# run query
query = query.strip('; ').replace('%', '%%')
if query:
try:
result = cursor.execute(query, headers=headers)
except Exception as e:
if arguments['--raise']:
raise
print(e)
continue
columns = [t[0] for t in cursor.description or []]
print(tabulate(result, headers=columns))
print('See ya!')