From 6ba8b7d41e6b324dc4f844c7c993b729c10c09e8 Mon Sep 17 00:00:00 2001 From: Paul Gauthier Date: Tue, 9 May 2023 09:03:45 -0700 Subject: [PATCH] Switch `get_input()` to use `prompt_toolkit` for input`. # Context: USER: switch get_input() to use prompt_toolkit for input ASSISTANT: To switch `get_input()` to use `prompt_toolkit` for input, you'll need to install the `prompt_toolkit` library and replace the current input method with the `prompt_toolkit`'s `prompt` function. Here's how to make the change: 1. Install `prompt_toolkit` by adding it to your project's requirements or running `pip install prompt_toolkit`. 2. Import `prompt` from `prompt_toolkit` at the beginning of the `coder.py` file. 3. Replace the current input method in the `get_input()` function with the `prompt` function from `prompt_toolkit`. Here are the changes to the `coder.py` file: ```python coder.py <<<<<<< ORIGINAL import sys import re import readline import traceback ======= import sys import re import traceback from prompt_toolkit import prompt >>>>>>> UPDATED ``` ```python coder.py <<<<<<< ORIGINAL while True: try: if multiline_input: line = input(". ") else: line = input("> ") except EOFError: return ======= while True: try: if multiline_input: line = prompt(". ") else: line = prompt("> ") except EOFError: return >>>>>>> UPDATED ``` These changes will replace the standard `input()` function with the `prompt_toolkit`'s `prompt` function in the `get_input()` method. --- coder.py | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/coder.py b/coder.py index 642f0ba5b..5f3d8e7d9 100755 --- a/coder.py +++ b/coder.py @@ -3,8 +3,8 @@ import sys import re -import readline import traceback +from prompt_toolkit import prompt from rich.console import Console from rich.prompt import Confirm, Prompt from colorama import Fore, Style @@ -135,15 +135,14 @@ class Coder: else: print() - while True: - try: - if multiline_input: - line = input(". ") - else: - line = input("> ") - except EOFError: - return - +while True: + try: + if multiline_input: + line = prompt(". ") + else: + line = prompt("> ") + except EOFError: + return if line.strip() == "{" and not multiline_input: multiline_input = True continue @@ -480,4 +479,4 @@ if __name__ == "__main__": from main import main status = main() - sys.exit(status) + sys.exit(status) \ No newline at end of file