當前位置: 首頁>>代碼示例>>Python>>正文


Python styles.Style方法代碼示例

本文整理匯總了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 
開發者ID:dbcli,項目名稱:pgcli,代碼行數:24,代碼來源:pgstyle.py

示例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 
開發者ID:dbcli,項目名稱:athenacli,代碼行數:25,代碼來源:clistyle.py

示例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 
開發者ID:dbcli,項目名稱:mssql-cli,代碼行數:25,代碼來源:mssqlstyle.py

示例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) 
開發者ID:bkerler,項目名稱:android_universal,代碼行數:20,代碼來源:renderer.py

示例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] 
開發者ID:dbcli,項目名稱:pgcli,代碼行數:16,代碼來源:pgstyle.py

示例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)]
    ) 
開發者ID:dbcli,項目名稱:pgcli,代碼行數:30,代碼來源:pgstyle.py

示例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
    ) 
開發者ID:tmbo,項目名稱:questionary,代碼行數:43,代碼來源:password.py

示例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
    ) 
開發者ID:tmbo,項目名稱:questionary,代碼行數:36,代碼來源:rawselect.py

示例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 
開發者ID:RasaHQ,項目名稱:rasa_core,代碼行數:11,代碼來源:console.py

示例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] 
開發者ID:dbcli,項目名稱:litecli,代碼行數:16,代碼來源:clistyle.py

示例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] 
開發者ID:dbcli,項目名稱:athenacli,代碼行數:14,代碼來源:clistyle.py

示例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)
    ]) 
開發者ID:dbcli,項目名稱:athenacli,代碼行數:33,代碼來源:clistyle.py

示例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) 
開發者ID:botfront,項目名稱:rasa-for-botfront,代碼行數:41,代碼來源:console.py

示例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 
開發者ID:botfront,項目名稱:rasa-for-botfront,代碼行數:15,代碼來源:console.py

示例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] 
開發者ID:dbcli,項目名稱:mssql-cli,代碼行數:14,代碼來源:mssqlstyle.py


注:本文中的prompt_toolkit.styles.Style方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。