From 659ce00c4020af1c126689a43e4003e9073101e0 Mon Sep 17 00:00:00 2001 From: Paul Gauthier Date: Tue, 9 May 2023 14:16:47 -0700 Subject: [PATCH] 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. --- aider/getinput.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/aider/getinput.py b/aider/getinput.py index ecabdc198..2bcc991db 100644 --- a/aider/getinput.py +++ b/aider/getinput.py @@ -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