)L ioXddlmZddlZejdk(sJddlZddlmZmZmZm Z m Z m Z m Z ddl mZmZddlmZmZmZddlmZddlmZdd lmZmZdd lmZdd lmZmZm Z m!Z!m"Z"d d l#m$Z$ddl%m&Z&ddl'm(Z(e$sddlm)Z)dgZ*d!dZ+dZ,dZ-Gdde.Z/edZ0Gdde&Z1GddZ2GddZ3 d"dZ4e4e2Z5e4e3Z6e7e5e7ek(sJe7e6e7ek(sJGdd Z8y)#) annotationsNwin32) ArgumentErrorbyrefc_charc_longc_uintc_ulongpointer)DWORDHANDLE)CallableTextIOTypeVar) CursorShape)Size)ANSI_COLOR_NAMESAttrs) get_cwidth)CONSOLE_SCREEN_BUFFER_INFOCOORD SMALL_RECTSTD_INPUT_HANDLESTD_OUTPUT_HANDLE)SPHINX_AUTODOC_RUNNING)Output) ColorDepth)windll Win32OutputcRt|jdz|jdzzS)aI 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: : wrong type",) argument 2: : 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 ii)rYX)coords a/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/prompt_toolkit/output/win32.py _coord_byvalr''s& %''G#egg&66 77Fz!prompt-toolkit-windows-output.logc$eZdZdZdfd ZxZS)NoConsoleScreenBufferErrorz Raised when the application is not running inside a Windows Console, but the user tries to instantiate Win32Output. cdtjjddv}|r#djtjd}nd}t||y)NxtermTERMzFound {}, 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?)osenvirongetformatsuper__init__)selfr,message __class__s r&r4z#NoConsoleScreenBufferError.__init__FsS2::>>&"55 /06vbjj6H/I KG !r(returnNone)__name__ __module__ __qualname____doc__r4 __classcell__)r7s@r&r*r*@s ""r(r*_TcPeZdZdZ d' d(dZd)dZd*dZd+dZd+dZd,dZ d-d Z d.d Z d/d Z d0d Z d0d Zd0dZd0dZd1dZd0dZd2dZd0dZd0dZd3d4dZd5dZd5dZd5dZd5dZd0dZd)dZd0dZd0dZd0dZd0dZ d0d Z!d0d!Z"d0d"Z#d6d#Z$d0d$Z%e&d0d%Z'd7d&Z(y)8r!zW I/O abstraction for rendering to Windows consoles. (cmd.exe and similar.) NcZ||_||_g|_||_t t j jt|_ d|_ d|_ t|_ |j}|r |jnd|_t"rt%t&d|_yy)NFab)use_complete_widthdefault_color_depth_bufferstdoutr r kernel32 GetStdHandlerhconsole_in_alternate_screen_hiddenColorLookupTablecolor_lookup_tableget_win32_screen_buffer_info wAttributes default_attrs_DEBUG_RENDER_OUTPUTopen_DEBUG_RENDER_OUTPUT_FILENAMELOG)r5rHrErFinfos r&r4zWin32Output.__init__`s #5#6 "$ $ v;;For win32, there is no difference between write and write_raw.N)rbr`s r& write_rawzWin32Output.write_raws 4r(c|j}|jr|jj}n-|jj |jj z }|jj|jjz dz}|jjdz }t||}t||S)Nr)rowscolumns) rPrEdwSizer$srWindowRightLeftBottomTopminr)r5rWwidthheightmaxwidths r&get_sizezWin32Output.get_sizes002  " "KKMMEMM''$--*<*<b> !&;8 #- /@!as" MUUWX   s%3 DDD E2)AE--E2c|jt}tjj |j t |}|r|St)z, Return Screen buffer info. )rvrr rIGetConsoleScreenBufferInforKrr*)r5sbinfosuccesss r&rPz(Win32Output.get_win32_screen_buffer_infosF, +-//<< MM5=  M, ,r(cX|jtjj|y)z% Set terminal title. Nrr rISetConsoleTitleW)r5titles r& set_titlezWin32Output.set_titles V__55u=r(cX|jtjjdy)Nr.rrZs r& clear_titlezWin32Output.clear_titles V__55r:r(ctdd}|j}|jj|jjz}|j dd|j ||y)Nr)rowcolumn)rrPrhr$r# cursor_goto_erase)r5startrlengths r& erase_screenzWin32Output.erase_screensVa 2246==??2 Qq) E6"r(c |j}|j}|j}|j|jz |j|j|jjz zz}|j ||yN)rPrhdwCursorPositionr$r#r)r5rsizerrs r& erase_downzWin32Output.erase_downsf224}}''&&466/TVVtvv8O8O8Q8Q/Q%RR E6"r(c|j}|j}|jj|jjz }|j ||y)r.N)rPrrhr$r)r5rrrs r&erase_end_of_linezWin32Output.erase_end_of_linesG224''6#:#:#<#<< E6"r(c t}|jtjj|j t dt|t|t||j}|jtjj|j |j|t|t|y)N ) r rr rIFillConsoleOutputCharacterArKrr r'rrPFillConsoleOutputAttributerQ)r5rr chars_writtenrs r&rzWin32Output._erases  OO 7 7 MM 4L &M   -  224 OO 6 6 MM       -  r(c|jtjj|j|j d|_y)z.Reset the console foreground/background color.FN)rr rISetConsoleTextAttributerKrRrMrZs r&reset_attributeszWin32Output.reset_attributess2 OO 3 3T]]DDVDV  r(c |\ }}}}}}} } } } t| |_|j} |tjk7rJ|r#| dz} | |j j |z} |r#| dz} | |j j|z} | r| dz| dzdzz| dzdz z} |jtjj|j| y)NiiirC) boolrMrRr DEPTH_1_BITrOlookup_fg_colorlookup_bg_colorrr rIrrK)r5attrs color_depthfgcolorbgcolorbold underlinestrikeitalicblinkreversehiddendim win_attrss r&set_attributeszWin32Output.set_attributess           F| ++ *00 0%, T44DDWMM %- T44DDWMM  U"O)+$*,  V__<r4rYr\rbrdrrrrPrrrrrrrrrrrrrrrrvrrrrrrrrrr classmethodrrrr(r&r!r!Zs$)15 AA!A/ A  A2$$" 0(4"-H> ;### .%XN      %<B <-0 . $       O O &r(c0eZdZdZdZdZdZdZdZdZ dZ d Z y ) FOREGROUND_COLORrrrrN r;r<r=BLACKBLUEGREENCYANREDMAGENTAYELLOWGRAY INTENSITYrr(r&r r / E D E D CG F DIr(r c0eZdZdZdZdZdZdZdZdZ dZ d Z y ) BACKGROUND_COLORrr 0rP`pNrrr(r&rrrr(rcid|jd|jd|jd|j|jzd|j|jzd|jd|jd|j d |j d |jd |jd |j|jzd |j|jzd|j |jzd|j |jzd|j|jzd|j|jzS)zHCreate a table that maps the 16 named ansi colors to their Windows code. ansidefault ansiblackansigrayansibrightblack ansiwhiteansired ansigreen ansiyellowansiblue ansimagentaansicyan ansibrightredansibrightgreenansibrightyellowansibrightblueansibrightmagentaansibrightcyan) rrrrrrrrr) color_clss r&_create_ansi_color_dictr8+sx y Y__  INN  9??Y-@-@@   Y^^i&9&99   9==  Y__  i&&  INN  y((  INN  )<)<<  9??Y-@-@@  I,,y/B/BB! " )..9+>+>># $ Y..1D1DD% & )..9+>+>>' r(cJeZdZdZd dZed dZd dZd dZd dZ ddZ y)rNz8 Inspired by pygments/formatters/terminal256.py c<|j|_i|_yr)_build_color_table _win32_colors best_matchrZs r&r4zColorLookupTable.__init__Rs!44679r(ct}t}ddd|j|jfddd|j|jfddd|j|jfddd|j |j fddd|j |j fddd|j|jfddd|j|jfddd|j|jfddd|j|jz|j|jzfddd|j|jz|j|jzfddd|j |jz|j |jzfddd|j |jz|j |jzfddd|j|jz|j|jzfddd|j|jz|j|jzfddd|j|jz|j|jzfddd|j|jz|j|jzfgS)z< Build an RGB-to-256 color conversion table rD) r rrrrrrrrrr)FGBGs r&r;z#ColorLookupTable._build_color_tableXs   4rxx 2 4rww 0 4rxx 2 4rww 0 4rvvrvv . 4rzz2:: 6 4ryy")) 4 4rww 0 4rww5rww7M N 4rxx",,62<<8O P 4rww5rww7M N 4rvv 4bffr||6K L 4rzzBLL8"**r||:S T 4ryy2<<7R\\9Q R 4rxx",,62<<8O P 4rww5rww7M N!  r(cd}d}d}|jD]4\}}} } } ||z } ||z } || z }| | z| | zz||zz}||ks/| }| }|}6||fS)Nir)r<)r5rgrdistancefg_matchbg_matchr_g_b_fg_bg_rdgdbdds r&_closest_colorzColorLookupTable._closest_colorss $($6$6  BBSRBRBRBR"r'!BG+A8| !!r(c|jj|d}|M tt|d}|dz dz}|dz dz}|dz}|j |||}||j|<|S#t$rd}YFwxYw)NrrrBr)r=r1rr ValueErrorrT)r5colorindexesrgbrFrGrs r&_color_indexeszColorLookupTable._color_indexess//%%eT2 ? #e*b)d"AT!Ad A))!Q2G%,DOOE "  sA.. A<;A<cL|tvr t|S|j|dS)z Return the color for use in the `windll.kernel32.SetConsoleTextAttribute` API call. :param fg_color: Foreground as text. E.g. 'ffffff' or 'red' r)FG_ANSI_COLORSrZ)r5fg_colors r&rz ColorLookupTable.lookup_fg_color- ~ %!(+ +&&x03 3r(cL|tvr t|S|j|dS)z Return the color for use in the `windll.kernel32.SetConsoleTextAttribute` API call. :param bg_color: Background as text. E.g. 'ffffff' or 'red' r)BG_ANSI_COLORSrZ)r5bg_colors r&rz ColorLookupTable.lookup_bg_colorr^r(Nr8)r9z$list[tuple[int, int, int, int, int]])rFrrGrrrr9tuple[int, int])rWrr9rb)r]rr9r)rarr9r) r;r<r=r>r4 staticmethodr;rTrZrrrr(r&rNrNMs49   4"$  4 4r(rN)r%rr9r)r7z/type[FOREGROUND_COLOR] | type[BACKGROUND_COLOR]r9zdict[str, int])9 __future__rsysplatformr/ctypesrrrrr r r ctypes.wintypesr r typingrrrprompt_toolkit.cursor_shapesrprompt_toolkit.data_structuresrprompt_toolkit.stylesrrprompt_toolkit.utilsrprompt_toolkit.win32_typesrrrrrutilsrbaserrrr __all__r'rSrU Exceptionr*r@r!r rr8r\r`setrNrr(r&rts"  ||w QQQ),,4/9++#  8* D"". T]v&&v&r    >6))9:()9: >c"23333 >c"23333_4_4r(