
    i"                         S r SSKJr  SSKJr  SSKJr  SSKrSSKrSSKJr  S r	S r
S	 rS
 rS rSrSrSrSrSrS rS rS rg)z*OS specific console_attr helper functions.    )absolute_import)division)unicode_literalsN)encodingc                      Sn [         [        [        [        4 H  n U" 5       n U (       a    OM     U =(       d    S$ !    M(  = f)zGets the terminal x and y dimensions in characters.

_GetTermSize*() helper functions taken from:
  http://stackoverflow.com/questions/263890/

Returns:
  (columns, lines): A tuple containing the terminal x and y dimensions.
N)P      )_GetTermSizePosix_GetTermSizeWindows_GetTermSizeEnvironment_GetTermSizeTput)xyget_terminal_sizes     \/var/www/html/banglarbhumi/venv/lib/python3.13/site-packages/fire/console/console_attr_os.pyGetTermSizer      sP     "-/3,.b	 
. 
x
s	   <Ac                    ^^^ SSK mSSKmSSKmUUU4S jn U " S5      =(       d    U " S5      =(       d    U " S5      nU(       d^  Sn [        R                  " [        R
                  " 5       [        R                  5      nU " U5      nUb  [        R                  " U5        U$ U$ !   Sn N#= f! Ub  [        R                  " U5        f f = f)z.Returns the Posix terminal x and y dimensions.r   Nc                    >  TR                  STR                  U TR                  S5      5      nU(       a
  US   US   4$ S$ !    g= f)zReturns the terminal (x,y) size for fd.

Args:
  fd: The terminal file descriptor.

Returns:
  The terminal (x,y) size for fd or None on error.
s   hhs   junk   r   N)unpackioctl
TIOCGWINSZ)fdrcfcntlstructtermioss     r   _GetXY!_GetTermSizePosix.<locals>._GetXY=   sP     ==B0B0BG LMb!beRU^+t+s   =A A Ar      )r   r   r   osopenctermidO_RDONLYclose)r   r   r   r   r   r   s      @@@r   r
   r
   4   s     " ay*F1I*"		B772::<-b":b 

	))b	
 
s   A B% %B+)B. .C
c                     SSK n SSKJn  SSKJn  UR                  R                  S5      nU" S5      nUR                  R                  X45      (       d  gU R                  SUR                  5      u  pVpxn	pppX-
  S-   nX-
  S-   nUU4$ )	z0Returns the Windows terminal x and y dimensions.r   N)create_string_buffer)windlli   s   hhhhHhhhhhhr   )	r   ctypesr&   r'   kernel32GetStdHandleGetConsoleScreenBufferInfor   raw)r   r&   r'   hcsbiunused_bufxunused_bufyunused_curxunused_curyunused_wattrlefttoprightbottomunused_maxxunused_maxyxys                     r   r   r   \   s     ) oo""3'!	b	!$		3	3A	<	<  &}}^TXXF;[|elQ!lQ!
Q-    c                  r    [        [        R                  S   5      [        [        R                  S   5      4$ )z=Returns the terminal x and y dimensions from the environment.COLUMNSLINES)intr    environ r=   r   r   r   u   s)    
bjj#
$c"**W*=&>	??r=   c                      SSK n [        R                  " U R                  SS/U R                  S95      n[        U5      n[        R                  " U R                  SS/U R                  S95      n[        U5      nX#4$ )z5Returns the terminal x and y dimensions from tput(1).r   Ntputcols)stderrlines)
subprocessr   Decodecheck_outputSTDOUTrA   )rI   outputrF   rowss       r   r   r   z   s    ??:22FF3C:D:K:K 3 M N&	V$??:22FG3D:D:K:K 3 M N&	V$
r=       àc                  N    [         [        4 H  n  U " 5       s  $    S $ !    M  = f)zReturns a function that reads one keypress from stdin with no echo.

Returns:
  A function that reads one keypress from stdin with no echo or a function
  that always returns None if stdin does not support it.
c                      g NrC   rC   r=   r   <lambda>#GetRawKeyFunction.<locals>.<lambda>   s    r=   )_GetRawKeyFunctionPosix_GetRawKeyFunctionWindows)get_raw_key_functions    r   GetRawKeyFunctionr\      s7      78:!##: 

s   $c                  (   ^^ SSK mSSKmUU4S jn U $ )z+_GetRawKeyFunction helper using Posix APIs.r   Nc                    >^ SSSSSSSSSSSS	.n [         R                  R                  5         [         R                  R	                  5       mU4S
 jnTR                  T5      n TR                  T5        U" 5       nU[        :X  a  U" 5       n U[        :X  a  UTR                  TTR                  U5        $ UR                  5       (       a  OUnU" 5       nUS:X  a  UnOMS  U R                  US5      TR                  TTR                  U5        $  TR                  TTR                  U5        U[        [        4;   a  S$ U$ !   Sn N7= f! TR                  TTR                  U5        f = f)zReads and returns one keypress from stdin, no echo, using Posix APIs.

Returns:
  The key name, None for EOF, <*> for function keys, otherwise a
  character.

<UP-ARROW><DOWN-ARROW><LEFT-ARROW><RIGHT-ARROW>	<PAGE-UP><PAGE-DOWN><HOME><END>)ABDC56HFMSTc                  Z   > [         R                  " [        R                  " T S5      5      $ )Nr   )r   rJ   r    read)r   s   r   _GetKeyCharE_GetRawKeyFunctionPosix.<locals>._GetRawKeyPosix.<locals>._GetKeyChar   s    __RWWR^,,r=   ~ N)sysstdoutflushstdinfileno	tcgetattrsetraw	_ANSI_CSI	tcsetattr	TCSADRAINisalphaget
_CONTROL_D
_CONTROL_Z)ansi_to_keyrt   old_settingscprev_cr   r   ttys        @r   _GetRawKeyPosix0_GetRawKeyFunctionPosix.<locals>._GetRawKeyPosix   si    K  JJ				B- $$R(L=	jjn
-a	
iM)^ G--|< YY[[&m!#XA  q"% G--|<! 
  G--|<Z0047a7	
aG--|<s$   %5E 8;E E E	E E+)r   r   )r   r   r   s    @@r   rY   rY      s     38j 
r=   c                     ^ SSK mU4S jn U $ )z-_GetRawKeyFunction helper using Windows APIs.r   Nc            	         > SSSSSSSSS	.n [         R                  R                  5         U4S
 jnU" 5       nU[        [        4;   a  U R                  U" 5       S5      $ U[        [        4;   a  S$ U$ )zReads and returns one keypress from stdin, no echo, using Windows APIs.

Returns:
  The key name, None for EOF, <*> for function keys, otherwise a
  character.
r_   r`   ra   rb   rc   rd   re   rf   )rm   PKro   IQGOc                  L   > [         R                  " T R                  5       5      $ rV   )r   rJ   getchmsvcrts   r   rt   I_GetRawKeyFunctionWindows.<locals>._GetRawKeyWindows.<locals>._GetKeyChar   s    __V\\^,,r=   rw   N)rx   ry   rz   _WINDOWS_CSI_1_WINDOWS_CSI_2r   r   r   )windows_to_keyrt   r   r   s      r   _GetRawKeyWindows4_GetRawKeyFunctionWindows.<locals>._GetRawKeyWindows   s}     	N JJ- 	A^^,,r22Z0047a7r=   r   )r   r   s    @r   rZ   rZ      s     8> 
r=   )__doc__
__future__r   r   r   r    rx   fire.consoler   r   r
   r   r   r   r   r   r   r   r   r\   rY   rZ   rC   r=   r   <module>r      sb     1 &  ' 	 
 !0%P2@
	 	

"<~$r=   