+
    rh"                         R t ^ RIHt ^ RIHt ^ RIHt ^ RIt^ RIt^ RIHt R t	R t
R tR	 tR
 tRtRtRtRtRtR tR tR tR# )z*OS specific console_attr helper functions.)absolute_import)division)unicode_literalsN)encodingc                     Rp \         \        \        \        3 F  p V! 4       p V '       d    MK  	  T ;'       g    R#     K*  ; i)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     >/usr/lib/python3/dist-packages/fire/console/console_attr_os.pyGetTermSizer      sR     "-/3,.b	 
. 
x
s	   >Ac                   aaa ^ RI o^ RIo^ RIoVVV3R lp V ! ^ 4      ;'       g    V ! ^4      ;'       g	    V ! ^4      pV'       g`   Rp \        P                  ! \        P
                  ! 4       \        P                  4      pV ! V4      pTe   \        P                  ! T4       T# V#    Rp L$; i  Te   \        P                  ! T4       i i ; i)z.Returns the Posix terminal x and y dimensions.Nc                   <  SP                  RSP                  V SP                  R4      4      pV'       d   V^,          V^ ,          3# R#     R# ; i)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   junkN)unpackioctl
TIOCGWINSZ)fdrcfcntlstructtermioss   & r   _GetXY!_GetTermSizePosix.<locals>._GetXY=   sP     ==B0B0BG LMb!beRU^+t+s   4A A 
A A)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/-B2 2Cc                 8   ^ RI p ^ RIHp ^ RIHp VP                  P                  R4      pV! ^4      pVP                  P                  W44      '       g   R# V P                  RVP                  4      w  rVrxp	rrrW,
          ^,           pW,
          ^,           pVV3# )z0Returns the Windows terminal x and y dimensions.N)create_string_buffer)windlls   hhhhHhhhhhhi)	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                     \        \        P                  R,          4      \        \        P                  R,          4      3# )z=Returns the terminal x and y dimensions from the environment.COLUMNSLINES)intr   environ r9   r   r   r   u   s)    
bjj#
$c"**W*=&>	??r9   c                    ^ RI p \        P                  ! V P                  RR.V P                  R7      4      p\        V4      p\        P                  ! V P                  RR.V P                  R7      4      p\        V4      pW#3# )z5Returns the terminal x and y dimensions from tput(1).Ntputcols)stderrlines)
subprocessr   Decodecheck_outputSTDOUTr=   )rE   outputrB   rowss       r   r   r   z   s    ??:22FF3C:D:K:K 3 M N&	V$??:22FG3D:D:K:K 3 M N&	V$
r9       àc                 N    \         \        3 F  p  V ! 4       u # 	  R #     K  ; i)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                      R # Nr?   r?   r9   r   <lambda>#GetRawKeyFunction.<locals>.<lambda>   s    r9   )_GetRawKeyFunctionPosix_GetRawKeyFunctionWindows)get_raw_key_functions    r   GetRawKeyFunctionrX      s7      78:!##: 

s   $c                 (   aa ^ RI o^ RIoVV3R lp V # )z+_GetRawKeyFunction helper using Posix APIs.Nc                   <a RRRRRRRRR	R
RRRRRRRRRR
RR/p \         P                  P                  4        \         P                  P	                  4       oV3R lpSP                  S4      p SP                  S4       V! 4       pV\        8X  d   V! 4       p V\        8X  d    VSP                  SSP                  V4       # VP                  4       '       d   MTpV! 4       pVR8X  g   KT  Tp V P                  VR4      SP                  SSP                  V4       #  SP                  SSP                  T4       T\        \        39   d   R# T#    Rp L8; i  SP                  SSP                  T4       i ; i)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.
A
<UP-ARROW>B<DOWN-ARROW>D<LEFT-ARROW>C<RIGHT-ARROW>5	<PAGE-UP>6<PAGE-DOWN>H<HOME>F<END>MSTc                  Z   < \         P                  ! \        P                  ! S ^4      4      # )   )r   rF   r   read)r   s   r   _GetKeyCharE_GetRawKeyFunctionPosix.<locals>._GetRawKeyPosix.<locals>._GetKeyChar   s    __RWWR^,,r9   ~ N)sysstdoutflushstdinfileno	tcgetattrsetraw	_ANSI_CSI	tcsetattr	TCSADRAINisalphaget
_CONTROL_D
_CONTROL_Z)ansi_to_keyrq   old_settingscprev_cr   r   ttys        @r   _GetRawKeyPosix0_GetRawKeyFunctionPosix.<locals>._GetRawKeyPosix   sx    	\^^_[]XW^[]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--|<s0   /7E E E -E E EE E:)r   r   )r   r   r   s    @@r   rU   rU      s     38j 
r9   c                    a ^ RI oV3R lp V # )z-_GetRawKeyFunction helper using Windows APIs.Nc                    < RRRRRRRRR	R
RRRRRR/p \         P                  P                  4        V3R lpV! 4       pV\        \        39   d   V P                  V! 4       R4      # V\        \        39   d   R# T# )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.
rg   r\   Pr^   Kr`   rk   rb   Ird   Qrf   Grh   Orj   c                  L   < \         P                  ! S P                  4       4      # rR   )r   rF   getchmsvcrts   r   rq   I_GetRawKeyFunctionWindows.<locals>._GetRawKeyWindows.<locals>._GetKeyChar   s    __V\\^,,r9   rt   N)ru   rv   rw   _WINDOWS_CSI_1_WINDOWS_CSI_2r   r   r   )windows_to_keyrq   r   r   s      r   _GetRawKeyWindows4_GetRawKeyFunctionWindows.<locals>._GetRawKeyWindows   s     	\^^_[]XW	N JJ- 	A^^,,r22Z0047a7r9   r   )r   r   s    @r   rV   rV      s     8> 
r9   )__doc__
__future__r   r   r   r   ru   fire.consoler   r   r	   r
   r   r   r|   r   r   r   r   rX   rU   rV   r?   r9   r   <module>r      sb     1 &  ' 	 
 !0%P2@
	 	

"<~$r9   