o
    Þ­jé  ã                   @   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 rät
ƒ ‚|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@   úR/var/www/html/CropPilot/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    