question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Refresh prompt from custom key binding

See original GitHub issue

I am trying to oweride ctrl+d with custom command, calling command works but after presing c-d prompt and bottom toolbar are same. (commands.exit() changes prompt and bottom toolbar but) They change only if I pres enter, how can I redraw prompt and bottom toolbar from custom binding?

here is example code

def shell():
    """Repl shell"""
    print("Welcome")
    prompt = PromptSession(
        history=FileHistory(os.path.join(os.path.expanduser("~"), ".history.txt"))
    )
    commands = Commands()
    bindings = KeyBindings()

    @bindings.add("c-d")
    def _(event):
        def print_exit():
            print(commands.exit())

        run_in_terminal(print_exit)

    while True:
        try:
            user_input = prompt.prompt(
                commands.prompt,
                auto_suggest=AutoSuggestFromHistory(),
                enable_history_search=True,
                key_bindings=bindings,
                bottom_toolbar=commands.bottom,
            )
            if not user_input:
                continue
            except (EOFError, KeyboardInterrupt):
                break

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
jonathanslenderscommented, Nov 20, 2018

I think the following should do it:

from prompt_toolkit.application import get_app

get_app().invalidate()
0reactions
deeuucommented, Aug 6, 2020

I too would very much appreciate a concrete example of updating the prompt from a custom key binding!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Visual Studio Code Key Bindings
Here you will find the complete list of key bindings for Visual Studio Code and how to change them.
Read more >
Enable the list refresh prompt - ServiceNow Docs
Receive a prompt to refresh a list when a list item has changed. A prompt indicates when to refresh the list, and after...
Read more >
Reload of tmux config not unbinding keys (bind-key is ...
If I reload my tmux config (from within tmux) the keybindings I once had loaded will remain loaded. The only way (I know...
Read more >
Tutorial: prompt_toolkit custom keybindings - Xonsh
The prompt_toolkit shell has a registry for handling custom keybindings. You may not like the default keybindings in xonsh, or you may want...
Read more >
How to "bind -x" keyboard shortcut and refresh prompt
redraw-current-line is a command in readline, you don't install it. Bash uses the readline library and that's it, the command is already ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found