signebedi / gptty

ChatGPT wrapper in your TTY
MIT License
47 stars 7 forks source link

[runtime] gracefully handle keyboard interrupts in `chat` #51

Closed signebedi closed 1 year ago

signebedi commented 1 year ago

When we want to re-write our queries in chat, we should be able to use keyboard interrupts without breaking the program. Something like:

        # Get user input
        try:
            i = await session.prompt_async(ANSI(f"{CYAN}> {RESET}"))
            # i = await ainput(f"{CYAN}> ")
            tag,question = get_tag_from_text(i)
            prompt_length = len(question)

        # handle keyboard interrupt
        except KeyboardInterrupt:
            i = None