本文整理汇总了Python中prompt_toolkit.styles.Style.from_dict方法的典型用法代码示例。如果您正苦于以下问题:Python Style.from_dict方法的具体用法?Python Style.from_dict怎么用?Python Style.from_dict使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类prompt_toolkit.styles.Style
的用法示例。
在下文中一共展示了Style.from_dict方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_style
# 需要导入模块: from prompt_toolkit.styles import Style [as 别名]
# 或者: from prompt_toolkit.styles.Style import from_dict [as 别名]
def get_style():
return Style.from_dict(
{
"completion-menu.completion.current": "bg:#00aaaa #000000",
# "completion-menu.completion": "bg:#008888 #ffffff",
"completion-menu.completion.fuzzymatch.outside": "fg:#00aaaa",
"prompt1": "{} bold".format(prompt_colors[0]),
"prompt2": "{} bold".format(prompt_colors[1]),
"prompt3": "{} bold".format(prompt_colors[2]),
"state_index": "#ffd700",
"rprompt": "fg:{}".format(config.prompt_rprompt),
"bottom-toolbar": config.prompt_bottom_toolbar,
"prompt_toolbar_version": "bg:{}".format(config.prompt_toolbar_version),
"prompt_toolbar_states": "bg:{}".format(config.prompt_toolbar_states),
"prompt_toolbar_buffers": "bg:{}".format(config.prompt_toolbar_buffers),
"prompt_toolbar_type": "bg:{}".format(config.prompt_toolbar_type),
"prompt_toolbar_plugins": "bg:{}".format(config.prompt_toolbar_plugins),
"prompt_toolbar_errors": "bg:{}".format(config.prompt_toolbar_errors),
}
)
示例2: main
# 需要导入模块: from prompt_toolkit.styles import Style [as 别名]
# 或者: from prompt_toolkit.styles.Style import from_dict [as 别名]
def main():
style = Style.from_dict({"hello": "#ff0066", "world": "#44ff44 italic",})
# Print using a a list of text fragments.
text_fragments = FormattedText(
[("class:hello", "Hello "), ("class:world", "World"), ("", "\n"),]
)
print(text_fragments, style=style)
# Print using an HTML object.
print(HTML("<hello>hello</hello> <world>world</world>\n"), style=style)
# Print using an HTML object with inline styling.
print(
HTML(
'<style fg="#ff0066">hello</style> '
'<style fg="#44ff44"><i>world</i></style>\n'
)
)
# Print using ANSI escape sequences.
print(ANSI("\x1b[31mhello \x1b[32mworld\n"))
示例3: __init__
# 需要导入模块: from prompt_toolkit.styles import Style [as 别名]
# 或者: from prompt_toolkit.styles.Style import from_dict [as 别名]
def __init__(self, ipython_shell, *a, **kw):
kw["_completer"] = create_completer(
kw["get_globals"],
kw["get_globals"],
ipython_shell.magics_manager,
ipython_shell.alias_manager,
lambda: self.enable_dictionary_completion,
)
kw["_lexer"] = create_lexer()
kw["_validator"] = IPythonValidator(get_compiler_flags=self.get_compiler_flags)
super().__init__(*a, **kw)
self.ipython_shell = ipython_shell
self.all_prompt_styles["ipython"] = IPythonPrompt(ipython_shell.prompts)
self.prompt_style = "ipython"
# UI style for IPython. Add tokens that are used by IPython>5.0
style_dict = {}
style_dict.update(default_ui_style)
style_dict.update(
{
"pygments.prompt": "#009900",
"pygments.prompt-num": "#00ff00 bold",
"pygments.out-prompt": "#990000",
"pygments.out-prompt-num": "#ff0000 bold",
}
)
self.ui_styles = {"default": Style.from_dict(style_dict)}
self.use_ui_colorscheme("default")
示例4: get_all_code_styles
# 需要导入模块: from prompt_toolkit.styles import Style [as 别名]
# 或者: from prompt_toolkit.styles.Style import from_dict [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_all_ui_styles
# 需要导入模块: from prompt_toolkit.styles import Style [as 别名]
# 或者: from prompt_toolkit.styles.Style import from_dict [as 别名]
def get_all_ui_styles() -> Dict[str, BaseStyle]:
"""
Return a dict mapping {ui_style_name -> style_dict}.
"""
return {
"default": Style.from_dict(default_ui_style),
"blue": Style.from_dict(blue_ui_style),
}
示例6: print_in_colors
# 需要导入模块: from prompt_toolkit.styles import Style [as 别名]
# 或者: from prompt_toolkit.styles.Style import from_dict [as 别名]
def print_in_colors(out):
style = Style.from_dict({"cli_out": "fg:{}".format(config.cli_info_color)})
print_formatted_text(FormattedText([("class:cli_out", str(out))]), style=style)
示例7: main
# 需要导入模块: from prompt_toolkit.styles import Style [as 别名]
# 或者: from prompt_toolkit.styles.Style import from_dict [as 别名]
def main():
# Printing a manually constructed list of (Token, text) tuples.
text = [
(Token.Keyword, "print"),
(Token.Punctuation, "("),
(Token.Literal.String.Double, '"'),
(Token.Literal.String.Double, "hello"),
(Token.Literal.String.Double, '"'),
(Token.Punctuation, ")"),
(Token.Text, "\n"),
]
print_formatted_text(PygmentsTokens(text))
# Printing the output of a pygments lexer.
tokens = list(pygments.lex('print("Hello")', lexer=PythonLexer()))
print_formatted_text(PygmentsTokens(tokens))
# With a custom style.
style = Style.from_dict(
{
"pygments.keyword": "underline",
"pygments.literal.string": "bg:#00ff00 #ffffff",
}
)
print_formatted_text(PygmentsTokens(tokens), style=style)
示例8: test_formatted_text_with_style
# 需要导入模块: from prompt_toolkit.styles import Style [as 别名]
# 或者: from prompt_toolkit.styles.Style import from_dict [as 别名]
def test_formatted_text_with_style():
f = _Capture()
style = Style.from_dict({"hello": "#ff0066", "world": "#44ff44 italic",})
tokens = FormattedText([("class:hello", "Hello "), ("class:world", "world"),])
# NOTE: We pass the default (8bit) color depth, so that the unit tests
# don't start failing when environment variables change.
pt_print(tokens, style=style, file=f, color_depth=ColorDepth.DEFAULT)
assert b"\x1b[0;38;5;197mHello" in f.data
assert b"\x1b[0;38;5;83;3mworld" in f.data
示例9: get_editor_style_by_name
# 需要导入模块: from prompt_toolkit.styles import Style [as 别名]
# 或者: from prompt_toolkit.styles.Style import from_dict [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),
])
示例10: get_style
# 需要导入模块: from prompt_toolkit.styles import Style [as 别名]
# 或者: from prompt_toolkit.styles.Style import from_dict [as 别名]
def get_style(self):
Style.from_dict({
'completion-menu.completion': 'bg:#008888 #ffffff',
'completion-menu.completion.current': 'bg:#00aaaa #000000',
'scrollbar.background': 'bg:#88aaaa',
'scrollbar.button': 'bg:#222222',
'token.literal.string.single': '#98ff75'
})
# --------------------------------------------------------------- #
示例11: get_style
# 需要导入模块: from prompt_toolkit.styles import Style [as 别名]
# 或者: from prompt_toolkit.styles.Style import from_dict [as 别名]
def get_style(self):
return merge_styles([super().get_style(), Style.from_dict(constants.STYLE)])
# --------------------------------------------------------------- #
示例12: _print_log_msg
# 需要导入模块: from prompt_toolkit.styles import Style [as 别名]
# 或者: from prompt_toolkit.styles.Style import from_dict [as 别名]
def _print_log_msg(self, msg_type, msg=None, data=None):
try:
print_formatted_text(helpers.color_formatted_text(helpers.format_log_msg(msg_type=msg_type, description=msg,
data=data,
indent_size=self.INDENT_SIZE),
msg_type),
file=self._file_handle, style=Style.from_dict(STYLE))
except:
print_formatted_text(helpers.format_log_msg(msg_type=msg_type, description=msg,
data=data, indent_size=self.INDENT_SIZE),
file=self._file_handle, style=Style.from_dict(STYLE))
示例13: load_style
# 需要导入模块: from prompt_toolkit.styles import Style [as 别名]
# 或者: from prompt_toolkit.styles.Style import from_dict [as 别名]
def load_style():
"""
Return a dict mapping {ui_style_name -> style_dict}.
"""
if is_windows():
return Style.from_dict(win32_code_style)
else:
return Style.from_dict(default_ui_style)
示例14: __init__
# 需要导入模块: from prompt_toolkit.styles import Style [as 别名]
# 或者: from prompt_toolkit.styles.Style import from_dict [as 别名]
def __init__(self, parent=None, **kwargs):
super(Console, self).__init__()
# determine the relevant parent
self.parent = parent
if self.parent is not None and self.parent.level == self.level:
while parent is not None and parent.level == self.level:
parent = parent.parent # go up of one console level
# raise an exception in the context of command's .run() execution,
# to be propagated to console's .run() execution, setting the
# directly higher level console in argument
raise ConsoleDuplicate(self, parent)
# back-reference the console
self.config.console = self
# configure the console regarding its parenthood
if self.parent is None:
if Console.parent is not None:
raise Exception("Only one parent console can be used")
Console.parent = self
Console.parent._start_time = datetime.now()
Console.appdispname = Console.appname
Console.appname = Console.appname.lower()
self.__init(**kwargs)
else:
self.parent.child = self
# reset commands and other bound stuffs
self.reset()
# setup the session with the custom completer and validator
completer, validator = CommandCompleter(), CommandValidator()
completer.console = validator.console = self
message, style = self.prompt
hpath = Path(self.config.option("WORKSPACE").value).joinpath("history")
self._session = PromptSession(
message,
completer=completer,
history=FileHistory(hpath),
validator=validator,
style=Style.from_dict(style),
)
CustomLayout(self)
示例15: main
# 需要导入模块: from prompt_toolkit.styles import Style [as 别名]
# 或者: from prompt_toolkit.styles.Style import from_dict [as 别名]
def main():
# Example 1: fixed text.
text = prompt("Say something: ", bottom_toolbar="This is a toolbar")
print("You said: %s" % text)
# Example 2: fixed text from a callable:
def get_toolbar():
return "Bottom toolbar: time=%r" % time.time()
text = prompt("Say something: ", bottom_toolbar=get_toolbar, refresh_interval=0.5)
print("You said: %s" % text)
# Example 3: Using HTML:
text = prompt(
"Say something: ",
bottom_toolbar=HTML(
'(html) <b>This</b> <u>is</u> a <style bg="ansired">toolbar</style>'
),
)
print("You said: %s" % text)
# Example 4: Using ANSI:
text = prompt(
"Say something: ",
bottom_toolbar=ANSI(
"(ansi): \x1b[1mThis\x1b[0m \x1b[4mis\x1b[0m a \x1b[91mtoolbar"
),
)
print("You said: %s" % text)
# Example 5: styling differently.
style = Style.from_dict(
{
"bottom-toolbar": "#aaaa00 bg:#ff0000",
"bottom-toolbar.text": "#aaaa44 bg:#aa4444",
}
)
text = prompt("Say something: ", bottom_toolbar="This is a toolbar", style=style)
print("You said: %s" % text)
# Example 6: Using a list of tokens.
def get_bottom_toolbar():
return [
("", " "),
("bg:#ff0000 fg:#000000", "This"),
("", " is a "),
("bg:#ff0000 fg:#000000", "toolbar"),
("", ". "),
]
text = prompt("Say something: ", bottom_toolbar=get_bottom_toolbar)
print("You said: %s" % text)
# Example 7: multiline fixed text.
text = prompt("Say something: ", bottom_toolbar="This is\na multiline toolbar")
print("You said: %s" % text)