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


Python completion.WordCompleter方法代碼示例

本文整理匯總了Python中prompt_toolkit.completion.WordCompleter方法的典型用法代碼示例。如果您正苦於以下問題:Python completion.WordCompleter方法的具體用法?Python completion.WordCompleter怎麽用?Python completion.WordCompleter使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在prompt_toolkit.completion的用法示例。


在下文中一共展示了completion.WordCompleter方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: interact

# 需要導入模塊: from prompt_toolkit import completion [as 別名]
# 或者: from prompt_toolkit.completion import WordCompleter [as 別名]
def interact(connection):
    # When a client is connected, erase the screen from the client and say
    # Hello.
    connection.send("Welcome!\n")

    # Display prompt with bottom toolbar.
    animal_completer = WordCompleter(["alligator", "ant"])

    def get_toolbar():
        return "Bottom toolbar..."

    session = PromptSession()
    result = await session.prompt_async(
        "Say something: ", bottom_toolbar=get_toolbar, completer=animal_completer
    )

    connection.send("You said: {}\n".format(result))
    connection.send("Bye.\n") 
開發者ID:prompt-toolkit,項目名稱:python-prompt-toolkit,代碼行數:20,代碼來源:toolbar.py

示例2: choose_shard

# 需要導入模塊: from prompt_toolkit import completion [as 別名]
# 或者: from prompt_toolkit.completion import WordCompleter [as 別名]
def choose_shard(self,
                     shards) -> Optional[str]:

        if len(shards) == 0:
            raise HermitError("Not enough shards to reconstruct secret.")

        shardnames = [shard.name for shard in shards]
        shardnames.sort()

        shardCompleter = WordCompleter(shardnames, sentence=True)

        while True:
            prompt_string = "Choose shard\n(options: {} or <enter> to quit)\n> "
            prompt_msg = prompt_string.format(", ".join(shardnames))
            shard_name = prompt(prompt_msg,
                                completer=shardCompleter,
                                **self.options).strip()

            if shard_name in shardnames:
                return shard_name

            if shard_name == '':
                return None

            print("Shard not found.") 
開發者ID:unchained-capital,項目名稱:hermit,代碼行數:27,代碼來源:interface.py

示例3: get_completer

# 需要導入模塊: from prompt_toolkit import completion [as 別名]
# 或者: from prompt_toolkit.completion import WordCompleter [as 別名]
def get_completer(self):
        standard_completions = list({word for d in self._command_descs for word in d.command.split()})  # Use a set to ensure unicity of words
        standard_completions += ['quit', 'help', 'exit']

        if PromptData.Wallet:
            for addr in PromptData.Wallet.Addresses:
                if addr not in self._known_things:
                    self._known_things.append(addr)
            for alias in PromptData.Wallet.NamedAddr:
                if alias.Title not in self._known_things:
                    self._known_things.append(alias.Title)
            for tkn in PromptData.Wallet.GetTokens().values():
                if tkn.symbol not in self._known_things:
                    self._known_things.append(tkn.symbol)

        all_completions = standard_completions + self._known_things

        PromptInterface.prompt_completer = WordCompleter(all_completions)

        return PromptInterface.prompt_completer 
開發者ID:CityOfZion,項目名稱:neo-python,代碼行數:22,代碼來源:prompt.py

示例4: get_roll

# 需要導入模塊: from prompt_toolkit import completion [as 別名]
# 或者: from prompt_toolkit.completion import WordCompleter [as 別名]
def get_roll(player_name, roll_names):
    if os.environ.get('PYCHARM_HOSTED') == "1":
        print(Fore.LIGHTRED_EX + "Warning: Cannot use fancy prompt dialog in PyCharm.")
        print(Fore.LIGHTRED_EX + "Run this app outside of PyCharm to see it in action.")
        val = input(Fore.LIGHTYELLOW_EX + "What is your roll: ")
        print(Fore.WHITE)
        return val

    print(f"Available rolls: {', '.join(roll_names)}.")

    # word_comp = WordCompleter(roll_names)
    word_comp = PlayComplete()

    roll = prompt(f"{player_name}, what is your roll: ", completer=word_comp)

    if not roll or roll not in roll_names:
        print(f"Sorry {player_name}, {roll} not valid!")
        return None

    return roll


# def get_roll(player_name, roll_names):
#     print("Available rolls:")
#     for index, r in enumerate(roll_names, start=1):
#         print(f"{index}. {r}")
#
#     text = input(f"{player_name}, what is your roll? ")
#     selected_index = int(text) - 1
#
#     if selected_index < 0 or selected_index >= len(rolls):
#         print(f"Sorry {player_name}, {text} is out of bounds!")
#         return None
#
#     return roll_names[selected_index]
# 
開發者ID:talkpython,項目名稱:python-for-absolute-beginners-course,代碼行數:38,代碼來源:rpsgame.py

示例5: _do_shell

# 需要導入模塊: from prompt_toolkit import completion [as 別名]
# 或者: from prompt_toolkit.completion import WordCompleter [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

示例6: completer

# 需要導入模塊: from prompt_toolkit import completion [as 別名]
# 或者: from prompt_toolkit.completion import WordCompleter [as 別名]
def completer():
    s = set()

    history_strings = history().load_history_strings()

    for name in history_strings:
        s.add(name)

    return WordCompleter(list(s), ignore_case=True) 
開發者ID:bjarneo,項目名稱:Pytify,代碼行數:11,代碼來源:prompt.py

示例7: __init__

# 需要導入模塊: from prompt_toolkit import completion [as 別名]
# 或者: from prompt_toolkit.completion import WordCompleter [as 別名]
def __init__(self, request, logger, config):
        self.request = request
        self.config = config
        self.logger = logger
        self.cmds = {
            "exploit": self._exploit,
            "check": self._check,
            "list": self._list,
        }

        self.auto_cmds = WordCompleter(["quit", "list", "check", "exploit"], ignore_case=True)
        self.history = FileHistory('.drupwn-history')
        self._load() 
開發者ID:immunIT,項目名稱:drupwn,代碼行數:15,代碼來源:Exploiter.py

示例8: _add_completions

# 需要導入模塊: from prompt_toolkit import completion [as 別名]
# 或者: from prompt_toolkit.completion import WordCompleter [as 別名]
def _add_completions(self):
        return WordCompleter([str(i) for i in range(9)]) 
開發者ID:skelsec,項目名稱:msldap,代碼行數:4,代碼來源:example.py

示例9: _sleep_completions

# 需要導入模塊: from prompt_toolkit import completion [as 別名]
# 或者: from prompt_toolkit.completion import WordCompleter [as 別名]
def _sleep_completions(self):
        return WordCompleter([str(i) for i in range(1, 60)]) 
開發者ID:skelsec,項目名稱:msldap,代碼行數:4,代碼來源:example.py

示例10: _completer_for_command

# 需要導入模塊: from prompt_toolkit import completion [as 別名]
# 或者: from prompt_toolkit.completion import WordCompleter [as 別名]
def _completer_for_command(self, command):
        if not hasattr(self, "_%s_completions" % command):
            return WordCompleter([])
        return getattr(self, "_%s_completions" % command)() 
開發者ID:skelsec,項目名稱:msldap,代碼行數:6,代碼來源:aiocmd.py

示例11: run

# 需要導入模塊: from prompt_toolkit import completion [as 別名]
# 或者: from prompt_toolkit.completion import WordCompleter [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

示例12: run

# 需要導入模塊: from prompt_toolkit import completion [as 別名]
# 或者: from prompt_toolkit.completion import WordCompleter [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

示例13: run

# 需要導入模塊: from prompt_toolkit import completion [as 別名]
# 或者: from prompt_toolkit.completion import WordCompleter [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

示例14: yes_no_prompt

# 需要導入模塊: from prompt_toolkit import completion [as 別名]
# 或者: from prompt_toolkit.completion import WordCompleter [as 別名]
def yes_no_prompt(title, default=True):
    result = prompt(title, completer=WordCompleter(['yes', 'no']),
                    validator=SetValidator(['yes', 'no'],
                                           show_possible=True),
                    default="yes" if default else "no")
    return result == 'yes' 
開發者ID:openstack,項目名稱:releases,代碼行數:8,代碼來源:interactive_release.py

示例15: __init__

# 需要導入模塊: from prompt_toolkit import completion [as 別名]
# 或者: from prompt_toolkit.completion import WordCompleter [as 別名]
def __init__(self):
        # Completer for full command names.
        self._command_completer = WordCompleter(
            sorted(COMMANDS_TO_HANDLERS.keys()),
            ignore_case=True, WORD=True, match_middle=True)

        # Completer for aliases.
        self._aliases_completer = WordCompleter(
            sorted(ALIASES.keys()),
            ignore_case=True, WORD=True, match_middle=True) 
開發者ID:prompt-toolkit,項目名稱:pymux,代碼行數:12,代碼來源:completer.py


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