当前位置: 首页>>代码示例>>Python>>正文


Python formatted_text.ANSI属性代码示例

本文整理汇总了Python中prompt_toolkit.formatted_text.ANSI属性的典型用法代码示例。如果您正苦于以下问题:Python formatted_text.ANSI属性的具体用法?Python formatted_text.ANSI怎么用?Python formatted_text.ANSI使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在prompt_toolkit.formatted_text的用法示例。


在下文中一共展示了formatted_text.ANSI属性的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: main

# 需要导入模块: from prompt_toolkit import formatted_text [as 别名]
# 或者: from prompt_toolkit.formatted_text import ANSI [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

示例2: main

# 需要导入模块: from prompt_toolkit import formatted_text [as 别名]
# 或者: from prompt_toolkit.formatted_text import ANSI [as 别名]
def main():
    # Option 1: pass a string to 'rprompt':
    answer = prompt("> ", rprompt=" <rprompt> ", style=example_style)
    print("You said: %s" % answer)

    # Option 2: pass HTML:
    answer = prompt("> ", rprompt=HTML(" <u>&lt;rprompt&gt;</u> "), style=example_style)
    print("You said: %s" % answer)

    # Option 3: pass ANSI:
    answer = prompt(
        "> ", rprompt=ANSI(" \x1b[4m<rprompt>\x1b[0m "), style=example_style
    )
    print("You said: %s" % answer)

    # Option 4: Pass a callable. (This callable can either return plain text,
    #           an HTML object, an ANSI object or a list of (style, text)
    #           tuples.
    answer = prompt("> ", rprompt=get_rprompt_text, style=example_style)
    print("You said: %s" % answer) 
开发者ID:prompt-toolkit,项目名称:python-prompt-toolkit,代码行数:22,代码来源:rprompt.py

示例3: run

# 需要导入模块: from prompt_toolkit import formatted_text [as 别名]
# 或者: from prompt_toolkit.formatted_text import ANSI [as 别名]
def run(self, key, value=None):
        if key == "options":
            if value is None:
                print_formatted_text(ANSI(str(self.config)))
            else:
                c = Config()
                c.prefix = "Module"
                c[self.config.option(value)] = self.config[value]
                print_formatted_text(ANSI(str(c)))
        elif key == "info":
            i = self.console.module.get_info(("fullpath|path", "description"),
                                             ("author", "email", "version"),
                                             ("comments",), ("options",),
                                             show_all=True)
            if len(i.strip()) != "":
                print_formatted_text(i)
        elif key == "issues":
            t = Entity.get_issues()
            if len(t) > 0:
                print_formatted_text(t) 
开发者ID:dhondta,项目名称:python-sploitkit,代码行数:22,代码来源:module.py

示例4: run

# 需要导入模块: from prompt_toolkit import formatted_text [as 别名]
# 或者: from prompt_toolkit.formatted_text import ANSI [as 别名]
def run(self):
        self.console.root.interfaces
        data = [["ESSID", "BSSID", "Channel", "Power", "Enc", "Cipher", "Auth",
                 "Password", "Stations"]]
        for essid, target in sorted(self.console.state['TARGETS'].items(),
                                    key=lambda x: x[0]):
            i = self.console.state['INTERFACES']
            c = any(x[1] == essid for x in i.values())
            rows = []
            for i, h in enumerate(data[0]):
                rows.append([""] * len(data[0]))
                v = target[h.lower()]
                if isinstance(v, (tuple, list)):
                    for j in range(len(v) - 1):
                        rows.append([""] * len(data[0]))
                else:
                    v = [v]
                for j, sv in enumerate(v):
                    if c:
                        sv = colored(sv, attrs=['bold'])
                    rows[j][i] = sv
            for r in rows:
                if all(v == "" for v in r):
                    continue
                data.append(r)
        if len(data) > 1:
            t = BorderlessTable(data, "Available Targets")
            print_formatted_text(ANSI(t.table))
        else:
            self.logger.warning("No target available yet") 
开发者ID:dhondta,项目名称:dronesploit,代码行数:32,代码来源:wifi.py

示例5: main

# 需要导入模块: from prompt_toolkit import formatted_text [as 别名]
# 或者: from prompt_toolkit.formatted_text import ANSI [as 别名]
def main():
    title("Special formatting")
    print(ANSI("    \x1b[1mBold"))
    print(ANSI("    \x1b[6mBlink"))
    print(ANSI("    \x1b[3mItalic"))
    print(ANSI("    \x1b[7mReverse"))
    print(ANSI("    \x1b[4mUnderline"))
    print(ANSI("    \x1b[8mHidden\x1b[0m (Hidden)"))

    # Ansi colors.
    title("ANSI colors")

    print(ANSI("    \x1b[91mANSI Red"))
    print(ANSI("    \x1b[94mANSI Blue"))

    # Other named colors.
    title("Named colors")

    print(ANSI("    \x1b[38;5;214morange"))
    print(ANSI("    \x1b[38;5;90mpurple"))

    # Background colors.
    title("Background colors")

    print(ANSI("    \x1b[97;101mANSI Red"))
    print(ANSI("    \x1b[97;104mANSI Blue"))

    print() 
开发者ID:prompt-toolkit,项目名称:python-prompt-toolkit,代码行数:30,代码来源:ansi.py

示例6: example_3

# 需要导入模块: from prompt_toolkit import formatted_text [as 别名]
# 或者: from prompt_toolkit.formatted_text import ANSI [as 别名]
def example_3():
    """
    Using ANSI for the formatting.
    """
    answer = prompt(
        ANSI(
            "\x1b[31mjohn\x1b[0m@"
            "\x1b[44mlocalhost\x1b[0m:"
            "\x1b[4m/user/john\x1b[0m"
            "# "
        )
    )
    print("You said: %s" % answer) 
开发者ID:prompt-toolkit,项目名称:python-prompt-toolkit,代码行数:15,代码来源:colored-prompt.py

示例7: getinput_autocompleted

# 需要导入模块: from prompt_toolkit import formatted_text [as 别名]
# 或者: from prompt_toolkit.formatted_text import ANSI [as 别名]
def getinput_autocompleted(name, commands, variables, liners):
	text = session.prompt( ANSI(name),
							completer=MyCompleter(commands, variables, liners),
							complete_while_typing=True,
							complete_in_thread=True,
							complete_style=CompleteStyle.READLINE_LIKE
						)
	return text 
开发者ID:D4Vinci,项目名称:One-Lin3r,代码行数:10,代码来源:utils.py

示例8: run

# 需要导入模块: from prompt_toolkit import formatted_text [as 别名]
# 或者: from prompt_toolkit.formatted_text import ANSI [as 别名]
def run(self, key, value=None):
        if key == "modules":
            h = Module.get_help(value)
            if h.strip() != "":
                print_formatted_text(h)
            else:
                self.logger.warning("No module loaded")
        elif key == "options":
            if value is None:
                print_formatted_text(ANSI(str(self.config)))
            else:
                c = Config()
                c[self.config.option(value)] = self.config[value]
                print_formatted_text(ANSI(str(c)))
        elif key == "projects":
            if value is None:
                data = [["Name"]]
                for p in projects(self):
                    data.append([p])
                print_formatted_text(BorderlessTable(data, "Existing projects"))
            else:
                print_formatted_text(value)
        elif key == "issues":
            t = Entity.get_issues()
            if len(t) > 0:
                print_formatted_text(t) 
开发者ID:dhondta,项目名称:python-sploitkit,代码行数:28,代码来源:general.py

示例9: main

# 需要导入模块: from prompt_toolkit import formatted_text [as 别名]
# 或者: from prompt_toolkit.formatted_text import ANSI [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

示例10: __init

# 需要导入模块: from prompt_toolkit import formatted_text [as 别名]
# 或者: from prompt_toolkit.formatted_text import ANSI [as 别名]
def __init(self, **kwargs):
        """ Initialize the parent console with commands and modules. """
        Console._dev_mode = kwargs.pop("dev", False)
        # setup banners
        bsrc = self._sources("banners")
        if bsrc is not None:
            print_formatted_text("")
            # display a random banner from the banners folder
            get_banner_func = kwargs.get('get_banner_func', get_banner)
            banner_colors = kwargs.get('banner_section_styles', {})
            text = get_banner_func(self.appdispname, bsrc, styles=banner_colors)
            if text:
                print_formatted_text(ANSI(text))
            # display a random quote from quotes.csv (in the banners folder)
            get_quote_func = kwargs.get('get_quote_func', get_quote)
            try:
                text = get_quote_func(os.path.join(bsrc, "quotes.csv"))
                if text:
                    print_formatted_text(ANSI(text))
            except ValueError:
                pass
        # setup libraries
        lsrc = self._sources("libraries")
        if lsrc is not None:
            if isinstance(lsrc, str):
                lsrc = [lsrc]
            if isinstance(lsrc, (list, tuple, set)):
                for lib in map(lambda p: os.path.abspath(p), lsrc[::-1]):
                    sys.path.insert(0, lib)
        # setup entities
        load_entities(
            [BaseModel, Command, Console, Model, Module, StoreExtension],
            *self._sources("entities"),
            include_base=kwargs.get("include_base", True),
            select=kwargs.get("select", {'command': Command._functionalities}),
            exclude=kwargs.get("exclude", {}),
            backref=kwargs.get("backref", BACK_REFERENCES),
            docstr_parser=kwargs.get("docstr_parser", parse_docstring),
        )
        Console._storage.models = Model.subclasses + BaseModel.subclasses
        # display module stats
        print_formatted_text(FormattedText([("#00ff00", Module.get_summary())]))
        # setup the prompt message
        self.message.insert(0, ('class:appname', self.appname))
        # display warnings
        self.reset()
        if Entity.has_issues():
            self.logger.warning("There are some issues ; use 'show issues' to "
                                "see more details")
        # console's components back-referencing
        for attr in ["_files", "_jobs"]:
            setattr(getattr(Console, attr), "console", self) 
开发者ID:dhondta,项目名称:python-sploitkit,代码行数:54,代码来源:console.py


注:本文中的prompt_toolkit.formatted_text.ANSI属性示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。