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.
This commit is contained in:
Paul Gauthier 2023-05-09 14:15:04 -07:00
parent b1fa3b91f9
commit c3eb968ec4

View file

@ -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