mirror of
https://github.com/Aider-AI/aider.git
synced 2025-05-29 16:54:59 +00:00
feat: Introduce run_interactive_command
that uses pexpect
if available, otherwise falls back to subprocess
This commit is contained in:
parent
444416638a
commit
15521c41d1
1 changed files with 24 additions and 1 deletions
|
@ -8,13 +8,36 @@ from io import BytesIO
|
|||
from pathlib import Path
|
||||
|
||||
import git
|
||||
import pexpect
|
||||
|
||||
from aider.dump import dump # noqa: F401
|
||||
|
||||
IMAGE_EXTENSIONS = {".png", ".jpg", ".jpeg", ".gif", ".bmp", ".tiff", ".webp"}
|
||||
|
||||
|
||||
def run_interactive_command(command):
|
||||
try:
|
||||
import pexpect
|
||||
return run_interactive_command_pexpect(command)
|
||||
except ImportError:
|
||||
return run_interactive_command_subprocess(command)
|
||||
|
||||
|
||||
def run_interactive_command_subprocess(command):
|
||||
try:
|
||||
result = subprocess.run(
|
||||
command,
|
||||
stdout=subprocess.PIPE,
|
||||
stderr=subprocess.STDOUT,
|
||||
text=True,
|
||||
shell=True,
|
||||
encoding=sys.stdout.encoding,
|
||||
errors="replace"
|
||||
)
|
||||
return result.returncode, result.stdout
|
||||
except Exception as e:
|
||||
return 1, str(e)
|
||||
|
||||
|
||||
def run_interactive_command_pexpect(command):
|
||||
"""
|
||||
Run a shell command interactively using pexpect, capturing all output.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue