
    	D,j                     z    d dl Z d dlZd dlZd dlZd dlmZ d dlZd dlZddZd Z	ddej
        j        fdZd	dZdS )
    N)BytesIOFc                 v   	 t           j                                        r=t          t          d          r(t          j                    dk    rt          | ||          S t          | ||          S # t          $ r@}d|  dt          |           }|t          |           n ||           d|fcY d }~S d }~ww xY w)NspawnWindowsz&Error occurred while running command 'z':    )sysstdinisattyhasattrpexpectplatformsystemrun_cmd_pexpectrun_cmd_subprocessOSErrorstrprint)commandverboseerror_printcwdeerror_messages         \/home/rurouni/.local/share/uv/tools/aider-chat/lib/python3.11/site-packages/aider/run_cmd.pyrun_cmdr      s     9 	:''7";"; 	:@Q@QU^@^@^"7GS999!'7C888      UUUSQRVVUU-    K&&&- s$   AA. A. .
B885B3-B83B8c                      	 t          j                    } 	 |                                 }|n/|                                                                }|dv r|S |} Fd S # t
          $ r Y d S w xY w)NT)powershell.exezcmd.exe)psutilProcessparentnamelower	Exception)current_processr    parent_names      r   get_windows_parent_process_namer&      s     .**	%$++--F~ ++----//K;;;""$O	% t   tts   AA A 
A,+A,c                    |rt          d|            	 t          j                            dd          }d }t	          j                    dk    rt                      }|dk    rd|  } |rGt          d|            t          d|           t	          j                    dk    rt          d	|           t          j        | t          j	        t          j
        d
d
|ddd
|
  
        }g }	 |j                            d          }|sn(t          |dd
           |                    |           E|                                 |j        d                    |          fS # t"          $ r}	dt%          |	          fcY d }	~	S d }	~	ww xY w)NzUsing run_cmd_subprocess:SHELL/bin/shr   r   zpowershell -Command zRunning command:zSHELL:zParent process:Treplacer   )	stdoutstderrtextshellencodingerrorsbufsizeuniversal_newlinesr   r    )endflush)r   osenvirongetr   r   r&   
subprocessPopenPIPESTDOUTr+   readappendwait
returncodejoinr#   r   )
r   r   r   r/   r.   parent_processprocessoutputchunkr   s
             r   r   r   *   s    4)7333(
w	22 ?	))<>>N!111::: 	9$g...(E"""  I--'888"?$#
 
 
 	!N''**E %Rt,,,,MM%   	! 	!2776??22   #a&&ys   EE 
E>#E93E>9E>c                    |rt          d|            t                      fd}	 t          j                            dd          }|rt          d|           t          j                            |          r.|rt          d|           t          j        |dd| gd	|
          }n(|rt          d           t          j        | d	|          }|	                    |           |
                                 |j                                                            d	d          fS # t          j        t          t           f$ r}d|  d| }d|fcY d}~S d}~ww xY w)z
    Run a shell command interactively using pexpect, capturing all output.

    :param command: The command to run as a string.
    :param verbose: If True, print output in real-time.
    :return: A tuple containing (exit_status, output)
    zUsing run_cmd_pexpect:c                 2                         |            | S )N)write)brD   s    r   output_callbackz(run_cmd_pexpect.<locals>.output_callbackf   s    Q    r(   r)   zWith shell:z!Running pexpect.spawn with shell:z-iz-czutf-8)argsr/   r   z$Running pexpect.spawn without shell.)r/   r   )output_filterr*   )r0   zError running command z: r   N)r   r   r6   r7   r8   pathexistsr   r   interactclose
exitstatusgetvaluedecodeExceptionPexpect	TypeError
ValueError)	r   r   r   rJ   r.   childr   	error_msgrD   s	           @r   r   r   Y   s     1&000YYF    
w	22 	(-'''7>>%   		F B95AAAM%tT7.Cg[^___EE  ><===M'GEEEE 	_555 	!2!2!9!9')!9!T!TTT$i<   ;W;;;;	)|s   D D) )EEEE)FNN)FN)r6   r   r9   r   ior   r   r   r   r&   r+   r/   r   r    rK   r   <module>r\      s    				      



                   ).4#*BU , , , ,^+ + + + + +rK   