)L i[ &dZddlmZddlZddlZddlZddlmZmZm Z m Z m Z m Z m Z ddlmZddlmZddlmZddlmZmZdd lmZd d lmZd d lmZd gZiddddddddddddddddddd d!d"d#d$d%d&d'd(d)d*d+d,d-d.d/Zidd0dd1dd2dd3dd4dd5dd6dd7dd8d d9d"d:d$d;d&d<d(d=d*d>d,d?d.d@ZiddAddAddBd dCd.dDddEddFddGddHddIddJd"dKd$dLd&dMd(dNd*dOd,dPZe ee ek(sJe ee ek(sJe ee ek(sJd]d^dQZ!e e"e#fZ$GdRdSZ%GdTdUee e"e"e"fe"fZ&e%dVWZ'e%dXWZ(e&Z)GdYdZeee#fZ*d_d[Z+Gd\d eZ,y)`z Output for vt100 terminals. A lot of thanks, regarding outputting of colors, goes to the Pygments project: (We don't rely on Pygments anymore, because many things are very custom, and everything has been highly optimized.) http://pygments.org/ ) annotationsN)CallableDictHashableIterableSequenceTextIOTuple) CursorShape)Size)Output)ANSI_COLOR_NAMESAttrs)is_dumb_terminal) ColorDepth) flush_stdout Vt100_Output ansidefault' ansiblackansired ansigreen ansiyellow!ansiblue" ansimagenta#ansicyan$ansigray%ansibrightblackZ ansibrightred[ansibrightgreen\ansibrightyellow]ansibrightblue^ansibrightmagenta_ansibrightcyan` ansiwhitea1()*+,-./defghijkrrrrJrJrLrLrNrNrrrrPrrPrPr)rrrPrPrrPrrPrPrNrrrrNrrNrNr)rrrNrNrrNrrNrNcJt|}t||z t||z zt||z z}|dkDr|jgdd}d}tj D]8\}\}} } |dk7s||vs||z dz|| z dzz|| z dzz} | |ks5|}| }:|S)z Find closest ANSI color. Return it by name. :param r: Red (Between 0 and 255.) :param g: Green (Between 0 and 255.) :param b: Blue (Between 0 and 255.) :param exclude: A tuple of color names to exclude. (E.g. ``('ansired', )``.) r) ansilightgray ansidarkgrayr5rr)listabsextendANSI_COLORS_TO_RGBitems) rgbexclude saturationdistancematchnamer2g2b2ds a/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/prompt_toolkit/output/vt100.py_get_closest_ansi_colorrqls7mGQUc!a%j(3q1u:5JBRSH E0668lr2r = T%8RA RA -RA =A8|  LcFeZdZdZdddZ d d dZ d d dZy) _16ColorCachez Cache which maps (r, g, b) tuples to 16 ansi colors. :param bg: Cache for background colors, instead of foreground. c ||_i|_yN)bg_cache)selfrws rp__init__z_16ColorCache.__init__s9; rrcp|t|f}|j}||vr|j||||<||S)zx Return a (ansi_code, ansi_name) tuple. (E.g. ``(44, 'ansiblue')``.) for a given (r,g,b) value. )tuplerx_get)ryvaluergkeycaches rpget_codez_16ColorCache.get_codesAg/  e 5'2E#JSzrrcx|\}}}t||||}|jr t|}||fSt|}||fS)Nrg)rqrwBG_ANSI_COLORSFG_ANSI_COLORS)ryr~rgrdrerfrjcodes rpr}z_16ColorCache._getsT1a'1aA 77!%(DU{"%(DU{rrN)F)rwboolreturnNone)r~tuple[int, int, int]rg Sequence[str]r_ColorCodeAndName)__name__ __module__ __qualname____doc__rzrr}rrrrprtrtsT < EG ) 4A    EG ) 4A   rrrtc eZdZdZddZddZy)_256ColorCachez: Cache which maps (r, g, b) tuples to 256 colors. cg}|jd|jd|jd|jd|jd|jd|jd|jd|jd |jd |jd |jd |jd |jd|jd|jdd}tdD]4}||dzdz}||dzdz}||dz}|j|||f6tddD]}d|dzz}|j|||f ||_y)NrHrOrQrR)rrrSrTrIrKrUrVrW)r,r,rNrXrYrM)rr2rNr$r )appendrangecolors)ryr valuerangeirdrerfvs rprzz_256ColorCache.__init__sv-/  () () () () () () () () () () () () () () () (): s %AAGq=)AAFa<(A1q5!A MM1a) $  %q" %AAF A MM1a) $ % rrc|\}}}d}d}t|jD]3\}\}} } |dk\s||z dz|| z dzz|| z dzz} | |ks0|}| }5|||<|S)Nr]rr^) enumerater) ryr~rdrerfrirjrrlrmrnros rp __missing__z_256ColorCache.__missing__s1a!(5 !OA|BBwVMQVM1QVMAx<E H !U  rrNrr)r~rrint)rrrrrzrrrrrprrs$LrrrF)rwTc0eZdZdZddZddZd dZd dZy) _EscapeCodeCachez Cache for VT100 escape codes. It maps (fgcolor, bgcolor, bold, underline, strike, italic, blink, reverse, hidden, dim) tuples to VT100 escape sequences. :param true_color: When True, use 24bit colors instead of 256 colors. c||_yrv) color_depth)ryrs rprzz_EscapeCodeCache.__init__ s &rrc |\ }}}}}}}} } } g} | j|j|xsd|xsd|r| jd| r| jd|r| jd|r| jd|r| jd| r| jd| r| jd|r| jd | rd d j| zd z} nd } | ||<| S)N12354789z[0;;m)ra_colors_to_coderjoin)ryattrsfgcolorbgcolorbold underlinestrikeitalicblinkreversehiddendimpartsresults rprz_EscapeCodeCache.__missing__ s            T))'-RBGH  LL   LL   LL   LL   LL   LL   LL   LL  %036FFU  rrcl t|d}|dz dz}|dz dz}|dz}|||fS#t$rwxYw)z'Turn 'ffffff', into (0xff, 0xff, 0xff).rrNr)r ValueError)rycolorrgbrdrerfs rp_color_name_to_rgbz#_EscapeCodeCache._color_name_to_rgb7sX eR.Cd"AT!Ad Aa7N    s ( 3cddfd }g}|j|d|j|dtt|S)zR Return a tuple with the vt100 values that represent this color. rc|rtnt}|r jtjk(rgS||vr||gS j |} jtjk(rG|r( k7r g}ng}tj||\}}|gStj|\}}| |gS jtjk(r|\}}} |rdndd||| gS|rdnddt|gS#t $rgcYSwxYw)Nr0&r^) rrrr DEPTH_1_BITrr DEPTH_4_BIT _16_bg_colorsr _16_fg_colors DEPTH_24_BIT _256_colors)rrwtablerrgrrkrdrerfbg_colorfg_ansifg_colorrys rpgetz-_EscapeCodeCache._colors_to_code..getLs$')NnED,, 0F0FF %e ~%11%8C ##z'='==#x/'.iG&(G%2%;%;C%;%Q d $v %2%;%;C%@ d"& $v %%)@)@@!GAq!#%R21a;;$&R2;s3CDD1"IsC// C=<C=FT)rstrrwrrz list[int])ramapr)ryrrrrrs``` @rprz _EscapeCodeCache._colors_to_codeCsQ( E( ET c(E*+ c(D)*3rrN)rrrr)rrrr)rrrr)rrrrrz Iterable[str])rrrrrzrrrrrrrprrs'(T 7 rrrc\tj|}|j|jfS)zw Get the size of this pseudo terminal. :param fileno: stdout.fileno() :returns: A (rows, cols) tuple. )osget_terminal_sizelinescolumns)filenosizes rp _get_sizer}s'    'D ::t|| ##rrceZdZUdZeZded< d* d+dZe d, d-dZ d.dZ d/dZ d0d Z d1d Z d1d Zd2d Zd3d Zd3dZd3dZd3dZd3dZd3dZd3dZd3dZd3dZd4dZd3dZd3dZd3dZd3dZd3dZd5d6dZd7dZ d7dZ!d7dZ"d7d Z#d3d!Z$d3d"Z%d8d#Z&d3d$Z'd3d%Z(d3d&Z)e*d9d'Z+d3d(Z,d:d)Z-y);ra :param get_size: A callable which returns the `Size` of the output terminal. :param stdout: Any object with has a `write` and `flush` method + an 'encoding' property. :param term: The terminal environment variable. (xterm, xterm-256color, linux, ...) :param enable_cpr: When `True` (the default), send "cursor position request" escape sequences to the output in order to detect the cursor position. That way, we can properly determine how much space there is available for the UI (especially for drop down menus) to render. The `Renderer` will still try to figure out whether the current terminal does respond to CPR escapes. When `False`, never attempt to send CPR requests. zset[int]_fds_not_a_terminalNc tfddDsJg|_|_||_||_||_||_||_tjttjtjttjtjttjtjttji|_d|_d|_y)Nc36K|]}t|ywrv)hasattr).0astdouts rp z(Vt100_Output.__init__..sB!761%Bs)writeflushF)all_bufferrdefault_color_depthrterm enable_bell enable_cprrrrr DEPTH_8_BITr_escape_code_caches_cursor_shape_changed_cursor_visible)ryrget_sizerrrrs ` rprzzVt100_Output.__init__sB/ABBBB"$ $ #6 ! &$  " "$4Z5K5K$L  " "$4Z5K5K$L  " "$4Z5K5K$L  # #%5j6M6M%N H  &+" -1rrc j}jso|||jvr_d}t j j||zt j j||jj|dfd }|||||S#tj$rd}YwxYw)z Create an Output class from a pseudo terminal. (This will take the dimensions by reading the pseudo terminal attributes.) Nz+Warning: Output is not a terminal (fd=%r). cd\}} tj\}}t|xsd|xsdS#t$rY wxYw)N)NNP)rowsr)rrOSErrorr )rrrs rprz'Vt100_Output.from_pty..get_sizesR)MD'   )&--/ : gTZRB? ?  s9 AA)rrrrr ) rioUnsupportedOperationisattyrsysstderrrradd)clsrrrrfdmsgrs ` rpfrom_ptyzVt100_Output.from_ptys" B}}BJ"Crrc&|jdy)Nz[?2004hr(rs rpenable_bracketed_pastez#Vt100_Output.enable_bracketed_paste_r.rrc&|jdy)Nz[?2004lr(rs rpdisable_bracketed_pastez$Vt100_Output.disable_bracketed_pastebr.rrc&|jdy)zh For vt100 only. Put the terminal in cursor mode (instead of application mode). z[?1lNr(rs rpreset_cursor_key_modez"Vt100_Output.reset_cursor_key_modees z"rrc0|jd||fzy)z' Move cursor position. z[%i;%iHNr()ryrowcolumns rp cursor_gotozVt100_Output.cursor_gotoms }V}45rrcf|dk(ry|dk(r|jdy|jd|zy)Nrrzz[%iAr(ryamounts rp cursor_upzVt100_Output.cursor_ups0 Q;  q[ NN8 $ NN:. /rrcf|dk(ry|dk(r|jdy|jd|zy)Nrrzz[%iBr(rLs rp cursor_downzVt100_Output.cursor_down{s2 Q;  q[ NN8 $ NN:. /rrcf|dk(ry|dk(r|jdy|jd|zy)Nrrzz[%iCr(rLs rpcursor_forwardzVt100_Output.cursor_forwardrOrrcf|dk(ry|dk(r|jdy|jd|zy)Nrrz[%iDr(rLs rpcursor_backwardzVt100_Output.cursor_backwards0 Q;  q[ NN4 NN:. /rrcR|jdvrd|_|jdyy)N)TNFz[?25lrrrs rp hide_cursorzVt100_Output.hide_cursors)   < /#(D NN; ' 0rrcR|jdvrd|_|jdyy)N)FNTz [?12l[?25hrXrs rp show_cursorzVt100_Output.show_cursors*   = 0#'D NN/ 0 1rrc<|tjk(ryd|_|jtjdtj dtj dtjdtjdtjdij|dy) NTz[2 qz[6 qz[4 qz[1 qz[5 qz[3 qr) r _NEVER_CHANGErrBLOCKBEAM UNDERLINEBLINKING_BLOCK BLINKING_BEAMBLINKING_UNDERLINEr)ry cursor_shapes rpset_cursor_shapezVt100_Output.set_cursor_shapes| ;44 4 %)" !!:  *%%z**J)):..  c,# rrcN|jrd|_|jdyy)zReset cursor shape.Fz[0 qN)rrrs rpreset_cursor_shapezVt100_Output.reset_cursor_shapes(  % %).D & NN: & &rrc|jsydj|j}g|_t|j|y)z3 Write to output stream and flush. Nr)rrrrrs rprzVt100_Output.flushs5|| wwt||$ T[[$'rrcF|jd|jy)z: Asks for a cursor position report (CPR). zN)rrrs rp ask_for_cprzVt100_Output.ask_for_cprs y! rrc|jsytjjdddk(ryt |j ry |j jS#t$rYywxYw)NFPROMPT_TOOLKIT_NO_CPRrr) rrenvironrrrrr rrs rpresponds_to_cprzVt100_Output.responds_to_cprsb ::>>12 6# = DII & ;;%%' '  s A## A/.A/c`|jr"|jd|jyy)z Sound bell.r!N)rrrrs rpbellzVt100_Output.bells%    NN4 JJL rrc|j |jS|j}|tjSt |rtj S|dvrtj StjS)z Return the default color depth for a vt100 terminal, according to the our term value. We prefer 256 colors almost always, because this is what most terminals support these days, and is a good default. r)rrrDEFAULTrrr)ryrs rpget_default_color_depthz$Vt100_Output.get_default_color_depthsk  # # /++ +yy <%% % D !)) ) + +)) )!!!rr)NNTT)rr rzCallable[[], Size]r str | NonerColorDepth | Nonerrrrrr)NNT) rr rrtrrurrrrr)rr)rr)rrrr)r#rrrr)rrrrrr)rr)rHrrIrrr)rMrrr)rdr rr)rr)rr).rrrrsetr__annotations__rz classmethodrrrrrrr$r&r)r+r-r0r2r4r6r8r;r=r@rBrDrFrJrNrQrSrVrYr[rergrrjpropertyrnrprsrrrrprrs| %(E)  15 #1#1%#1 #1 / #1  #1#1 #1J 15 2 2 2 / 2  2  2 2 h $$" 7 ",& && ! !" 1##&&#6 0000( 1  ' (  "rrr) rdrrerrfrrgrrr)rrrztuple[int, int])-r __future__rrrr typingrrrrrr r prompt_toolkit.cursor_shapesr prompt_toolkit.data_structuresr prompt_toolkit.outputr prompt_toolkit.stylesrrprompt_toolkit.utilsrrrr__all__rrrbrvrqrrrrtrrrrrrrrrrrprs# NNN4/(91#&  2r    " 2rRr b!"#$b%&',2r    " 2sSs c!"#$c%&'. # ")#!#$"% "!$'%&)'(*)*(+,+-.(/6 >c"23333 >c"23333 #&6"7777D#s(O&&R?T%S# .34?D' &  y tE3J'y x$p"6p"rr