Python prompt_toolkit.shortcuts.prompt() Examples

The following are 15 code examples of prompt_toolkit.shortcuts.prompt(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module prompt_toolkit.shortcuts , or try the search function .
Example #1
Source File: __init__.py    From click-repl with MIT License 7 votes vote down vote up
def bootstrap_prompt(prompt_kwargs, group):
    """
    Bootstrap prompt_toolkit kwargs or use user defined values.

    :param prompt_kwargs: The user specified prompt kwargs.
    """
    prompt_kwargs = prompt_kwargs or {}

    defaults = {
        "history": InMemoryHistory(),
        "completer": ClickCompleter(group),
        "message": u"> ",
    }

    for key in defaults:
        default_value = defaults[key]
        if key not in prompt_kwargs:
            prompt_kwargs[key] = default_value

    return prompt_kwargs 
Example #2
Source File: utils.py    From contrail-api-cli with MIT License 6 votes vote down vote up
def continue_prompt(message=""):
    """Prompt the user to continue or not

    Returns True when the user type Yes.

    :param message: message to display
    :type message: str

    :rtype: bool
    """
    answer = False
    message = message + "\n'Yes' or 'No' to continue: "
    while answer not in ('Yes', 'No'):
        answer = prompt(message, eventloop=eventloop())
        if answer == "Yes":
            answer = True
            break
        if answer == "No":
            answer = False
            break
    return answer 
Example #3
Source File: slow-completions.py    From python-prompt-toolkit with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def main():
    # We wrap it in a ThreadedCompleter, to make sure it runs in a different
    # thread. That way, we don't block the UI while running the completions.
    slow_completer = SlowCompleter()

    # Add a bottom toolbar that display when completions are loading.
    def bottom_toolbar():
        return " Loading completions... " if slow_completer.loading > 0 else ""

    # Display prompt.
    text = prompt(
        "Give some animals: ",
        completer=slow_completer,
        complete_in_thread=True,
        complete_while_typing=True,
        bottom_toolbar=bottom_toolbar,
        complete_style=CompleteStyle.MULTI_COLUMN,
    )
    print("You said: %s" % text) 
Example #4
Source File: Prompt.py    From topydo with GNU General Public License v3.0 5 votes vote down vote up
def run(self):
        """ Main entry function. """
        history = InMemoryHistory()
        self._load_file()

        while True:
            # (re)load the todo.txt file (only if it has been modified)

            try:
                user_input = prompt(u'topydo> ', history=history,
                                    completer=self.completer,
                                    complete_while_typing=False)
                user_input = shlex.split(user_input)
            except EOFError:
                sys.exit(0)
            except KeyboardInterrupt:
                continue
            except ValueError as verr:
                error('Error: ' + str(verr))
                continue

            try:
                (subcommand, args) = get_subcommand(user_input)
            except ConfigError as ce:
                error('Error: ' + str(ce) + '. Check your aliases configuration')
                continue

            try:
                if self._execute(subcommand, args) != False:
                    self._post_execute()
            except TypeError:
                print(GENERIC_HELP) 
Example #5
Source File: Prompt.py    From topydo with GNU General Public License v3.0 5 votes vote down vote up
def main():
    """ Main entry point of the prompt interface. """
    PromptApplication().run() 
Example #6
Source File: Exploiter.py    From drupwn with GNU General Public License v3.0 5 votes vote down vote up
def run(self):
        buf = ""

        self.logger.handle("Commands available: list | quit | check [CVE_NUMBER] | exploit [CVE_NUMBER]", None)
        while True:
            buf = prompt("\nDrupwn> ", history=self.history, completer=self.auto_cmds, complete_while_typing=False)
            args = buf.split(" ")
            try:
                if args[0] == "quit":
                    break
                self.cmds[args[0]](args)
            except:
                pass 
Example #7
Source File: hello-world.py    From python-prompt-toolkit with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def interact(connection):
    clear()
    connection.send("Welcome!\n")

    # Ask for input.
    result = await prompt(message="Say something: ", async_=True)

    # Send output.
    connection.send("You said: {}\n".format(result))
    connection.send("Bye.\n") 
Example #8
Source File: custom-lexer.py    From python-prompt-toolkit with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def main():
    answer = prompt("Give me some input: ", lexer=RainbowLexer())
    print("You said: %s" % answer) 
Example #9
Source File: clock-input.py    From python-prompt-toolkit with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def get_prompt():
    " Tokens to be shown before the prompt. "
    now = datetime.datetime.now()
    return [
        ("bg:#008800 #ffffff", "%s:%s:%s" % (now.hour, now.minute, now.second)),
        ("bg:cornsilk fg:maroon", " Enter something: "),
    ] 
Example #10
Source File: clock-input.py    From python-prompt-toolkit with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def main():
    result = prompt(get_prompt, refresh_interval=0.5)
    print("You said: %s" % result) 
Example #11
Source File: multi-column-autocompletion-with-meta.py    From python-prompt-toolkit with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def main():
    text = prompt(
        "Give some animals: ",
        completer=animal_completer,
        complete_style=CompleteStyle.MULTI_COLUMN,
    )
    print("You said: %s" % text) 
Example #12
Source File: fuzzy-word-completer.py    From python-prompt-toolkit with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def main():
    text = prompt(
        "Give some animals: ", completer=animal_completer, complete_while_typing=True
    )
    print("You said: %s" % text) 
Example #13
Source File: autocompletion-like-readline.py    From python-prompt-toolkit with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def main():
    text = prompt(
        "Give some animals: ",
        completer=animal_completer,
        complete_style=CompleteStyle.READLINE_LIKE,
    )
    print("You said: %s" % text) 
Example #14
Source File: shell.py    From shellen with MIT License 5 votes vote down vote up
def prompt(self):
        message = [
            ('class:pygments.os',    OS_MATCHING[self.os]),
            ('class:pygments.colon', ':'),
            ('class:pygments.mode',  self.mode),
            ('class:pygments.colon', ':'),
            ('class:pygments.arch',  self.pexec.arch),
            ('class:pygments.pound', ' > ')
        ]

        return prompt(message, style=self.prompt_style, history=self.__get_history()) 
Example #15
Source File: shell.py    From shellen with MIT License 5 votes vote down vote up
def irun(self):
        while True:
            try:
                cmd = self.prompt()
                if cmd == '':
                    continue
                else:
                    if not self.handle_command(cmd):
                        cprint('\n<red,bold>[-]</> Invalid command.\n')
            except Exception as e:
                cprint('\n<red,bold>[-]</> Error occured: {}\n'.format(e))
            except KeyboardInterrupt:
                cprint()