
    7U                     T    d dl mZ d dlZd dlZd dlZd dlZd dlZd Z G d de      Z	y)    )absolute_importNc                 0   t        j                  | j                               sy	 t        j                  dt        j                  | t        j                  d            }|S #  	 t         j                  d   t         j                  d   f}Y |S #  Y Y yxY wxY w)z
    Return a tuple (rows,cols) representing the size of the TTY `fd`.

    The provided file descriptor should be the stdout stream of the TTY.

    If the TTY size cannot be determined, returns None.
    NhhhhhhLINESCOLUMNS)
osisattyfilenostructunpackfcntlioctltermios
TIOCGWINSZenviron)fddimss     //usr/lib/python3/dist-packages/dockerpty/tty.pysizer      s     99RYY[!}}T5;;r73E3Ev#NO K	JJw'I)>?D K	s#   9A! !B$&BBBBc                   <    e Zd ZdZd
dZd Zd Zd Zd Zd Z	d Z
y	)Terminalz
    Terminal provides wrapper functionality to temporarily make the tty raw.

    This is useful when streaming data from a pseudo-terminal into the tty.

    Example:

        with Terminal(sys.stdin, raw=True):
            do_things_in_raw_mode()
    c                 .    || _         || _        d| _        y)a  
        Initialize a terminal for the tty with stdin attached to `fd`.

        Initializing the Terminal has no immediate side effects. The `start()`
        method must be invoked, or `with raw_terminal:` used before the
        terminal is affected.
        N)r   raworiginal_attributes)selfr   r   s      r   __init__zTerminal.__init__=   s     #'     c                 &    | j                          | S )z?
        Invoked when a `with` block is first entered.
        )startr   s    r   	__enter__zTerminal.__enter__K   s    
 	

r   c                 $    | j                          y)z:
        Invoked when a `with` block is finished.
        N)stop)r   _s     r   __exit__zTerminal.__exit__T   s    
 			r   c                     | j                   S )zE
        Returns True if the TTY should operate in raw mode.
        )r   r!   s    r   israwzTerminal.israw\   s    
 xxr   c                    t        j                  | j                  j                               rU| j	                         rDt        j                  | j                        | _        t        j                  | j                         yyy)z}
        Saves the current terminal attributes and makes the tty raw.

        This method returns None immediately.
        N)
r	   r
   r   r   r(   r   	tcgetattrr   ttysetrawr!   s    r   r    zTerminal.startd   sR     99TWW^^%&4::<'.'8'8'AD$JJtww ,8&r   c                     | j                   :t        j                  | j                  t        j                  | j                          yy)z
        Restores the terminal attributes back to before setting raw mode.

        If the raw terminal was not started, does nothing.
        N)r   r   	tcsetattrr   	TCSADRAINr!   s    r   r$   zTerminal.stopp   s<     ##/!!(( 0r   c                 x    dj                  t        |       j                  | j                  | j                        S )Nz{cls}({fd}, raw={raw}))clsr   r   )formattype__name__r   r   r!   s    r   __repr__zTerminal.__repr__~   s5    '..T
##ww /  	r   N)T)r4   
__module____qualname____doc__r   r"   r&   r(   r    r$   r5    r   r   r   r   1   s*    	(	 r   r   )

__future__r   r	   r   r+   r   r   r   objectr   r9   r   r   <module>r<      s,   " ' 	  
  .Qv Qr   