本文整理汇总了Python中prompt_toolkit.styles.Style方法的典型用法代码示例。如果您正苦于以下问题:Python styles.Style方法的具体用法?Python styles.Style怎么用?Python styles.Style使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类prompt_toolkit.styles
的用法示例。
在下文中一共展示了styles.Style方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: style_factory_output
# 需要导入模块: from prompt_toolkit import styles [as 别名]
# 或者: from prompt_toolkit.styles import Style [as 别名]
def style_factory_output(name, cli_style):
try:
style = pygments.styles.get_style_by_name(name).styles
except ClassNotFound:
style = pygments.styles.get_style_by_name("native").styles
for token in cli_style:
if token.startswith("Token."):
token_type, style_value = parse_pygments_style(token, style, cli_style)
style.update({token_type: style_value})
elif token in PROMPT_STYLE_TO_TOKEN:
token_type = PROMPT_STYLE_TO_TOKEN[token]
style.update({token_type: cli_style[token]})
else:
# TODO: cli helpers will have to switch to ptk.Style
logger.error("Unhandled style / class name: %s", token)
class OutputStyle(PygmentsStyle):
default_style = ""
styles = style
return OutputStyle
示例2: style_factory_output
# 需要导入模块: from prompt_toolkit import styles [as 别名]
# 或者: from prompt_toolkit.styles import Style [as 别名]
def style_factory_output(name, cli_style):
try:
style = pygments.styles.get_style_by_name(name).styles
except ClassNotFound:
style = pygments.styles.get_style_by_name('native').styles
for token in cli_style:
if token.startswith('Token.'):
token_type, style_value = parse_pygments_style(
token, style, cli_style)
style.update({token_type: style_value})
elif token in PROMPT_STYLE_TO_TOKEN:
token_type = PROMPT_STYLE_TO_TOKEN[token]
style.update({token_type: cli_style[token]})
else:
# TODO: cli helpers will have to switch to ptk.Style
logger.error('Unhandled style / class name: %s', token)
class OutputStyle(PygmentsStyle):
default_style = ""
styles = style
return OutputStyle
示例3: style_factory_output
# 需要导入模块: from prompt_toolkit import styles [as 别名]
# 或者: from prompt_toolkit.styles import Style [as 别名]
def style_factory_output(name, cli_style):
try:
style = pygments.styles.get_style_by_name(name).styles
except ClassNotFound:
style = pygments.styles.get_style_by_name('native').styles
for token in cli_style:
if token.startswith('Token.'):
token_type, style_value = parse_pygments_style(
token, style, cli_style)
style.update({token_type: style_value})
elif token in PROMPT_STYLE_TO_TOKEN:
token_type = PROMPT_STYLE_TO_TOKEN[token]
style.update({token_type: cli_style[token]})
else:
# TODO: cli helpers will have to switch to ptk.Style
logger.error('Unhandled style / class name: %s', token)
class OutputStyle(PygmentsStyle): # pylint: disable=too-few-public-methods
default_style = ""
styles = style
return OutputStyle
示例4: __init__
# 需要导入模块: from prompt_toolkit import styles [as 别名]
# 或者: from prompt_toolkit.styles import Style [as 别名]
def __init__(self, style, output, use_alternate_screen=False, mouse_support=False):
assert isinstance(style, Style)
assert isinstance(output, Output)
self.style = style
self.output = output
self.use_alternate_screen = use_alternate_screen
self.mouse_support = to_cli_filter(mouse_support)
self._in_alternate_screen = False
self._mouse_support_enabled = False
self._bracketed_paste_enabled = False
# Waiting for CPR flag. True when we send the request, but didn't got a
# response.
self.waiting_for_cpr = False
self.reset(_scroll=True)
示例5: parse_pygments_style
# 需要导入模块: from prompt_toolkit import styles [as 别名]
# 或者: from prompt_toolkit.styles import Style [as 别名]
def parse_pygments_style(token_name, style_object, style_dict):
"""Parse token type and style string.
:param token_name: str name of Pygments token. Example: "Token.String"
:param style_object: pygments.style.Style instance to use as base
:param style_dict: dict of token names and their styles, customized to this cli
"""
token_type = string_to_tokentype(token_name)
try:
other_token_type = string_to_tokentype(style_dict[token_name])
return token_type, style_object.styles[other_token_type]
except AttributeError:
return token_type, style_dict[token_name]
示例6: style_factory
# 需要导入模块: from prompt_toolkit import styles [as 别名]
# 或者: from prompt_toolkit.styles import Style [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)]
)
示例7: password
# 需要导入模块: from prompt_toolkit import styles [as 别名]
# 或者: from prompt_toolkit.styles import Style [as 别名]
def password(
message: Text,
default: Text = "",
validate: Any = None,
qmark: Text = DEFAULT_QUESTION_PREFIX,
style: Optional[Style] = None,
**kwargs: Any
) -> Question:
"""Question the user to enter a secret text not displayed in the prompt.
This question type can be used to prompt the user for information
that should not be shown in the command line. The typed text will be
replaced with `*`.
Args:
message: Question text
default: Default value will be returned if the user just hits
enter.
validate: Require the entered value to pass a validation. The
value can not be submited until the validator accepts
it (e.g. to check minimum password length).
This can either be a function accepting the input and
returning a boolean, or an class reference to a
subclass of the prompt toolkit Validator class.
qmark: Question prefix displayed in front of the question.
By default this is a `?`
style: A custom color and style for the question parts. You can
configure colors as well as font types for different elements.
Returns:
Question: Question instance, ready to be prompted (using `.ask()`).
"""
return text.text(
message, default, validate, qmark, style, is_password=True, **kwargs
)
示例8: rawselect
# 需要导入模块: from prompt_toolkit import styles [as 别名]
# 或者: from prompt_toolkit.styles import Style [as 别名]
def rawselect(
message: Text,
choices: List[Union[Text, Choice, Dict[Text, Any]]],
default: Optional[Text] = None,
qmark: Text = DEFAULT_QUESTION_PREFIX,
style: Optional[Style] = None,
**kwargs: Any
) -> Question:
"""Ask the user to select one item from a list of choices using shortcuts.
The user can only select one option.
Args:
message: Question text
choices: Items shown in the selection, this can contain `Choice` or
or `Separator` objects or simple items as strings. Passing
`Choice` objects, allows you to configure the item more
(e.g. preselecting it or disabeling it).
default: Default return value (single value).
qmark: Question prefix displayed in front of the question.
By default this is a `?`
style: A custom color and style for the question parts. You can
configure colors as well as font types for different elements.
Returns:
Question: Question instance, ready to be prompted (using `.ask()`).
"""
return select.select(
message, choices, default, qmark, style, use_shortcuts=True, **kwargs
)
示例9: get_cmd_input
# 需要导入模块: from prompt_toolkit import styles [as 别名]
# 或者: from prompt_toolkit.styles import Style [as 别名]
def get_cmd_input():
response = questionary.text("",
qmark="Your input ->",
style=Style([('qmark', '#b373d6'),
('', '#b373d6')])).ask()
if response is not None:
return response.strip()
else:
return None
示例10: parse_pygments_style
# 需要导入模块: from prompt_toolkit import styles [as 别名]
# 或者: from prompt_toolkit.styles import Style [as 别名]
def parse_pygments_style(token_name, style_object, style_dict):
"""Parse token type and style string.
:param token_name: str name of Pygments token. Example: "Token.String"
:param style_object: pygments.style.Style instance to use as base
:param style_dict: dict of token names and their styles, customized to this cli
"""
token_type = string_to_tokentype(token_name)
try:
other_token_type = string_to_tokentype(style_dict[token_name])
return token_type, style_object.styles[other_token_type]
except AttributeError as err:
return token_type, style_dict[token_name]
示例11: parse_pygments_style
# 需要导入模块: from prompt_toolkit import styles [as 别名]
# 或者: from prompt_toolkit.styles import Style [as 别名]
def parse_pygments_style(token_name, style_object, style_dict):
"""Parse token type and style string.
:param token_name: str name of Pygments token. Example: "Token.String"
:param style_object: pygments.style.Style instance to use as base
:param style_dict: dict of token names and their styles, customized to this cli
"""
token_type = string_to_tokentype(token_name)
try:
other_token_type = string_to_tokentype(style_dict[token_name])
return token_type, style_object.styles[other_token_type]
except AttributeError as err:
return token_type, style_dict[token_name]
示例12: style_factory
# 需要导入模块: from prompt_toolkit import styles [as 别名]
# 或者: from prompt_toolkit.styles import Style [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)
])
示例13: print_bot_output
# 需要导入模块: from prompt_toolkit import styles [as 别名]
# 或者: from prompt_toolkit.styles import Style [as 别名]
def print_bot_output(
message: Dict[Text, Any], color=cli_utils.bcolors.OKBLUE
) -> Optional[questionary.Question]:
if ("text" in message) and not ("buttons" in message):
cli_utils.print_color(message.get("text"), color=color)
if "image" in message:
cli_utils.print_color("Image: " + message.get("image"), color=color)
if "attachment" in message:
cli_utils.print_color("Attachment: " + message.get("attachment"), color=color)
if "buttons" in message:
choices = cli_utils.button_choices_from_message_data(
message, allow_free_text_input=True
)
question = questionary.select(
message.get("text"),
choices,
style=Style([("qmark", "#6d91d3"), ("", "#6d91d3"), ("answer", "#b373d6")]),
)
return question
if "elements" in message:
cli_utils.print_color("Elements:", color=color)
for idx, element in enumerate(message.get("elements")):
cli_utils.print_color(
cli_utils.element_to_string(element, idx), color=color
)
if "quick_replies" in message:
cli_utils.print_color("Quick Replies:", color=color)
for idx, element in enumerate(message.get("quick_replies")):
cli_utils.print_color(cli_utils.button_to_string(element, idx), color=color)
if "custom" in message:
cli_utils.print_color("Custom json:", color=color)
cli_utils.print_color(json.dumps(message.get("custom"), indent=2), color=color)
示例14: get_user_input
# 需要导入模块: from prompt_toolkit import styles [as 别名]
# 或者: from prompt_toolkit.styles import Style [as 别名]
def get_user_input(button_question: questionary.Question) -> Optional[Text]:
if button_question is not None:
response = cli_utils.payload_from_button_question(button_question)
if response == cli_utils.FREE_TEXT_INPUT_PROMPT:
# Re-prompt user with a free text input
response = get_user_input(None)
else:
response = questionary.text(
"",
qmark="Your input ->",
style=Style([("qmark", "#b373d6"), ("", "#b373d6")]),
).ask()
return response.strip() if response is not None else None
示例15: parse_pygments_style
# 需要导入模块: from prompt_toolkit import styles [as 别名]
# 或者: from prompt_toolkit.styles import Style [as 别名]
def parse_pygments_style(token_name, style_object, style_dict):
"""Parse token type and style string.
:param token_name: str name of Pygments token. Example: "Token.String"
:param style_object: pygments.style.Style instance to use as base
:param style_dict: dict of token names and their styles, customized to this cli
"""
token_type = string_to_tokentype(token_name)
try:
other_token_type = string_to_tokentype(style_dict[token_name])
return token_type, style_object.styles[other_token_type]
except AttributeError:
return token_type, style_dict[token_name]