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


Python Style.from_dict方法代碼示例

本文整理匯總了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),
        }
    ) 
開發者ID:securisec,項目名稱:chepy,代碼行數:22,代碼來源:__main__.py

示例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")) 
開發者ID:prompt-toolkit,項目名稱:python-prompt-toolkit,代碼行數:24,代碼來源:print-formatted-text.py

示例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") 
開發者ID:prompt-toolkit,項目名稱:ptpython,代碼行數:33,代碼來源:ipython.py

示例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 
開發者ID:prompt-toolkit,項目名稱:ptpython,代碼行數:12,代碼來源:style.py

示例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),
    } 
開發者ID:prompt-toolkit,項目名稱:ptpython,代碼行數:10,代碼來源:style.py

示例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) 
開發者ID:securisec,項目名稱:chepy,代碼行數:5,代碼來源:cli.py

示例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) 
開發者ID:prompt-toolkit,項目名稱:python-prompt-toolkit,代碼行數:28,代碼來源:pygments-tokens.py

示例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 
開發者ID:prompt-toolkit,項目名稱:python-prompt-toolkit,代碼行數:12,代碼來源:test_print_formatted_text.py

示例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),
    ]) 
開發者ID:prompt-toolkit,項目名稱:pyvim,代碼行數:17,代碼來源:style.py

示例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'
        })

    # --------------------------------------------------------------- # 
開發者ID:nccgroup,項目名稱:fuzzowski,代碼行數:12,代碼來源:prompt.py

示例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)])

    # --------------------------------------------------------------- # 
開發者ID:nccgroup,項目名稱:fuzzowski,代碼行數:6,代碼來源:session_prompt.py

示例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)) 
開發者ID:nccgroup,項目名稱:fuzzowski,代碼行數:13,代碼來源:fuzz_logger_text.py

示例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) 
開發者ID:CoinAlpha,項目名稱:hummingbot,代碼行數:10,代碼來源:style.py

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

示例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) 
開發者ID:prompt-toolkit,項目名稱:python-prompt-toolkit,代碼行數:59,代碼來源:bottom-toolbar.py


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