U
    ,ºc£  ã                   @   s   d Z ddlmZ ddlmZ ddlm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	mZ ddl	mZ dd	l	mZ ddd„Zddd„ZdS )z9General console printing utilities used by the Cloud SDK.é    )Úabsolute_import)Údivision)Úprint_functionN)Úconsole_attr)Úconsole_pager)Úencoding)ÚfilesFc                 C   sb   t j ¡ sdS | r t j ¡ s dS |r2t j ¡ s2dS |r^t d¡}t d¡}|s^|rZ|dkr^dS dS )aí  Determines if the current terminal session is interactive.

  sys.stdin must be a terminal input stream.

  Args:
    output: If True then sys.stdout must also be a terminal output stream.
    error: If True then sys.stderr must also be a terminal output stream.
    heuristic: If True then we also do some additional heuristics to check if
               we are in an interactive context. Checking home path for example.

  Returns:
    True if the current terminal session is interactive.
  FÚHOMEÚHOMEPATHú/T)ÚsysÚstdinÚisattyÚstdoutÚstderrÚosÚgetenv)ÚoutputÚerrorÚ	heuristicÚhomeZhomepath© r   ú;/tmp/pip-unpacked-wheel-1xt1w7un/fire/console/console_io.pyÚIsInteractive!   s    


r   Tc           
      C   s  t dds| | ¡ dS |rþt tjdd¡}|dkr:d}n |sZdD ]}t |¡rB|} qZqB|rþt tjdd¡}d|pvd	 }t tjd|¡ t	 	t	j
t	j¡ tj|tjdd
}t ¡  ¡ }	|j|  |	¡d | ¡  t	 	t	j
t	j¡ |dkrút tjdd¡ dS t | ||¡ ¡  dS )a  Run a user specified pager or fall back to the internal pager.

  Args:
    contents: The entire contents of the text lines to page.
    out: The output stream.
    prompt: The page break prompt.
    check_pager: Checks the PAGER env var and uses it if True.
  T)r   NZPAGERú-)ÚlessÚpagerÚLESSz-RÚ )r   Úshell)Úinput)r   Úwriter   ZGetEncodedValuer   Úenvironr   ZFindExecutableOnPathZSetEncodedValueÚsignalÚSIGINTÚSIG_IGNÚ
subprocessÚPopenÚPIPEr   ZGetConsoleAttrZGetEncodingÚcommunicateÚencodeÚwaitÚSIG_DFLr   ZPagerZRun)
ÚcontentsÚoutÚpromptZcheck_pagerr   ÚcommandZ	less_origr   ÚpÚencr   r   r   ÚMoreH   s4    	


r3   )FFF)NT)Ú__doc__Ú
__future__r   r   r   r   r#   r&   r   Zfire.consoler   r   r   r   r   r3   r   r   r   r   Ú<module>   s   
'