mirror of
https://github.com/Aider-AI/aider.git
synced 2025-05-23 22:04:59 +00:00
handle piped input for canned asciinema demos
This commit is contained in:
parent
9b734cb149
commit
4c97799b42
2 changed files with 31 additions and 23 deletions
|
@ -164,6 +164,8 @@ class Coder:
|
|||
if self.num_control_c >= 2:
|
||||
break
|
||||
self.console.print("[bold red]^C again to quit")
|
||||
except EOFError:
|
||||
return
|
||||
|
||||
def run_loop(self):
|
||||
if self.pretty:
|
||||
|
@ -336,6 +338,8 @@ class Coder:
|
|||
for match in self.pattern.finditer(content):
|
||||
_, path, _, _, original, updated = match.groups()
|
||||
|
||||
path = path.strip()
|
||||
|
||||
if path not in self.fnames:
|
||||
if not Path(path).exists():
|
||||
question = f"[red bold]Allow creation of new file {path}?"
|
||||
|
|
|
@ -5,6 +5,12 @@ from prompt_toolkit import prompt
|
|||
from prompt_toolkit.completion import Completer, Completion
|
||||
from prompt_toolkit.history import FileHistory
|
||||
|
||||
from rich.console import Console
|
||||
import sys
|
||||
import time
|
||||
import random
|
||||
|
||||
|
||||
class FileContentCompleter(Completer):
|
||||
def __init__(self, fnames):
|
||||
self.fnames = fnames
|
||||
|
@ -20,28 +26,29 @@ class FileContentCompleter(Completer):
|
|||
with open(fname, "r") as f:
|
||||
content = f.read()
|
||||
|
||||
for word in re.split(r'\W+', content):
|
||||
for word in re.split(r"\W+", content):
|
||||
if word.startswith(last_word):
|
||||
yield Completion(word, start_position=-len(last_word))
|
||||
|
||||
|
||||
from rich.console import Console
|
||||
import sys
|
||||
import time
|
||||
import random
|
||||
def canned_input():
|
||||
console = Console()
|
||||
|
||||
console = Console()
|
||||
|
||||
def get_input(history_file, fnames):
|
||||
if not sys.stdin.isatty():
|
||||
input_line = input()
|
||||
|
||||
console.print("> ", end="", style="green")
|
||||
for char in input_line:
|
||||
console.print(char, end="", style="green", flush=True)
|
||||
time.sleep(random.uniform(0.05, 0.1))
|
||||
console.print(char, end="", style="green")
|
||||
time.sleep(random.uniform(0.01, 0.15))
|
||||
console.print()
|
||||
console.print()
|
||||
return input_line
|
||||
|
||||
|
||||
def get_input(history_file, fnames):
|
||||
if not sys.stdin.isatty():
|
||||
return canned_input()
|
||||
|
||||
inp = ""
|
||||
multiline_input = False
|
||||
|
||||
|
@ -54,15 +61,12 @@ def get_input(history_file, fnames):
|
|||
else:
|
||||
show = "> "
|
||||
|
||||
try:
|
||||
line = prompt(
|
||||
show,
|
||||
completer=completer_instance,
|
||||
history=FileHistory(history_file),
|
||||
style=style,
|
||||
)
|
||||
except EOFError:
|
||||
return
|
||||
if line.strip() == "{" and not multiline_input:
|
||||
multiline_input = True
|
||||
continue
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue