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


Python prompt_toolkit.PromptSession方法代码示例

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


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

示例1: main

# 需要导入模块: import prompt_toolkit [as 别名]
# 或者: from prompt_toolkit import PromptSession [as 别名]
def main():
    settings = Settings()
    bindings = get_bindings(settings)
    executor = Executor(settings)
    toolbar = Toolbar(settings)
    completer = KafkaCompleter(settings) if settings.enable_auto_complete else None
    suggester = AutoSuggestFromHistory() if settings.enable_auto_suggest else None
    history = ThreadedHistory(FileHistory(get_user_history_path())) if settings.enable_history else InMemoryHistory()
    session = PromptSession(completer=completer, style=style, bottom_toolbar=toolbar.handler,
                            key_bindings=bindings, history=history, include_default_pygments_style=False)
    while True:
        try:
            command = session.prompt([("class:operator", "> ")], auto_suggest=suggester)
        except KeyboardInterrupt:
            continue
        except EOFError:
            break
        else:
            executor.execute(command)

    settings.save_settings() 
开发者ID:devshawn,项目名称:kafka-shell,代码行数:23,代码来源:main.py

示例2: _fix_unecessary_blank_lines

# 需要导入模块: import prompt_toolkit [as 别名]
# 或者: from prompt_toolkit import PromptSession [as 别名]
def _fix_unecessary_blank_lines(ps: PromptSession) -> None:
    """This is a fix for additional empty lines added by prompt toolkit.

    This assumes the layout of the default session doesn't change, if it
    does, this needs an update."""

    default_container = ps.layout.container

    default_buffer_window = (
        default_container.get_children()[0].content.get_children()[1].content
    )

    assert isinstance(default_buffer_window, Window)
    # this forces the main window to stay as small as possible, avoiding
    # empty lines in selections
    default_buffer_window.dont_extend_height = Always() 
开发者ID:tmbo,项目名称:questionary,代码行数:18,代码来源:common.py

示例3: create_inquirer_layout

# 需要导入模块: import prompt_toolkit [as 别名]
# 或者: from prompt_toolkit import PromptSession [as 别名]
def create_inquirer_layout(
    ic: InquirerControl,
    get_prompt_tokens: Callable[[], List[Tuple[Text, Text]]],
    **kwargs
) -> Layout:
    """Create a layout combining question and inquirer selection."""

    ps = PromptSession(get_prompt_tokens, reserve_space_for_menu=0, **kwargs)

    _fix_unecessary_blank_lines(ps)

    return Layout(
        HSplit(
            [ps.layout.container, ConditionalContainer(Window(ic), filter=~IsDone())]
        )
    ) 
开发者ID:tmbo,项目名称:questionary,代码行数:18,代码来源:common.py

示例4: prompt

# 需要导入模块: import prompt_toolkit [as 别名]
# 或者: from prompt_toolkit import PromptSession [as 别名]
def prompt(self, msg):
        """Get input using prompt_toolkit."""
        try:
            # prompt_toolkit v2
            prompt = prompt_toolkit.PromptSession(history=self.history).prompt
        except AttributeError:
            # prompt_toolkit v1
            prompt = partial(prompt_toolkit.prompt, history=self.history)
        return prompt(
            msg,
            multiline=self.multiline,
            vi_mode=self.vi_mode,
            wrap_lines=self.wrap_lines,
            enable_history_search=self.history_search,
            lexer=PygmentsLexer(CoconutLexer),
            style=style_from_pygments_cls(
                pygments.styles.get_style_by_name(self.style),
            ),
        ) 
开发者ID:evhub,项目名称:coconut,代码行数:21,代码来源:util.py

示例5: main

# 需要导入模块: import prompt_toolkit [as 别名]
# 或者: from prompt_toolkit import PromptSession [as 别名]
def main(database):
    connection = sqlite3.connect(database)
    session = PromptSession(
        lexer=PygmentsLexer(SqlLexer), completer=sql_completer, style=style
    )

    while True:
        try:
            text = session.prompt("> ")
        except KeyboardInterrupt:
            continue  # Control-C pressed. Try again.
        except EOFError:
            break  # Control-D pressed.

        with connection:
            try:
                messages = connection.execute(text)
            except Exception as e:
                print(repr(e))
            else:
                for message in messages:
                    print(message)

    print("GoodBye!") 
开发者ID:prompt-toolkit,项目名称:python-prompt-toolkit,代码行数:26,代码来源:sqlite-cli.py

示例6: main

# 需要导入模块: import prompt_toolkit [as 别名]
# 或者: from prompt_toolkit import PromptSession [as 别名]
def main():
    print(
        "Asynchronous loading of history. Notice that the up-arrow will work "
        "for as far as the completions are loaded.\n"
        "Even when the input is accepted, loading will continue in the "
        "background and when the next prompt is displayed.\n"
    )
    our_history = ThreadedHistory(SlowHistory())

    # The history needs to be passed to the `PromptSession`. It can't be passed
    # to the `prompt` call because only one history can be used during a
    # session.
    session = PromptSession(history=our_history)

    while True:
        text = session.prompt("Say something: ")
        print("You said: %s" % text) 
开发者ID:prompt-toolkit,项目名称:python-prompt-toolkit,代码行数:19,代码来源:slow-history.py

示例7: cli_ads_search

# 需要导入模块: import prompt_toolkit [as 别名]
# 或者: from prompt_toolkit import PromptSession [as 别名]
def cli_ads_search(args):
    """Command-line interface for ads-search call."""
    if args.next:
        query = None
    else:
        completer = u.KeyWordCompleter(u.ads_keywords, bm.load())
        session = prompt_toolkit.PromptSession(
            history=FileHistory(u.BM_HISTORY_ADS()))
        query = session.prompt(
            "(Press 'tab' for autocomplete)\n",
            auto_suggest=u.AutoSuggestCompleter(),
            completer=completer,
            complete_while_typing=False,
            ).strip()
        if query == "" and os.path.exists(u.BM_CACHE()):
            query = None
        elif query == "":
            return
    try:
        am.manager(query)
    except ValueError as e:
        print(f"\nError: {str(e)}") 
开发者ID:pcubillos,项目名称:bibmanager,代码行数:24,代码来源:__main__.py

示例8: __init__

# 需要导入模块: import prompt_toolkit [as 别名]
# 或者: from prompt_toolkit import PromptSession [as 别名]
def __init__(self, db_path):
        self.db_path = db_path

        self.completer = WMCompleter(self)
        self.signatures = Signatures()
        self.prompt_session = PromptSession(
            HTML("WMDB ≫ "),
            #bottom_toolbar=functools.partial(bottom_toolbar, ts=self.teamservers),
            completer=self.completer,
            complete_in_thread=True,
            complete_while_typing=True,
            auto_suggest=AutoSuggestFromHistory(),
            #rprompt=get_rprompt(False),
            #style=example_style,
            search_ignore_case=True
        ) 
开发者ID:byt3bl33d3r,项目名称:WitnessMe,代码行数:18,代码来源:wmdb.py

示例9: _do_shell

# 需要导入模块: import prompt_toolkit [as 别名]
# 或者: from prompt_toolkit import PromptSession [as 别名]
def _do_shell(_args):
    commands = ['compile', 'convert', 'help', 'exit']
    completer = WordCompleter(commands, WORD=True)
    user_home = os.path.expanduser('~')
    history = FileHistory(os.path.join(user_home, '.asn1tools-history.txt'))
    session = PromptSession(completer=completer,
                            complete_while_typing=True,
                            auto_suggest=AutoSuggestFromHistory(),
                            enable_history_search=True,
                            history=history)
    input_spec = None
    output_spec = None
    output_codec = None

    print("\nWelcome to the asn1tools shell!\n")

    while True:
        try:
            line = session.prompt(u'$ ')
        except EOFError:
            return

        line = line.strip()

        if line:
            if line.startswith('compile'):
                input_spec, output_spec, output_codec = _handle_command_compile(line)
            elif line.startswith('convert'):
                _handle_command_convert(line,
                                        input_spec,
                                        output_spec,
                                        output_codec)
            elif line == 'help':
                _handle_command_help()
            elif line == 'exit':
                return
            else:
                print('{}: command not found'.format(line)) 
开发者ID:eerimoq,项目名称:asn1tools,代码行数:40,代码来源:__init__.py

示例10: custom_prompt

# 需要导入模块: import prompt_toolkit [as 别名]
# 或者: from prompt_toolkit import PromptSession [as 别名]
def custom_prompt(currentSong): 
    
    session = PromptSession(
        message=get_prompt,
        history=history(),
        auto_suggest=AutoSuggestFromHistory(),
        enable_history_search=True,
        bottom_toolbar=get_bottom_toolbar(currentSong),
        completer=completer(),
        complete_while_typing=True,
        complete_in_thread=True,
        style=style
    )

    return session.prompt() 
开发者ID:bjarneo,项目名称:Pytify,代码行数:17,代码来源:prompt.py

示例11: shell

# 需要导入模块: import prompt_toolkit [as 别名]
# 或者: from prompt_toolkit import PromptSession [as 别名]
def shell(self, items, pargs):
        self.pargs = pargs
        self.items = items
        stdout.write(
            '\n')  # When the fetching messege ends need to add \n after \r.
        self.prompt_show_items()
        history = InMemoryHistory()

        session = PromptSession() if PROMPT_TOOLKIT_V2 else None
        while True:
            kwargs = dict(
                history=history,
                auto_suggest=AutoSuggestFromHistory(),
                completer=WGCompleter(list(self.items.keys())),
                style=we_get_prompt_style
            )
            try:
                p = prompt(u'we-get > ', **kwargs)
            except TypeError as e:
                log.debug('{}:{}'.format(type(e), e))
                kwargs.pop('history')
                if PROMPT_TOOLKIT_V2:
                    p = session.prompt(u'we-get > ', **kwargs)
                else:
                    p = prompt(u'we-get > ', **kwargs)

            if self.prompt_no_command(p):
                continue
            elif self.prompt_is_single_command(p):
                command = p
                args = None
            else:
                _ = p.split()
                command = _[0]
                _.pop(0)
                args = ' '.join(_)
            if not self.prompt_verify_command(command, args):
                continue
            elif not self.prompt_parse_command(command, args):
                break 
开发者ID:rachmadaniHaryono,项目名称:we-get,代码行数:42,代码来源:shell.py

示例12: run

# 需要导入模块: import prompt_toolkit [as 别名]
# 或者: from prompt_toolkit import PromptSession [as 别名]
def run(self):
        if self._ignore_sigint and sys.platform != "win32":
            asyncio.get_event_loop().add_signal_handler(signal.SIGINT, self._sigint_handler)
        self.session = PromptSession(enable_history_search=True, key_bindings=self._get_bindings())
        try:
            with patch_stdout():
                await self._run_prompt_forever()
        finally:
            if self._ignore_sigint and sys.platform != "win32":
                asyncio.get_event_loop().remove_signal_handler(signal.SIGINT)
            self._on_close() 
开发者ID:skelsec,项目名称:msldap,代码行数:13,代码来源:aiocmd.py

示例13: run

# 需要导入模块: import prompt_toolkit [as 别名]
# 或者: from prompt_toolkit import PromptSession [as 别名]
def run(self):
        """Runs the interface and waits for user input commands."""
        completer = WordCompleter(['show', 'name', 'field', 'fields',
                                   'dump', 'recalculate', 'clear', 'back'])
        history = FileHistory(self._polym_path + '/.linterface_history')
        session = PromptSession(history=history)
        while True:
            try:
                command = session.prompt(HTML("<bold>PH:cap/t%d/<red>%s</red> > </bold>" %
                                              (self._tindex, self._l.name)),
                                         completer=completer,
                                         complete_style=CompleteStyle.READLINE_LIKE,
                                         auto_suggest=AutoSuggestFromHistory(),
                                         enable_history_search=True)
            except KeyboardInterrupt:
                self.exit_program()
                continue
            # Argument parsing
            command = command.split(" ")
            if command[0] in self.EXIT:
                self.exit_program()
            elif command[0] in self.RET:
                break
            elif command[0] in ["s", "show"]:
                self._show(command)
            elif command[0] == "name":
                self._name(command)
            elif command[0] in ["field", "f"]:
                self._field(command)
            elif command[0] in ["fields", "fs"]:
                self._fields(command)
            elif command[0] in ["dump", "d"]:
                self._dump(command)
            elif command[0] in ["recalculate", "r"]:
                self._recalculate(command)
            elif command[0] == "clear":
                Interface._clear()
            elif command[0] == "":
                continue
            else:
                Interface._wrong_command() 
开发者ID:shramos,项目名称:polymorph,代码行数:43,代码来源:layerinterface.py

示例14: run

# 需要导入模块: import prompt_toolkit [as 别名]
# 或者: from prompt_toolkit import PromptSession [as 别名]
def run(self):
        """Runs the interface and waits for user input commands."""
        completer = WordCompleter(['show', 'dissect', 'template', 'wireshark',
                                   'clear', 'back'])
        history = FileHistory(self._polym_path + '/.tlinterface_history')
        session = PromptSession(history=history)
        while True:
            try:
                command = session.prompt(HTML("<bold>PH:<red>cap</red> > </bold>"),
                                         completer=completer,
                                         complete_style=CompleteStyle.READLINE_LIKE,
                                         auto_suggest=AutoSuggestFromHistory(),
                                         enable_history_search=True)
            except KeyboardInterrupt:
                self.exit_program()
                continue
            command = command.split(" ")
            if command[0] in self.EXIT:
                self.exit_program()
            elif command[0] in self.RET:
                break
            elif command[0] in ["show", "s"]:
                self._show(command)
            elif command[0] == "dissect":
                self._dissect(command)
            elif command[0] in ["template", "t"]:
                self._template(command)
            elif command[0] in ["wireshark", "w"]:
                self._wireshark(command)
            elif command[0] == "clear":
                Interface._clear()
            elif command[0] == "":
                continue
            else:
                Interface._wrong_command() 
开发者ID:shramos,项目名称:polymorph,代码行数:37,代码来源:tlistinterface.py

示例15: run

# 需要导入模块: import prompt_toolkit [as 别名]
# 或者: from prompt_toolkit import PromptSession [as 别名]
def run(self):
        """Runs the interface and waits for user input commands."""
        completer = WordCompleter(['capture', 'spoof', 'clear', 'import'])
        history = FileHistory(self._polym_path + '/.minterface_history')
        session = PromptSession(history=history)
        while True:
            try:
                command = session.prompt(HTML("<bold><red>PH</red> > </bold>"),
                                         completer=completer,
                                         complete_style=CompleteStyle.READLINE_LIKE,
                                         auto_suggest=AutoSuggestFromHistory(),
                                         enable_history_search=True)
            except KeyboardInterrupt:
                self.exit_program()
                continue
            command = command.split(" ")
            if command[0] in self.EXIT:
                self.exit_program()
            elif command[0] in ["capture", "c"]:
                self._capture(command)
            elif command[0] in ["spoof", "s"]:
                self._spoof(command)
            elif command[0] in ["import", "i"]:
                self._import(command)
            elif command[0] == "clear":
                Interface._clear()
            elif command[0] == "":
                continue
            else:
                Interface._wrong_command() 
开发者ID:shramos,项目名称:polymorph,代码行数:32,代码来源:maininterface.py


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