8f7 UddlZddlmZmZmZddlmZddlmZm Z m Z m Z m Z m Z mZmZddlmZddlmZmZmZmZddlmZdd lmZdd lmZdd lmZmZdd l m!Z!dd l"m#Z#GddeZ$GddeeZ%e&dkrddl'Z'ddl(Z(ddl)m*Z*ddlm+Z+m Z m,Z,ddl-m.Z.ddlmZddl/m%Z%ddl0m1Z1ddl2m3Z3ddl4m5Z5ddl6m7Z7eZe5dddZ4e7d d!d"Z6e68d#d$d%d&e1d'd(e6d)d*d+d,d-e4e3d.g Z9e*e9Z:gd/Z;e%e05Ze>fe?fe@d1<eAd2D]ZBe;eBeCe;zZDe;D]rZEeEeDkr e(jFd3e'jGdd4dkreHeIe:d5e'j'd6zdzz e=eDeEf<eCe=eCe;dz kr6e=JeKe=Lde7d78Z6e6Md9e6Md:e6Md;e=ND]4\\ZOZPZQe68eOePe#eQd<eQd=krd>nd?@5e "4GG  %%%%%c8|jdSN)r$setr's r)stopz_RefreshThread.stops r*c>|jd|jz sz|jj5|js|jdddn #1swxYwY|jd|jz xdSdS)Nr)r$waitr r_lockis_setrefreshr.s r)runz_RefreshThread.runs)..T% 0FT)rF) _renderablerr@_screen _alt_screen_redirect_stdout_redirect_stderr_restore_stdout_restore_stderrrr2 ipy_widgetrB_startedrC_refresh_threadr rF_get_renderablerrG _live_render) r'rHr@rArBr rCrDrErFrGs r)r&z Live.__init__3s"A%%%'G%%%%")"5ww;==    / /2626WW )-(# !'6Y9="4!2-&    ! !5F   r*c|jS)z'Check if live display has been started.)rRr.s r) is_startedzLive.is_started[s }r*cN|j|n|j}|pdS)N)rTrJr'rHs r)rGzLive.get_renderable`s9#/  " " "!  Rr*r4cx|j5|jr ddddS|j|d|_|jr|jd|_|jd||j ||r9 | n##t$r| wxYw|j r3t||j|_|jddddS#1swxYwYdS)z|Start live rendering display. Args: refresh (bool, optional): Also refresh. Defaults to False. NTF)r2rRr@set_liverKset_alt_screenrL show_cursor_enable_redirect_iopush_render_hookr4 Exceptionr/rBrr rSstart)r'r4s r)rbz Live.starths Z - -}  - - - - - - - - L ! !$ ' ' ' DM| E#'<#>#>t#D#D L $ $U + + +  $ $ & & & L ) )$ / / / LLNNNN  IIKKK   -'5dDQ ,,T->-M-M-O-OPPP2t~2--///--///L00222+, 0H, ))+++L,,T222'; 33E:::~Qd.>Q ,,T->-M-M-O-OPPP2t~2--////32 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0sU KAK:J,<'F#CJJ, K,J0 0K3J0 4KK Kc@||jdu|S)Nr4)rbrJr.s r) __enter__zLive.__enter__s# 4+47 888 r*exc_typeexc_valexc_tbc.|dSr,)r/)r'rqrrrss r)__exit__z Live.__exit__s r*c|jjs |jjr|jrgt t jtsHt j|_tdt|jt jt _|j rkt t j tsNt j |_ tdt|jt j t _ dSdSdSdS)z&Enable redirecting of stdout / stderr.r N) r@rirfrM isinstancesysstdoutrrOrrNstderrrPr.s r)r_zLive._enable_redirect_ios < # Qt|'> Q$ QZ I-N-N Q'*z$!(IdlCJ,O,OPP $ QZ I-N-N Q'*z$!(IdlCJ,O,OPP  Q Q Q Q Q Qr*c|jr&td|jt_d|_|jr(td|jt_d|_dSdS)z'Disable redirecting of stdout / stderr.r N)rOrrxryrPrzr.s r)rgzLive._disable_redirect_ios`   (h(<==CJ#'D   (h(<==CJ#'D  ( (r*cZ|}|jrt|n|S)zwGet the renderable that is being displayed Returns: RenderableType: Displayed renderable. )rGrLrrZs r)rHzLive.renderables0((** %)%5Evj!!!:Er*roct|tr|j|}|j5||_|r|ddddS#1swxYwYdS)zUpdate the renderable that is being displayed Args: renderable (RenderableType): New renderable to use. refresh (bool, optional): Refresh the display. Defaults to False. N)rwstrr@ render_strr2rJr4)r'rHr4s r)updatez Live.updates j# & & =00< >F-B> F-#C,)F-+C,,"F-'E5 F-E F-E F-"'F F-F F-F F--F14F1 renderablesc0|j|j_|jjr_|j5|jrt jn|j}|g||j}dddn #1swxYwYn|j s|j s g||j}|S)z;Process renderables to restore cursor and display progress.N) rFrUr@is_interactiver2rLrhomeposition_cursorrRrC)r'rresets r)process_renderableszLive.process_renderabless/3.D+ < & < G G'=GLNNN*::<< %F{FD4EF  G G G G G G G G G G G G G G G  <&*n <AE& & & ^,& '" &  &  & "& & & & 2& !"n*&  & & & & PDX     --T-d----<0000>4 ./-('   QQQQ((((FNFFFXFEJ    T d    2222: 12  r*r__main__)cycle)Dictr Tuple)Align)r)r)Panel)Rule)Syntax)Tablea~def loop_last(values: Iterable[T]) -> Iterable[Tuple[bool, T]]: """Iterate and generate a tuple with a flag for last value.""" iter_values = iter(values) try: previous_value = next(iter_values) except StopIteration: return for value in iter_values: yield False, previous_value previous_value = value yield True, previous_valuepythonT) line_numbersfoobarbaz123zYou can make the terminal shorter and taller to see the live table hideText may be printed while the progress bars are rendering.z(In fact, [i]any[/i] renderable will workzSuch as [magenta]tables[/]...zPretty printed structures...examplezPretty printed)typetextz Syntax...zGive it a try!)SGDMYREURUSDAUDJPYCNHHKDCADINRDKKGBPRUBNZDMXNIDRTWDTHBVND)r@exchange_rate_dictdg? i@zExchange Rates)titlezSource CurrencyzDestination Currencyz Exchange Ratez.4fg?redgreen)style)Trx threadingrrrtypesrtypingrrr r r r r rrYrr@rrrrrkr file_proxyrjupyterr live_renderrrrArrrrrr7randomtime itertoolsrrralignrrpanelrrulersyntaxrtableradd_rowprogress_renderablesexamples exchanges live_tablerr~r;__annotations__rangeindexlenselect_exchangeexchangesleeprandintlognextpoplistkeys add_columnitemssourcedest exchange_ratercenterrr*r)rs **********HHHHHHHHHHHHHHHHHHHHKKKKKKKKKKKK!!!!!!!!!!!!;;;;;;;;(((((V(((&iiiii<iiiX zMMMKKK((((((((((      """"""giiG V " F E% & &E MM#sC    E 899' &$455   u)**HI* g   !7*;=DsCx%!78===U3ZZ 7 7E'I(>?O% 7 7.. 3!6>!R((1,,KKX///BE"V]__s*a/C"OX#>?3)**SS^^a-???&**440B0G0G0I0I+J+J1+MNNN$4555  !2333  !7888  1115G5M5M5O5O1NVTMMM,22+83+>+>%%G!!,%,u"5"566667 7 7!7!7!7!7!7!7!7!7!7!7!7!7!7!7!7!7!7!7Os?F2K??LL