mirror of
https://github.com/Aider-AI/aider.git
synced 2025-05-31 01:35:00 +00:00
fix: Add run_interactive_command function to aider/utils.py
This commit is contained in:
parent
0557f04bd7
commit
59a43bd0a1
1 changed files with 31 additions and 0 deletions
|
@ -5,6 +5,8 @@ import sys
|
|||
import tempfile
|
||||
import time
|
||||
from pathlib import Path
|
||||
import pexpect
|
||||
from io import BytesIO
|
||||
|
||||
import git
|
||||
|
||||
|
@ -12,6 +14,35 @@ from aider.dump import dump # noqa: F401
|
|||
|
||||
IMAGE_EXTENSIONS = {".png", ".jpg", ".jpeg", ".gif", ".bmp", ".tiff", ".webp"}
|
||||
|
||||
def run_interactive_command(command):
|
||||
"""
|
||||
Run a shell command interactively using pexpect, capturing all output.
|
||||
|
||||
:param command: The command to run as a string.
|
||||
:return: A tuple containing (exit_status, output)
|
||||
"""
|
||||
output = BytesIO()
|
||||
|
||||
def output_callback(b):
|
||||
output.write(b)
|
||||
return b
|
||||
|
||||
try:
|
||||
# Spawn the command
|
||||
child = pexpect.spawn(command, encoding=None)
|
||||
|
||||
# Transfer control to the user, capturing output
|
||||
child.interact(output_filter=output_callback)
|
||||
|
||||
# Wait for the command to finish and get the exit status
|
||||
child.close()
|
||||
return child.exitstatus, output.getvalue().decode('utf-8', errors='replace')
|
||||
|
||||
except pexpect.ExceptionPexpect as e:
|
||||
error_msg = f"Error running command: {e}"
|
||||
print(error_msg, file=sys.stderr)
|
||||
return 1, error_msg
|
||||
|
||||
|
||||
class IgnorantTemporaryDirectory:
|
||||
def __init__(self):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue