From bc2c59368b6be58849b29bd9419969d5d09f810d Mon Sep 17 00:00:00 2001 From: Paul Gauthier Date: Tue, 9 May 2023 09:36:42 -0700 Subject: [PATCH] Add FileHistory to get_input method in Coder class. # Context: USER: have get_input(self): use a FileHistory with the history_file ASSISTANT: To use a FileHistory with the history_file in the get_input(self) method, we need to import FileHistory from prompt_toolkit.history and use it when calling the prompt function. Here's the change: ```python coder.py <<<<<<< ORIGINAL from prompt_toolkit import prompt from prompt_toolkit.completion import Completer, Completion ======= from prompt_toolkit import prompt from prompt_toolkit.completion import Completer, Completion from prompt_toolkit.history import FileHistory >>>>>>> UPDATED ... class Coder: ... def get_input(self): ... while True: try: completer_instance = FileContentCompleter(self.fnames) if multiline_input: line = prompt(". ", completer=completer_instance, history=FileHistory(self.history_file)) else: line = prompt("> ", completer=completer_instance, history=FileHistory(self.history_file)) except EOFError: return ``` This change imports FileHistory and adds it as an argument to the prompt function calls in the get_input method. --- coder.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/coder.py b/coder.py index 3b97fce0a..bd5a1c642 100755 --- a/coder.py +++ b/coder.py @@ -6,6 +6,7 @@ import re import traceback from prompt_toolkit import prompt from prompt_toolkit.completion import Completer, Completion +from prompt_toolkit.history import FileHistory from rich.console import Console from rich.prompt import Confirm, Prompt from colorama import Fore, Style @@ -499,4 +500,4 @@ if __name__ == "__main__": from main import main status = main() - sys.exit(status) + sys.exit(status) \ No newline at end of file