+
    ,j                    f    ^ RI Ht ^ RIHt  ^ RIHt Rt ! R R4      t	R#   ]]3 d    Rt Li ; i)	    )annotations)Optional)PyPtySessionTFc                      ] tR t^t$ RtR]R&   R R lt]R R l4       tR R	 lt	R
 R lt
R R ltR R ltRR R lltR R ltRtR# )
PtySessiona  
A pseudoterminal (PTY) session for interactive shell use.

This is the higher-level PTY API built on top of PtyProcess.
It provides convenient methods for interactive shell sessions with:
- Easy command sending via send_line()
- Interactive mode with wait_until pattern matching
- Automatic buffering and flushing

Use this for interactive shell sessions where you want to send commands
and optionally hand over control to the user.
r   _innerc                    V ^8  d   QhRRRR/# )   commandz	list[str]returnNone )formats   "7lib/python3.14/site-packages/rattler/pty/pty_session.py__annotate__PtySession.__annotate__   s     ', ',	 ',d ',    c                T    \         '       g   \        R4      h\        V4      V n        R# )a  
Create a new PTY session with the given command.

The PTY session is created with echo enabled by default, which is
appropriate for interactive shell use.

Arguments:
    command: A list of strings representing the command and its arguments.
             The first element is the executable, subsequent elements are arguments.

Raises:
    RuntimeError: If the PTY session could not be created.

Examples
--------
```python
>>> from rattler.pty import PtySession
>>> # Start an interactive bash session
>>> session = PtySession(["bash"])
>>> session.send_line("export MY_VAR=hello")
>>> # Hand over control to the user (blocks until shell exits)
>>> exit_code = session.interact()
>>>
```

If you want to send commands without using interact() (which blocks),
use exit() to clean up when done:

```python
>>> from rattler.pty import PtySession
>>> session = PtySession(["bash"])
>>> session.send_line("echo hello")
>>> status = session.exit()  # Clean up the session
>>>
```
z3PTY functionality is not available on this platformN)_PTY_AVAILABLEImportErrorr   r   )selfr   s   &&r   __init__PtySession.__init__   s"    J ~STT"7+r   c                    V ^8  d   QhRRRR/# )r
   py_pty_sessionr   r   r   r   )r   s   "r   r   r   H   s      , : r   c                4    V P                  V 4      pWn        V# )z'Construct from FFI PyPtySession object.)__new__r   )clsr   sessions   && r   _from_py_pty_sessionPtySession._from_py_pty_sessionG   s     ++c"'r   c                    V ^8  d   QhRRRR/# )r
   linestrr   intr   )r   s   "r   r   r   N   s     + +c +c +r   c                8    V P                   P                  V4      # )ar  
Send a string followed by a newline to the PTY session.

This is like typing a command and pressing Enter. The command is flushed
immediately, so the shell will receive it right away.

Arguments:
    line: The string to send (newline will be added automatically).

Returns:
    The number of bytes written.

Raises:
    RuntimeError: If the write operation fails.

Examples
--------
```python
>>> from rattler.pty import PtySession
>>> session = PtySession(["bash"])
>>> session.send_line("export MY_VAR=hello")
22
>>> session.send_line("echo $MY_VAR")
13
>>> session.exit()  # Clean up when done
'Signaled(SIGTERM)'
>>>
```
)r   	send_line)r   r#   s   &&r   r'   PtySession.send_lineN   s    < {{$$T**r   c                    V ^8  d   QhRRRR/# )r
   datar$   r   r%   r   )r   s   "r   r   r   n   s     & & & &r   c                8    V P                   P                  V4      # )a  
Send a string to the PTY session without adding a newline.

Note: You'll need to call flush() to ensure the data is sent.

Arguments:
    data: The string to send.

Returns:
    The number of bytes written.

Raises:
    RuntimeError: If the write operation fails.

Examples
--------
```python
>>> from rattler.pty import PtySession
>>> session = PtySession(["bash"])
>>> session.send("echo")
4
>>> session.send(" hello\n")
7
>>> session.flush()
>>> session.exit()  # Clean up when done
'Signaled(SIGTERM)'
>>>
```
)r   send)r   r*   s   &&r   r,   PtySession.sendn   s    < {{%%r   c                   V ^8  d   QhRR/# )r
   r   r   r   )r   s   "r   r   r      s      t r   c                :    V P                   P                  4        R# )a  
Flush any pending output to the PTY.

This is automatically called by send_line(), but can be called manually
if you use send().

Raises:
    RuntimeError: If the flush operation fails.

Examples
--------
```python
>>> from rattler.pty import PtySession
>>> session = PtySession(["bash"])
>>> session.send("echo hello\n")
11
>>> session.flush()  # Make sure the command is sent
>>> session.exit()  # Clean up when done
'Signaled(SIGTERM)'
>>>
```
N)r   flushr   s   &r   r0   PtySession.flush   s    . 	r   c                   V ^8  d   QhRR/# r
   r   r$   r   )r   s   "r   r   r      s     " "c "r   c                6    V P                   P                  4       # )a  
Exit the process gracefully by sending SIGTERM.

This method blocks until the process has exited. Useful for cleaning up
PTY sessions when you're done sending commands but don't want to use interact().

Returns:
    A string describing the exit status.

Raises:
    RuntimeError: If the process could not be terminated.

Examples
--------
```python
>>> from rattler.pty import PtySession
>>> session = PtySession(["bash"])
>>> session.send_line("echo hello")
11
>>> status = session.exit()
>>> print(status)
Signaled(SIGTERM)
>>>
```
)r   exitr1   s   &r   r6   PtySession.exit   s    4 {{!!r   Nc                    V ^8  d   QhRRRR/# )r
   
wait_untilzOptional[str]r   zOptional[int]r   )r   s   "r   r   r      s     +0 +0= +0M +0r   c                8    V P                   P                  V4      # )a  
Start an interactive session, optionally waiting for a pattern first.

This method:
1. Sets the terminal to raw mode
2. If wait_until is provided, buffers output until that pattern appears
3. Then forwards all I/O between the user's terminal and the PTY
4. Returns when the shell process exits

Arguments:
    wait_until: Optional pattern to wait for before showing output.
                Useful for waiting for shell initialization to complete.
                If not found within 1 second, a warning is shown and
                interaction begins anyway.

Returns:
    The exit code of the shell process, or None if terminated by signal.

Raises:
    RuntimeError: If interaction fails.

Examples
--------
```python
>>> session = PtySession(["bash"])
>>> # Send some setup commands
>>> session.send_line("export MY_VAR=hello")
>>> session.send_line("echo 'READY'")
>>> # Wait for "READY" before handing control to user
>>> exit_code = session.interact(wait_until="READY")
>>> print(f"Session exited with code: {exit_code}")
Session exited with code: 0
>>>
```

```python
>>> session = PtySession(["bash"])
>>> # Interact immediately without waiting
>>> exit_code = session.interact()
>>>
```
)r   interact)r   r9   s   &&r   r;   PtySession.interact   s    V {{##J//r   c                   V ^8  d   QhRR/# r4   r   )r   s   "r   r   r      s      # r   c                	    R # )zPtySession()r   r1   s   &r   __repr__PtySession.__repr__   s    r   )r   )N)__name__
__module____qualname____firstlineno____doc____annotations__r   classmethodr    r'   r,   r0   r6   r;   r?   __static_attributes__r   r   r   r   r      sO     ',R  +@&@2"8+0Z r   r   N)

__future__r   typingr   rattler.rattlerr   r   r   AttributeErrorr   r   r   r   <module>rM      s?    " ,N
c c	 	^$ Ns   " 00