L iidZddlmZddlmZddlZddlZddlZddl Z ddl Z ddl Z ddl Z ddlmZddlmZddlmZddlmZdd lmZdd lmZdd lmZdd lmZdd lmZddlmZddlmZddlmZddlm Z ddl!m"Z"e jFdZ$ejJdk(rdZ&dZ'ndZ&dZ'Gdde jPe$Z)d(d)dZ* d*dZ+ d*dZ, d+dZ-Gdd Z.d,d-d!Z/d.d"Z0e jbd#k(rddl2Z2ejfd/d$Z4d0d%Z5yddl6Z6ddl7Z7ejfd/d&Z4d0d'Z5y)1z This module contains implementations for the termui module. To keep the import time of Click down, some infrequently used functionality is placed in this module and only imported as needed. ) annotationsN)gettext)StringIO)Path) TracebackType)_default_text_stdout)CYGWIN)get_best_encoding)isatty) open_stream) strip_ansi)term_len)WIN)ClickException)echoVnt  z [?25lz[?25h c6eZdZ d ddZddZ ddZddZddZddZe ddZ e dd Z e dd Z dd Z dd Zdd ZddZddZddZddZdd dZddZddZy)! ProgressBarNc||_||_||_||_||_||_| |_| |_| |_| xsd|_ | t} | t} | |_ ||_ ||_d|_||_|dk(|_|ddlm}||d}|dk(rd}|,| t)dt+j,dt/|}t1||_||_d|_g|_||t9j8x|_|_d|_d|_ d|_!d|_"d|_#tI|j|_%d|_&y)Nr) length_hintziterable or length is requiredzcabc.Iterable[V]F)' fill_char empty_char bar_templateinfo_sephiddenshow_eta show_percentshow_positem_show_funclabelr rfilecolorupdate_min_steps_completed_intervalswidth autowidthoperatorr TypeErrortcastrangeiterlengthposavgtimestartlast_eta eta_knownfinished max_widthentered current_itemr _is_atty _last_line)selfiterabler3rrrr r!r"r#r$r%r&r'r(r)r+rs X/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/click/_termui_impl.py__init__zProgressBar.__init__,s]&#$(     (  ,+2 <')D|z  0$%! $z > , 2.F|  ~ @AAvv0%-@H&*8n   "  %)YY[0 T]$# %)" &*tyy) &*c4d|_|j|S)NT)r<render_progressr@s rB __enter__zProgressBar.__enter__ss   rDc$|jyN) render_finish)r@exc_type exc_valuetbs rB__exit__zProgressBar.__exit__xs rDcp|js td|j|jS)N.You need to use progress bars in a with block.)r< RuntimeErrorrF generatorrGs rB__iter__zProgressBar.__iter__s.||OP P ~~rDc*tt|SrJ)nextr2rGs rB__next__zProgressBar.__next__s DJrDc|js |jsy|jjt|jj yrJ)r!r>r'write AFTER_BARflushrGs rBrKzProgressBar.render_finishs0 ;;dmm   " rDc|jryt|jt|jxsdxsdz dS)N?r)r:minr4floatr3rGs rBpctzProgressBar.pcts5 ==488uT[[%5A6;!>DHH A"fG "HA"fG "HAFE "HA1uBuRj'"QwrlCC1WRL'">>rDclt|j}|j|d|jz }|S)N/)strr4r3)r@r4s rB format_poszProgressBar.format_poss3$((m ;; " Qt{{m$ $C rDc@t|jdzddddS)Ndz 4%r)rmr`rGs rB format_pctzProgressBar.format_pcts&dhhn%b)+AB//rDcF|jRt|j|jz}|j|z}||j |j|z zz }|S|j r|j|jz}|St|j |jxsdz}|jdk7rU|j|ttj|j|jzdz dz|jz<dj|}|S)Nrrg@g?r) r3rmr`r+rrr:listremathcosr4join)r@ bar_lengthbarcharss rB format_barzProgressBar.format_bars ;; "TXX 23J..:-C 4??djj:&=> >C ]]..4::-C DJJO!<=E&&!+ NN $((T-D-D"DEKcQ**% ''%.C rDc|j}g}|j| |j }|jr|j|j |r|j|j |j r7|jr+|js|j|j|j.|j|j}||j||j|j|j|jj!|dzj#S)N)r&rinfo)r#r3r$appendruryr"r9r:rqr%r=rr&rr r~rstrip)r@r# info_bits item_infos rBformat_progress_linez ProgressBar.format_progress_lines((  ;; "|';#}},L ==   T__. /    T__. / ==T^^DMM   T__. /    *++D,=,=>I$  +   ( **95  &( rDcX|jry|jsW|j|jk7r=|j|_t |j|j |j yg}|jrddl}|j}d|_ t|j}td|jj|z }||krF|j:|j!t"|j!d|jz||_||_ |j}|j |j}|j!t"|j}t|}|j|j|kr||_|j!||j!d||z zdj%|}||jk7rE||_t ||j |j d|j j'yy)N)r'r(r rF)r'r(nl)r!r>r?r&rr'r(r,shutilr+rrmaxget_terminal_sizecolumnsr;r BEFORE_BARr~r[) r@bufr old_widthclutter_length new_width clear_widthlineline_lens rBrFzProgressBar.render_progresss ;; }}$**,"&**TZZdiitzzB  >>  IDJ%d&?&?&ABNAv779AANRSI9$)C :& 3/0!*"DJjj >> %..K :((*D> >> !T^^h%>%DN 4 3+012wws| 4?? ""DO DIITZZE B IIOO  #rDc|xj|z c_|j |j|jk\rd|_tj|jz dkrytj|_|jr/tj|j z |jz }n!tj|j z }|j dd|gz|_|jdu|_y)NTr]i)r4r3r:r6r8r7r5r9)r@n_stepssteps rB make_stepzProgressBar.make_steps G ;; "txx4;;'> DM IIK$-- '3 .   88IIK$**,8D99;+D88BC=D6)D0rDc|||_|xj|z c_|j|jk\r3|j|j|j d|_yy)aUpdate the progress bar by advancing a specified number of steps, and optionally set the ``current_item`` for this new position. :param n_steps: Number of steps to advance. :param current_item: Optional item to set as ``current_item`` for the updated position. .. versionchanged:: 8.0 Added the ``current_item`` optional parameter. .. versionchanged:: 8.0 Only render when the number of steps meets the ``update_min_steps`` threshold. Nr)r=r*r)rrF)r@rr=s rBupdatezProgressBar.update0sb  # ,D  !!W,!  $ $(=(= = NN444 5  "()D % >rDc.d|_d|_d|_y)NFT)r9r=r:rGs rBfinishzProgressBar.finishJs  rDc#XK|js td|js|jEd{y|jD]=}||_|j dk(r|j ||jd?|j|j y7rw)zReturn a generator which yields the items added to the bar during construction, and updates the progress bar *after* the yielded block returns. rQNrr) r<rRr>r2r=r*rFrr)r@rvs rBrSzProgressBar.generatorOs||OP P}}yy ii $&! ,,1((* A  KKM  " !s3B*B(A3B*)N#rz%(bar)sz FTNFNNNNr)"rAzcabc.Iterable[V] | Noner3z int | Nonerrtrrtrrtr rtr!boolr"rr# bool | Noner$rr%z)t.Callable[[V | None], str | None] | Noner& str | Noner'zt.TextIO | Noner(rr)rmr+rmreturnNone)rzProgressBar[V])rLztype[BaseException] | NonerMzBaseException | NonerNzTracebackType | Nonerr)rzcabc.Iterator[V])rr)rr)rr_rrt)rrmrrrJ)rrmr=zV | Nonerr)__name__ __module__ __qualname__rCrHrOrTrWrKpropertyr`rergrqruryrrrFrrrrSrDrBrr+s"%$(DH $! !#E+)E+E+ E+  E+  E+E+E+E+"E+E+BE+E+E+E+ !E+"#E+$ %E+N ,( !      CC 44   0&6,\1,*4 #rDrc@t}| t}ttjr t|s t |||St jtjjddd}|r"trt|||ryt|||rytjjddvr t |||Ststjjdrt|d g|ryt|d g|ryd dl}|j#\}}tj$| t|d g|r tj&|yt |||tj&|S#tj&|wxYw) z2Decide what method to use for paging through text.NPAGERrF)posixTERM)dumbemacsos2morelessr)r rr sysstdin _nullpagershlexsplitosenvirongetr_tempfilepager _pipepagerplatform startswithtempfilemkstempcloseunlink)rSr(stdoutpager_cmd_partsrfdfilenames rBpagerrqsH ! #F~ #)) F6N&)U33kk"**..""=UKO i%@  ?E :  zz~~f!22&)U33 s||&&u->F8U4 )fXu-##%LBHHRL i&5 1  (&)U3 ( (s?F$ FFc|syddl}|d}|dd}|j|}|syt|j}|j}ddl} t tj} |L|dk(rGtjjdddj|} | sd | d<d }n d | vsd | vrd }| jt|g|zd| j| d d } | jJ |D]*} |s t| } | jj!| , | jj) | j+ y #t"$rY:t$$r}| j'|d}~wwxYw#t"$rYLwxYw#t,$rYnwxYw_# | jj)n#t"$rYnwxYw | j+w#t,$rYnwxYw"xYw)zPage through text by feeding it to another program. Invoking a pager through this might support colors. Returns `True` if the command was found, `False` otherwise and thus another pager should be attempted. FrNrrLESSrr-RTrRreplace)shellrenverrorstext)rwhichrabsolutename subprocessdictrrrr~PopenrtPIPErrrYBrokenPipeError Exception terminaterwaitKeyboardInterrupt)rS cmd_partsr(rcmd cmd_params cmd_filepathcmd_pathcmd_namerr less_flagscres rBrrs  A,C12J<<$L  L!**,H}}H rzz C }V+ vr23CHHZ4H3IJ CKE J #"3E X*$oo    A 77  ' D!$' GGMM$   "  GGMMO  G        %    GGMMO    %  s3/E"F$E?F E<FE<%E77E<<F? F  F  FFG- F;:G-; GG-GG- GG- G)&G-(G))G-c|syddl}|d}|j|}|syt|j}ddl}ddl}|j \} } dj|} |s t| } ttj} t| dd5} | j| j| ddd |jt!|| gt%j&| t%j(| y#1swYQxYw#t"$rYBwxYw#t%j&| t%j(| wxYw)zPage through text by invoking a program on a temporary file. Returns `True` if the command was found, `False` otherwise and thus another pager should be attempted. FrNrwbT)rrrrrrrr~rr rrr rYencodecallrtOSErrorrrr)rSrr(rrrrrrrrrencodingfs rBrrs  A,C<<$L L!**,H##%LB 779 D $ ,H Xt $Q ''1  H%&'X12   ( ''       (s0!D D D D$!D'#D$$D'',EcN|D] }|s t|}|j|"y)z>Simply print unformatted text. This is the ultimate fallback.N)rrY)streamrSr(rs rBrr*s,d#D TrDceZdZ d d dZd dZd dZejd dZejd dZddZy)EditorNc<||_||_||_||_yrJ)editorr require_save extension)r@rrrrs rBrCzEditor.__init__5s! ("rDc|j |jSdD]'}tjj|}|s%|cStryddlm}dD]}|| |cSy)N)VISUALEDITORnotepadr)r)zsensible-editorvimnanovi)rrrrrrr)r@keyrrrs rB get_editorzEditor.get_editorAsm ;; ";; % C$B    6 FV}(  rDcddl}|j}d}|jr9tjj }|j |jdjd|D} |j|d||d}|j}|dk7r$ttdj|y#t$r+}ttdj|| |d}~wwxYw) Nrrc3(K|] }d|d yw)"Nr).0rs rB z$Editor.edit_files..\sJH!H:QJsT)argsrrz{editor}: Editing failed)rz{editor}: Editing failed: {e})rr)rrrrrcopyrr~rrr_formatr) r@ filenamesrrr exc_filenamer exit_coders rB edit_fileszEditor.edit_filesRs")- 88jjoo'G NN488 $xxJ JJ    xq/WD!AIA~$01888G  129919M  s5AC C<&C77C<cyrJrr@rs rBeditz Editor.editls=@rDcyrJrrs rBrz Editor.editqs47rDcddl}|d}njt|ttfr|}nQ|r|j ds|dz }t r"|j ddjd}n|jd}|jd|j\}} tj|d 5}|j|dddtj|tjj|tjj!|d z ftjj!|}|j#|f|j$r9tjj!||k(r tj&|yt)|d 5}|j+}dddt|ttfrtj&|Sj-dj ddtj&|S#1swY]xYw#1swYyxYw#tj&|wxYw) NrrDrz z utf-8-sigzutf-8zeditor-)prefixsuffixrrb)r isinstancebytes bytearrayendswithrrrrrrfdopenrYutimepathgetatimegetmtimerrropenreaddecode) r@rrdatarrr timestamprs rBrz Editor.editts <&)D ui0 1DDMM$/ ||D&188E{{7+##9T^^#LD 2t$    HHTBGG,,T2BGG4D4DT4JQ4NO P((.I OOTG $  RWW%5%5d%;y%H IIdOdD! QVVX $ 23 IIdO99[)11&$? IIdO3  "   IIdOsIH1+H=B._unquote_files&( >>) $#ab'"C rDdarwinr$z-Wrz /dev/nullw)stderrexplorerz/select,r7z/WAITrcygstartz-w.zxdg-open)zhttp://zhttps://r)r0rtrrt)rrrrr$rrrrrrr rr!dirnamer webbrowser) r0rlocaterr1r nullrr:s rBopen_urlr=s ||xx  KK   KK  M#&'K% ##D#6;;= JJL $C(3% 01D9D G$ KKO KK  ??4( (  $C 45D>1 26$  OOC  sC) G+GG&(AG5G G#"G#& G21G253H-,H-cv|dk(r t|dk(rts t|dk(rtr ty)N)rrEOFError)chs rB_translate_ch_to_excrDs7 V|!! V|Cj V|j rDwin32c#Kdyw)NrrrrDrB raw_terminalrGs sc8|r 66!**RW-v~~>D66!**RW-v}}=D V ! ! $&LBR  rDc#Kttjstd}|j }n tjj }d} t j |} tj||t j|t j|tjj||jyy#t j|t j|tjj||jwwxYw#t j$rYywxYww)Nz/dev/tty)r rrr$filenotermios tcgetattrttysetraw tcsetattr TCSADRAINrr[rerror)rr old_settingss rBrGrG1s cii Z AB!!#BA ",,R0L  2!!"g&7&7F   "=GGI!!!"g&7&7F   "=GGI!}}   sDAED:/CAD:EAD77D::E EEEcJt5}tj|djt t j d}|r8tt jrt jj|t||cdddS#1swYyxYw)N r) rGrr%r&r rrr rrYrD)rrrCs rBrPrPLso ^ rR''(9#))(DiPBszz*   $  $   s BBB"rJ)rSr)r(rrr)rSr)rz list[str]r(rrr)rzt.TextIOrSr)r(rrr)FF)r0rtrrr;rrrm)rCrtrr)rzcabc.Iterator[int])rrrrt)8__doc__ __future__rcollections.abcabccabc contextlibr|rrrr6typingr/rr iorpathlibrtypesr_compatr r r r r rrr exceptionsrutilsrTypeVarrrrrZGenericrrrrrrr=rDrrLcontextmanagerrGrPrSrUrrDrBrms #  )& & AIIcN77d?JIJIC#!))A,C#L 'T]!].7]@K] ]@,!,.7,@K, ,^ !3