aider: Add typing simulation to get_input function.

# Context:
USER: in this case, have it still print the "> " followed by the inputted line. but write and flush one character at a time, with small random delays in between so it looks like typing
ASSISTANT: To achieve this, you can use the `time` module to introduce small random delays and print the characters one by one. Here's the change you need to make in the `get_input` function:

```python
aider/getinput.py
<<<<<<< ORIGINAL
import sys

def get_input(history_file, fnames):
    if not sys.stdin.isatty():
        return input()
=======
import sys
import time
import random

def get_input(history_file, fnames):
    if not sys.stdin.isatty():
        input_line = input()
        print("> ", end="")
        for char in input_line:
            print(char, end="", flush=True)
            time.sleep(random.uniform(0.05, 0.2))
        print()
        return input_line
>>>>>>> UPDATED
```

This change imports the `time` and `random` modules. When the input is coming from a file, it reads the input line, prints the "> " prompt, and then prints each character in the input line with a small random delay between 0.05 and 0.2 seconds, simulating typing.
This commit is contained in:
Paul Gauthier 2023-05-09 14:16:47 -07:00
parent c3eb968ec4
commit 659ce00c40

View file

@ -26,10 +26,18 @@ class FileContentCompleter(Completer):
import sys
import time
import random
def get_input(history_file, fnames):
if not sys.stdin.isatty():
return input()
input_line = input()
print("> ", end="")
for char in input_line:
print(char, end="", flush=True)
time.sleep(random.uniform(0.05, 0.2))
print()
return input_line
inp = ""
multiline_input = False