+
    RioX                    2   ^ RI Ht ^ RIt]P                  R8X  g   Q h^ RIt^ RIHtHtHtH	t	H
t
HtHt ^ RIHtHt ^ RIHtHtHt ^ RIHt ^ RIHt ^ R	IHtHt ^ R
IHt ^ RIHtHtH t H!t!H"t" ^RI#H$t$ ^RI%H&t& ^RI'H(t( ]$'       g   ^ RIH)t) R.t*R R lt+Rt,Rt- ! R R].4      t/]! R4      t0 ! R R]&4      t1 ! R R4      t2 ! R R4      t3R R lt4]4! ]24      t5]4! ]34      t6]7! ]54      ]7! ]4      8X  g   Q h]7! ]64      ]7! ]4      8X  g   Q h ! R R 4      t8R# )!    )annotationsNwin32)ArgumentErrorbyrefc_charc_longc_uintc_ulongpointer)DWORDHANDLE)CallableTextIOTypeVar)CursorShape)Size)ANSI_COLOR_NAMESAttrs)
get_cwidth)CONSOLE_SCREEN_BUFFER_INFOCOORD
SMALL_RECTSTD_INPUT_HANDLESTD_OUTPUT_HANDLE)SPHINX_AUTODOC_RUNNING)Output)
ColorDepth)windllWin32Outputc                    V ^8  d   QhRRRR/# )   coordr   returnr    )formats   "Z/home/ubuntu/hermes-agent/venv/lib/python3.14/site-packages/prompt_toolkit/output/win32.py__annotate__r'   '   s     8 8 8& 8    c                j    \        V P                  R,          V P                  R,          ,          4      # )a%  
Turns a COORD object into a c_long.
This will cause it to be passed by value instead of by reference. (That is what I think at least.)

When running ``ptipython`` is run (only with IPython), we often got the following error::

     Error in 'SetConsoleCursorPosition'.
     ArgumentError("argument 2: <class 'TypeError'>: wrong type",)
 argument 2: <class 'TypeError'>: wrong type

It was solved by turning ``COORD`` parameters into a ``c_long`` like this.

More info: http://msdn.microsoft.com/en-us/library/windows/desktop/ms686025(v=vs.85).aspx
i   i  )r   YX)r"   s   &r&   _coord_byvalr,   '   s&     %''G#egg&6677r(   Fz!prompt-toolkit-windows-output.logc                  2   a  ] tR t^@tRtR V 3R lltRtV ;t# )NoConsoleScreenBufferErrorzu
Raised when the application is not running inside a Windows Console, but
the user tries to instantiate Win32Output.
c                   V ^8  d   QhRR/# r!   r#   Noner$   )r%   s   "r&   r'   'NoConsoleScreenBufferError.__annotate__F   s     " "$ "r(   c                	   < R \         P                  P                  RR4      9   pV'       d(   RP                  \         P                  R,          4      pMRp\        SV `  V4       R# )xtermTERM zFound {}, while expecting a Windows console. Maybe try to run this program using "winpty" or run it in cmd.exe instead. Or otherwise, in case of Cygwin, use the Python executable that is compiled for Cygwin.z2No Windows console found. Are you running cmd.exe?N)osenvirongetr%   super__init__)selfr4   message	__class__s   &  r&   r;   #NoConsoleScreenBufferError.__init__F   sS    2::>>&"55/ 06vbjj6H/I  KG!r(   r$   )__name__
__module____qualname____firstlineno____doc__r;   __static_attributes____classcell__)r>   s   @r&   r.   r.   @   s    
" "r(   r.   _Tc                     ] tR t^ZtRtRLR R lltR R ltR R ltR	 R
 ltR R lt	R R lt
R R ltR R ltR R ltR R ltR R ltR R ltR R ltR R ltR R  ltR! R" ltR# R$ ltR% R& ltRMR' R( lltR) R* ltR+ R, ltR- R. ltR/ R0 ltR1 R2 ltR3 R4 ltR5 R6 ltR7 R8 ltR9 R: lt R; R< lt!R= R> lt"R? R@ lt#RA RB lt$RC RD lt%RE RF lt&]'RG RH l4       t(RI RJ lt)RKt*R# )Nr   zK
I/O abstraction for rendering to Windows consoles.
(cmd.exe and similar.)
Nc               (    V ^8  d   QhRRRRRRRR/# )	r!   stdoutr   use_complete_widthbooldefault_color_depthzColorDepth | Noner#   r1   r$   )r%   s   "r&   r'   Win32Output.__annotate__`   s8     A AA !A /	A
 
Ar(   c                	p   W n         W0n        . V n        Wn        \	        \
        P                  P                  \        4      4      V n	        R V n
        R V n        \        4       V n        V P                  4       pV'       d   VP                  M^V n        \"        '       d   \%        \&        R4      V n        R# R# )FabN)rK   rM   _bufferrJ   r   r   kernel32GetStdHandler   hconsole_in_alternate_screen_hiddenColorLookupTablecolor_lookup_tableget_win32_screen_buffer_infowAttributesdefault_attrs_DEBUG_RENDER_OUTPUTopen_DEBUG_RENDER_OUTPUT_FILENAMELOG)r<   rJ   rK   rM   infos   &&&& r&   r;   Win32Output.__init__`   s     #5#6 "$$v;;<MNO$)!"2"4 00215T--294@DH  r(   c                   V ^8  d   QhRR/# r!   r#   intr$   )r%   s   "r&   r'   rN   y   s     $ $ $r(   c                6    V P                   P                  4       # )zReturn file descriptor.)rJ   filenor<   s   &r&   rf   Win32Output.filenoy   s    {{!!##r(   c                   V ^8  d   QhRR/# )r!   r#   strr$   )r%   s   "r&   r'   rN   }   s     $ $# $r(   c                .    V P                   P                  # )z Return encoding used for stdout.)rJ   encodingrg   s   &r&   rl   Win32Output.encoding}   s    {{###r(   c                    V ^8  d   QhRRRR/# r!   datarj   r#   r1   r$   )r%   s   "r&   r'   rN      s     " "# "$ "r(   c                	    V P                   '       d   R \        V4      ,          pV P                  P                  V4       R# ) N)rV   r   rQ   appendr<   rp   s   &&r&   writeWin32Output.write   s,    <<<D))DD!r(   c                    V ^8  d   QhRRRR/# ro   r$   )r%   s   "r&   r'   rN      s      c d r(   c                (    V P                  V4       R# )z>For win32, there is no difference between write and write_raw.N)ru   rt   s   &&r&   	write_rawWin32Output.write_raw   s    

4r(   c                   V ^8  d   QhRR/# )r!   r#   r   r$   )r%   s   "r&   r'   rN      s     0 0$ 0r(   c                	   V P                  4       pV P                  '       d   VP                  P                  pM1VP                  P
                  VP                  P                  ,
          pVP                  P                  VP                  P                  ,
          ^,           pVP                  P                  ^,
          p\        WB4      p\        W2R7      # )   )rowscolumns)rY   rK   dwSizer+   srWindowRightLeftBottomTopminr   )r<   r`   widthheightmaxwidths   &    r&   get_sizeWin32Output.get_size   s    002
 """KKMMEMM''$--*<*<<E%%(9(99A= ;;==1$H$ //r(   c               (    V ^8  d   QhRRRRRRRR/# )r!   funczCallable[..., _T]aobjectkwr#   rG   r$   )r%   s   "r&   r'   rN      s)      - 6  B r(   c                @   V P                  4        \        '       Ed   V P                  P                  VP                  : P                  4       R,           4       V P                  P                  RRP                  V Uu. uF  qD: NK  	  up4      P                  R4      ,           R,           4       V P                  P                  RRP                  V Uu. uF  p\        V4      : NK  	  up4      P                  R4      ,           R,           4       V P                  P                  4         V! V/ VB # u upi u upi   \         dR   p\        '       d@   T P                  P                  RTP                  : RT: RT R2P                  4       4       h Rp?ii ; i)	z"
Flush and call win API function.
   
s        z, zutf-8z    Error in rr   
N)	flushr\   r_   ru   r@   encodejointyper   )r<   r   r   r   ies   &&*,  r&   _winapiWin32Output._winapi   sF    	

HHNNt}}/88:UBCHHNN499%:1h%:;BB7KKeS HHNN))Q7QQ{^Q78??HI
 HHNN	>b>! &; 8  	##-/@!as" MUUWX		s%   ?D7D</E FAFFc                   V ^8  d   QhRR/# )r!   r#   r   r$   )r%   s   "r&   r'   rN      s     "- "-.H "-r(   c                    V P                  4        \        4       p\        P                  P	                  V P
                  \        V4      4      pV'       d   V# \        h)z
Return Screen buffer info.
)r   r   r   rR   GetConsoleScreenBufferInforT   r   r.   )r<   sbinfosuccesss   &  r&   rY   (Win32Output.get_win32_screen_buffer_info   sF    , 	

+-//<<MM5=
 M,,r(   c                    V ^8  d   QhRRRR/# )r!   titlerj   r#   r1   r$   )r%   s   "r&   r'   rN      s     > >s >t >r(   c                Z    V P                  \        P                  P                  V4       R# )z
Set terminal title.
Nr   r   rR   SetConsoleTitleW)r<   r   s   &&r&   	set_titleWin32Output.set_title   s     	V__55u=r(   c                   V ^8  d   QhRR/# r0   r$   )r%   s   "r&   r'   rN      s     ; ;T ;r(   c                	Z    V P                  \        P                  P                  R 4       R# r6   Nr   rg   s   &r&   clear_titleWin32Output.clear_title   s    V__55r:r(   c                   V ^8  d   QhRR/# r0   r$   )r%   s   "r&   r'   rN      s     # #d #r(   c                	    \        ^ ^ 4      pV P                  4       pVP                  P                  VP                  P                  ,          pV P                  ^ ^ R7       V P                  W4       R# )r   )rowcolumnN)r   rY   r   r+   r*   cursor_goto_erase)r<   startr   lengths   &   r&   erase_screenWin32Output.erase_screen   sT    a2246==??2Qq)E"r(   c                   V ^8  d   QhRR/# r0   r$   )r%   s   "r&   r'   rN      s     # #D #r(   c                	,   V P                  4       pVP                  pVP                  pVP                  VP                  ,
          VP                  VP                  VP                  P                  ,
          ,          ,           pV P                  W44       R # N)rY   r   dwCursorPositionr+   r*   r   )r<   r   sizer   r   s   &    r&   
erase_downWin32Output.erase_down   sd    224}}''&&466/TVVtvv8O8O8Q8Q/Q%RRE"r(   c                   V ^8  d   QhRR/# r0   r$   )r%   s   "r&   r'   rN      s     # #4 #r(   c                    V P                  4       pVP                  pVP                  P                  VP                  P                  ,
          pV P	                  W#4       R# r   )rY   r   r   r+   r   )r<   r   r   r   s   &   r&   erase_end_of_lineWin32Output.erase_end_of_line   sE    224''6#:#:#<#<<E"r(   c               $    V ^8  d   QhRRRRRR/# )r!   r   r   r   rd   r#   r1   r$   )r%   s   "r&   r'   rN      s!     
 
E 
3 
4 
r(   c           
     	   \        4       pV P                  \        P                  P                  V P
                  \        R 4      \        V4      \        V4      \        V4      4       V P                  4       pV P                  \        P                  P                  V P
                  VP                  V\        V4      \        V4      4       R# )    N)r
   r   r   rR   FillConsoleOutputCharacterArT   r   r   r,   r   rY   FillConsoleOutputAttributerZ   )r<   r   r   chars_writtenr   s   &&&  r&   r   Win32Output._erase   s    	OO77MM4L&M- 	
 224OO66MM- 	
r(   c                   V ^8  d   QhRR/# r0   r$   )r%   s   "r&   r'   rN     s      $ r(   c                    V P                  \        P                  P                  V P                  V P
                  4       RV n        R# )z.Reset the console foreground/background color.FN)r   r   rR   SetConsoleTextAttributerT   r[   rV   rg   s   &r&   reset_attributesWin32Output.reset_attributes  s2    OO33T]]DDVDV	
 r(   c               $    V ^8  d   QhRRRRRR/# )r!   attrsr   color_depthr   r#   r1   r$   )r%   s   "r&   r'   rN     s&     %X %XE %X
 %Xt %Xr(   c           
     	*   Vw
  ppppppp	p
pp\        V4      V n        V P                  pV\        P                  8w  de   V'       d+   VR,          pWP
                  P                  V4      ,          pV'       d+   VR,          pWP
                  P                  V4      ,          pV
'       d4   VR,          V^,          ^,          ,          V^,          ^,	          ,          pV P                  \        P                  P                  V P                  V4       R# )   Niii )rL   rV   r[   r   DEPTH_1_BITrX   lookup_fg_colorlookup_bg_colorr   r   rR   r   rT   )r<   r   r   fgcolorbgcolorbold	underlinestrikeitalicblinkreversehiddendim	win_attrss   &&&           r&   set_attributesWin32Output.set_attributes  s     	
F| ++	*000%,	44DDWMM	 %-	44DDWMM	 U"O)+$*,  	V__<<dmmYWr(   c                   V ^8  d   QhRR/# r0   r$   )r%   s   "r&   r'   rN   D  s      $ r(   c                	    R # r   r$   rg   s   &r&   disable_autowrapWin32Output.disable_autowrapD      r(   c                   V ^8  d   QhRR/# r0   r$   )r%   s   "r&   r'   rN   H  s       r(   c                	    R # r   r$   rg   s   &r&   enable_autowrapWin32Output.enable_autowrapH  r   r(   c               $    V ^8  d   QhRRRRRR/# )r!   r   rd   r   r#   r1   r$   )r%   s   "r&   r'   rN   L  s!     
 
s 
 
D 
r(   c                	    \        W!R 7      pV P                  \        P                  P                  V P
                  \        V4      4       R# r+   r*   N)r   r   r   rR   SetConsoleCursorPositionrT   r,   )r<   r   r   poss   &&& r&   r   Win32Output.cursor_gotoL  s3    f$OO44dmm\RUEV	
r(   c                    V ^8  d   QhRRRR/# r!   amountrd   r#   r1   r$   )r%   s   "r&   r'   rN   R  s     
 
 
 
r(   c                	   V P                  4       P                  p\        VP                  VP                  V,
          R 7      pV P                  \        P                  P                  V P                  \        V4      4       R# r   )rY   r   r   r+   r*   r   r   rR   r   rT   r,   r<   r   srr   s   &&  r&   	cursor_upWin32Output.cursor_upR  sU    ..0AAbddbddVm,OO44dmm\RUEV	
r(   c                    V ^8  d   QhRRRR/# r   r$   )r%   s   "r&   r'   rN   Y  s        #  $  r(   c                	*    V P                  V) 4       R # r   )r   r<   r   s   &&r&   cursor_downWin32Output.cursor_downY  s    wr(   c                    V ^8  d   QhRRRR/# r   r$   )r%   s   "r&   r'   rN   \  s     
 
S 
T 
r(   c                	   V P                  4       P                  p\        \        ^ VP                  V,           4      VP
                  R7      pV P                  \        P                  P                  V P                  \        V4      4       R# )r   r   N)rY   r   r   maxr+   r*   r   r   rR   r   rT   r,   r   s   &&  r&   cursor_forwardWin32Output.cursor_forward\  s^    ..0AA c!RTTF]+rtt4OO44dmm\RUEV	
r(   c                    V ^8  d   QhRRRR/# r   r$   )r%   s   "r&   r'   rN   e  s     % %c %d %r(   c                	*    V P                  V) 4       R # r   )r  r   s   &&r&   cursor_backwardWin32Output.cursor_backwarde  s    VG$r(   c                   V ^8  d   QhRR/# r0   r$   )r%   s   "r&   r'   rN   h  s      t r(   c           	        V P                   '       g   V P                  P                  4        R# RP                  V P                   4      p\        '       dM   V P
                  P                  V: P                  4       R,           4       V P
                  P                  4        V FL  p\        4       p\        P                  P                  V P                  V^\        V4      R4      pV^ 8w  d   KL  Q h	  . V n         R# )z#
Write to output stream and flush.
Nr6   r   )rQ   rJ   r   r   r\   r_   ru   r   r   r   rR   WriteConsoleWrT   r   )r<   rp   bwrittenretvals   &    r&   r   Win32Output.flushh  s     ||| KKwwt||$HHNNth//1E9:HHNN
 AgG__22q!U7^TF Q;;  r(   c                   V ^8  d   QhRR/# rc   r$   )r%   s   "r&   r'   rN     s     B B Br(   c                	    V P                  4       pVP                  P                  VP                  P                  ,
          ^,           # )r}   )rY   r   r   r   r*   )r<   r`   s   & r&   get_rows_below_cursor_position*Win32Output.get_rows_below_cursor_position  s6    002}}##d&;&;&=&==AAr(   c                   V ^8  d   QhRR/# r0   r$   )r%   s   "r&   r'   rN     s     
 
 
r(   c                d   V P                  4       pVP                  pVP                  p\        4       p^ Vn        VP
                  VP                  ,
          Vn        VP                  VP                  ,
          p^ VP                  VP                  ,
          u;8  d   V^,
          8  d   M MVP                  Vn        M\        WSP                  4      Vn        VP                  V,
          Vn        V P                  \        P                  P                  V P                  R\        V4      4       R# )z~
To be called before drawing the prompt. This should scroll the console
to left, with the cursor at the bottom (if possible).
TN)rY   r   r   r   r   r   r   r   r*   r  r   r   rR   SetConsoleWindowInforT   r   )r<   r`   r   
cursor_posresult
win_heights   &     r&   scroll_buffer_to_prompt#Win32Output.scroll_buffer_to_prompt  s     002]]**
 xx"'') YY'
ryy:<<'8*q.8IIFM
LL9FM]]Z/
 	OO00$--uV}	
r(   c                   V ^8  d   QhRR/# r0   r$   )r%   s   "r&   r'   rN     s     - - -r(   c                B   V P                   '       g   RpRp\        V P                  \        P                  P
                  W,          \        ^ 4      R\        ^4      R4      4      pV P                  \        P                  P                  V4       W0n        RV n         R# R# )z 
Go to alternate screen buffer.
l        i   @NT)	rU   r   r   r   rR   CreateConsoleScreenBufferr   SetConsoleActiveScreenBufferrT   )r<   GENERIC_READGENERIC_WRITEhandles   &   r&   enter_alternate_screen"Win32Output.enter_alternate_screen  s     (((%L&M OO== 0!H!H	F LLEEvN"M(,D%% )r(   c                   V ^8  d   QhRR/# r0   r$   )r%   s   "r&   r'   rN     s     . .t .r(   c                r   V P                   '       d   \        V P                  \        P                  P
                  \        4      4      pV P                  \        P                  P                  V4       V P                  \        P                  P                  V P                  4       Wn	        RV n         R# R# )z&
Make stdout again the active buffer.
FN)
rU   r   r   r   rR   rS   r   r   CloseHandlerT   )r<   rJ   s   & r&   quit_alternate_screen!Win32Output.quit_alternate_screen  s{     $$$V__99;LMF LLEEvNLL44dmmD"M(-D% %r(   c                   V ^8  d   QhRR/# r0   r$   )r%   s   "r&   r'   rN     s     
 
d 
r(   c                	j   ^p^@p\        \        P                  P                  \        4      4      p\        4       pV P                  \        P                  P                  V\        V4      4       V P                  \        P                  P                  VVP                  V,          V( ,          4       R#    Nr   r   rR   rS   r   r   r   GetConsoleModer   SetConsoleModevalue)r<   ENABLE_MOUSE_INPUTENABLE_QUICK_EDIT_MODEr#  original_modes   &    r&   enable_mouse_support Win32Output.enable_mouse_support  s    !
 "(445EFGV__33VW]=STOO**  #55:P9PP	
r(   c                   V ^8  d   QhRR/# r0   r$   )r%   s   "r&   r'   rN     s     

 

t 

r(   c                	X   ^p\        \        P                  P                  \        4      4      p\        4       pV P                  \        P                  P                  V\        V4      4       V P                  \        P                  P                  VVP                  V( ,          4       R# r-  r/  )r<   r3  r#  r5  s   &   r&   disable_mouse_support!Win32Output.disable_mouse_support  sv    !445EFGV__33VW]=STOO**#5"55	
r(   c                   V ^8  d   QhRR/# r0   r$   )r%   s   "r&   r'   rN           T r(   c                	    R # r   r$   rg   s   &r&   hide_cursorWin32Output.hide_cursor      r(   c                   V ^8  d   QhRR/# r0   r$   )r%   s   "r&   r'   rN     r=  r(   c                	    R # r   r$   rg   s   &r&   show_cursorWin32Output.show_cursor  rA  r(   c                    V ^8  d   QhRRRR/# )r!   cursor_shaper   r#   r1   r$   )r%   s   "r&   r'   rN     s      [ T r(   c                	    R # r   r$   )r<   rG  s   &&r&   set_cursor_shapeWin32Output.set_cursor_shape  rA  r(   c                   V ^8  d   QhRR/# r0   r$   )r%   s   "r&   r'   rN     s      D r(   c                	    R # r   r$   rg   s   &r&   reset_cursor_shapeWin32Output.reset_cursor_shape  rA  r(   c                   V ^8  d   QhRR/# r0   r$   )r%   s   "r&   r'   rN     s     O OT Or(   c                    \        \        P                  P                  4       4      p^p\        P                  P                  VRR\        V4      4       R# )z
Call win32 API to refresh the whole Window.

This is sometimes necessary when the application paints background
for completion menus. When the menu disappears, it leaves traces due
to a bug in the Windows Console. Sending a repaint request solves it.
N)r   r   rR   GetConsoleWindowuser32RedrawWindowr	   )clsr#  RDW_INVALIDATEs   &  r&   win32_refresh_window Win32Output.win32_refresh_window  s=     88:;""64vn7MNr(   c                   V ^8  d   QhRR/# )r!   r#   r   r$   )r%   s   "r&   r'   rN     s     
& 
& 
&r(   c                V    V P                   e   V P                   # \        P                  # )z
Return the default color depth for a windows terminal.

Contrary to the Vt100 implementation, this doesn't depend on a $TERM
variable.
)rM   r   DEPTH_4_BITrg   s   &r&   get_default_color_depth#Win32Output.get_default_color_depth  s(     ##/+++%%%r(   )
r_   rQ   rV   rU   rX   r[   rM   rT   rJ   rK   )FN)r   r   )+r@   rA   rB   rC   rD   r;   rf   rl   ru   ry   r   r   rY   r   r   r   r   r   r   r   r   r   r   r   r   r   r  r  r   r  r  r$  r)  r6  r:  r?  rD  rI  rM  classmethodrV  r[  rE   r$   r(   r&   r   r   Z   s    
A2$$"0(4"-H>;###
.%XN

 
%<B
<-0.
$

 O O
& 
&r(   c                  :    ] tR tRt^ t^t^t^t^t^t	^t
^t^tRtR# )FOREGROUND_COLORi  r$   Nr@   rA   rB   rC   BLACKBLUEGREENCYANREDMAGENTAYELLOWGRAY	INTENSITYrE   r$   r(   r&   r_  r_    /    EDED
CGFDIr(   r_  c                  :    ] tR tRt^ t^t^ t^0t^@t^Pt	^`t
^pt^tRtR# )BACKGROUND_COLORi  r$   Nr`  r$   r(   r&   rl  rl    rj  r(   rl  c                    V ^8  d   QhRRRR/# )r!   	color_clsz/type[FOREGROUND_COLOR] | type[BACKGROUND_COLOR]r#   zdict[str, int]r$   )r%   s   "r&   r'   r'   +  s      >r(   c                   / RV P                   bRV P                   bRV P                  bRV P                   V P                  ,          bRV P                  V P                  ,          bRV P                  bRV P                  bRV P
                  bR	V P                  bR
V P                  bRV P                  bRV P                  V P                  ,          bRV P                  V P                  ,          bRV P
                  V P                  ,          bRV P                  V P                  ,          bRV P                  V P                  ,          bRV P                  V P                  ,          b# )zHCreate a table that maps the 16 named ansi colors to their Windows code.ansidefault	ansiblackansigrayansibrightblack	ansiwhiteansired	ansigreen
ansiyellowansiblueansimagentaansicyanansibrightredansibrightgreenansibrightyellowansibrightblueansibrightmagentaansibrightcyan)	ra  rh  ri  re  rc  rg  rb  rf  rd  )rn  s   &r&   _create_ansi_color_dictr  +  sx   yY__ 	INN 	9??Y-@-@@	
 	Y^^i&9&99 	9== 	Y__ 	i&& 	INN 	y(( 	INN 	)<)<< 	9??Y-@-@@  	I,,y/B/BB!" 	)..9+>+>>#$ 	Y..1D1DD%& 	)..9+>+>>' r(   c                  l    ] tR tRtRt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tR# )rW   iM  z0
Inspired by pygments/formatters/terminal256.py
c                   V ^8  d   QhRR/# r0   r$   )r%   s   "r&   r'   ColorLookupTable.__annotate__R  s     9 9$ 9r(   c                	>    V P                  4       V n        / V n        R # r   )_build_color_table_win32_colors
best_matchrg   s   &r&   r;   ColorLookupTable.__init__R  s    !446 79r(   c                   V ^8  d   QhRR/# )r!   r#   z$list[tuple[int, int, int, int, int]]r$   )r%   s   "r&   r'   r  Y  s     
 
 D 
r(   c                 ~   \         p \        p^ ^ ^ V P                  VP                  3^ ^ ^V P                  VP                  3^ ^^ V P                  VP                  3^ ^^V P
                  VP
                  3^^ ^ V P                  VP                  3^^ ^V P                  VP                  3^^^ V P                  VP                  3^^^V P                  VP                  3^D^D^V P                  V P                  ,          VP                  VP                  ,          3^D^^DV P                  V P                  ,          VP                  VP                  ,          3^D^^V P
                  V P                  ,          VP
                  VP                  ,          3^^D^DV P                  V P                  ,          VP                  VP                  ,          3^^D^V P                  V P                  ,          VP                  VP                  ,          3^^^DV P                  V P                  ,          VP                  VP                  ,          3^D^D^DV P                  V P                  ,          VP                  VP                  ,          3^^^V P                  V P                  ,          VP                  VP                  ,          3.# )z,
Build an RGB-to-256 color conversion table
)r_  rl  ra  rb  rc  rd  re  rf  rg  rh  ri  )FGBGs     r&   r  #ColorLookupTable._build_color_tableX  s
   
  4rxx24rww04rxx24rww04rvvrvv.4rzz2::64ryy"))44rww04rww5rww7MN4rxx",,62<<8OP4rww5rww7MN4rvv4bffr||6KL4rzzBLL8"**r||:ST4ryy2<<7R\\9QR4rxx",,62<<8OP4rww5rww7MN!
 	
r(   c               (    V ^8  d   QhRRRRRRRR/# )r!   rrd   gr  r#   tuple[int, int]r$   )r%   s   "r&   r'   r  s  s(     " " " " " "r(   c                	    Rp^ p^ pV P                    FO  w  rxrpW,
          pW(,
          pW9,
          pW,          W,          ,           W,          ,           pW8  g   KI  T
pTpTpKQ  	  WV3# )i  i )r  )r<   r  r  r  distancefg_matchbg_matchr_g_b_fg_bg_rdgdbdds   &&&&            r&   _closest_colorColorLookupTable._closest_colors  sq     $($6$6 BBSBBB"'!BG+A| %7 !!r(   c                    V ^8  d   QhRRRR/# )r!   colorrj   r#   r  r$   )r%   s   "r&   r'   r    s      C O r(   c                	*   V P                   P                  VR 4      pVf`    \        \        V4      ^4      pV^,	          ^,          pV^,	          ^,          pV^,          pV P                  WEV4      pW P                   V&   V#   \         d    ^ p LZi ; ir   )r  r9   rd   rj   
ValueErrorr  )r<   r  indexesrgbr  r  r  s   &&     r&   _color_indexesColorLookupTable._color_indexes  s    //%%eT2?#e*b) d"AT!Ad
A))!2G%,OOE"  s   B BBc                    V ^8  d   QhRRRR/# )r!   fg_colorrj   r#   rd   r$   )r%   s   "r&   r'   r         4 4 4 4r(   c                b    V\         9   d   \         V,          # V P                  V4      ^ ,          # )z
Return the color for use in the
`windll.kernel32.SetConsoleTextAttribute` API call.

:param fg_color: Foreground as text. E.g. 'ffffff' or 'red'
)FG_ANSI_COLORSr  )r<   r  s   &&r&   r    ColorLookupTable.lookup_fg_color  -     ~%!(++&&x033r(   c                    V ^8  d   QhRRRR/# )r!   bg_colorrj   r#   rd   r$   )r%   s   "r&   r'   r    r  r(   c                b    V\         9   d   \         V,          # V P                  V4      ^,          # )z
Return the color for use in the
`windll.kernel32.SetConsoleTextAttribute` API call.

:param bg_color: Background as text. E.g. 'ffffff' or 'red'
)BG_ANSI_COLORSr  )r<   r  s   &&r&   r    ColorLookupTable.lookup_bg_color  r  r(   )r  r  N)r@   rA   rB   rC   rD   r;   staticmethodr  r  r  r   r   rE   r$   r(   r&   rW   rW   M  s9    9 
 
4"$44 4r(   rW   )9
__future__r   sysplatformr7   ctypesr   r   r   r   r	   r
   r   ctypes.wintypesr   r   typingr   r   r   prompt_toolkit.cursor_shapesr   prompt_toolkit.data_structuresr   prompt_toolkit.stylesr   r   prompt_toolkit.utilsr   prompt_toolkit.win32_typesr   r   r   r   r   utilsr   baser   r   r   r   __all__r,   r\   r^   	Exceptionr.   rG   r   r_  rl  r  r  r  setrW   r$   r(   r&   <module>r     s   " 

||w  	 Q Q Q ) , , 4 / 9 +  +  #  
8*   D " ". T]v&& v&r	 		 	6 ))9:()9:
>c"233 33
>c"233 33_4 _4r(   