File: //proc/1233/cwd/usr/lib/python3/dist-packages/dockerpty/__pycache__/tty.cpython-310.pyc
o
�7U� � @ sP d dl mZ d dlZd dlZd dlZd dlZd dlZdd� ZG dd� de�Z dS )� )�absolute_importNc C sd t �| �� �s dS zt�dt�| tjd��}W |S zt j d t j d f}W Y |S Y Y dS )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�dims� r �//usr/lib/python3/dist-packages/dockerpty/tty.py�size s ��r c @ sJ e Zd ZdZddd�Zdd� Zdd� Zd d
� Zdd� Zd
d� Z dd� Z
dS )�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()
Tc C s || _ || _d| _dS )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 r r r �__init__= s
zTerminal.__init__c C s | � � | S )z?
Invoked when a `with` block is first entered.
)�start�r r r r � __enter__K s zTerminal.__enter__c G s | � � dS )z:
Invoked when a `with` block is finished.
N)�stop)r �_r r r �__exit__T s zTerminal.__exit__c C s | j S )zE
Returns True if the TTY should operate in raw mode.
)r r r r r �israw\ s zTerminal.israwc C s>