o
    !h                     @   sB   d Z ddlZddlZddlmZ ddlmZmZ defddZ	dS )z
Unified getchar implementation for all platforms.

Combines approaches from:
- Textual (Unix/Linux): Copyright (c) 2023 Textualize Inc., MIT License
- Click (Windows fallback): Copyright 2014 Pallets, BSD-3-Clause License
    N)getincrementaldecoder)OptionalTextIOreturnc                  C   sP  t jdkrgzddl} W n ty   t jd Y S w | j}| }|dv r,|| 7 }|S |g}d}t||k rY|  rY| }|dv rCn|	| |dkrOt
 t||k rY|  s;d|}d|v ret
 |S ddl}ddl}d}	t j std	}	|	 }
nt j }
z||
}zt||
}||j  |j|jB |jB |jB  M  < ||j  |j|jB |jB |jB |jB  M  < d||j |j< ||
|j | t!|
d}t"d
 }|j#|dd}d|v rt
 |W ||
|j | t j$%  |	dur|	&  W S W S ||
|j | t j$%  |	dur|	&  w w  |j'y'   t jd Y S w )a.  
    Read input from stdin with support for longer pasted text.

    On Windows:
    - Uses msvcrt for native Windows console input
    - Handles special keys that send two-byte sequences
    - Reads up to 4096 characters for paste support

    On Unix/Linux:
    - Uses Textual's approach with manual termios configuration
    - Reads up to 4096 bytes with proper UTF-8 decoding
    - Provides fine-grained terminal control

    Returns:
        str: The input character(s) read from stdin

    Raises:
        KeyboardInterrupt: When CTRL+C is pressed
    win32r   N   )    ài    z/dev/ttyzutf-8T)final)(sysplatformmsvcrtImportErrorstdinreadgetwchlenkbhitappendKeyboardInterruptjointermiosttyisattyopenfileno	tcgetattrLFLAGECHOICANONIEXTENISIGIFLAGIXONIXOFFICRNLINLCRIGNCRCCVMIN	tcsetattrTCSANOWosr   decodestdoutflushcloseerror)r   funcrvchars	max_chars	next_charresultr   r   ffdattrs_beforenewattrraw_datadecoder r@   W/var/www/html/pro-man-master/venv/lib/python3.10/site-packages/rich_toolkit/_getchar.pygetchar   s   
















rB   )
__doc__r.   r   codecsr   typingr   r   strrB   r@   r@   r@   rA   <module>   s    