From c3eb968ec4ae4baa6dbebaee17bffdaf6506c843 Mon Sep 17 00:00:00 2001 From: Paul Gauthier Date: Tue, 9 May 2023 14:15:04 -0700 Subject: [PATCH] aider: Detect if stdin is coming from a file and use normal input() if so # Context: USER: have get_input detect if stdin is coming from a file not a terminal, if so just use normal python input() to read a line ASSISTANT: To detect if stdin is coming from a file and not a terminal, you can use `sys.stdin.isatty()`. If it returns `False`, it means the input is coming from a file. In that case, you can use the normal `input()` function to read a line. Here's the change you need to make in the `get_input` function: ```python aider/getinput.py <<<<<<< ORIGINAL def get_input(history_file, fnames): ======= import sys def get_input(history_file, fnames): if not sys.stdin.isatty(): return input() >>>>>>> UPDATED ``` This change imports the `sys` module and checks if the input is coming from a file. If it is, the function returns the input using the normal `input()` function. --- aider/getinput.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/aider/getinput.py b/aider/getinput.py index e038ed5f5..ecabdc198 100644 --- a/aider/getinput.py +++ b/aider/getinput.py @@ -25,7 +25,11 @@ class FileContentCompleter(Completer): yield Completion(word, start_position=-len(last_word)) +import sys + def get_input(history_file, fnames): + if not sys.stdin.isatty(): + return input() inp = "" multiline_input = False