)L iڊdZddlmZddlmZddlmZmZmZm Z ddl m Z ddl m Z mZddlmZmZddlmZmZdd lmZdd lmZmZmZmZmZmZdd lmZm Z m!Z!m"Z"dd l#m$Z$dd l%m&Z&ddl'm(Z(ddl)m*Z*ddl+m,Z,ddl-m.Z.m/Z/m0Z0m1Z1m2Z2m3Z3m4Z4m5Z5m6Z6m7Z7ddl8m9Z9m:Z:m;Z;ddlZ?ddl@mAZAmBZBmCZCddlDmEZEmFZFmGZGmHZHmIZIddlJmKZKmLZLddlMmNZNmOZOddlPmQZQddlRmSZSmTZTddlUmVZVgdZWe*ZXGddZYGd d!ZZGd"d#Z[Gd$d%Z\Gd&d'Z]Gd(d)Z^Gd*d+Z_e d,Z`Gd-d.ee`ZaGd/d0eae`ZbGd1d2eae`ZcGd3d4ecedZeGd5d6ZfGd7d8ZgGd9d:Zhy;)z#TextArea.__init__..s(?rZcjSr_) completerrasr[rcz#TextArea.__init__.. t~~rZc.tjSr_)rcomplete_while_typingrasr[rcz#TextArea.__init__..s : :;rZcjSr_) validatorrasr[rcz#TextArea.__init__..rfrZcjSr_) auto_suggestrasr[rcz#TextArea.__init__..s D4E4ErZ) document multiliner`rerhrjrlaccept_handlerhistorynamecjSr_)lexerrasr[rcz#TextArea.__init__..s tzzrZ) processorfilterzclass:text-area.promptstyle)bufferrsinput_processorssearch_buffer_controlpreview_search focusablefocus_on_clickTdisplay_arrowsr?zclass:text-area minc.tjSr_)r wrap_linesrasr[rcz#TextArea.__init__..s)ArZ) heightwidthdont_extend_heightdont_extend_widthcontentrwr left_margins right_marginsget_line_prefix) isinstancer@controlrerhrsrlr`rrjr rrrr=r rxr*r7r4r2rrr5rr3r1r0Dexactr(window)rbtextrnpasswordrsrlrerhrjrorpr|r}rr`rrrr line_numbersr scrollbarrw search_fieldr{promptryrqsearch_controlrrs` r[__init__zTextArea.__init__s<  !N  m 4)11N  #! #%:" ("$"dA& ?@&'=>"+;#''=>+,EF)   %;;12$(*Idkk,BgX,M%/1)H:MF*BC #1))!  & !0!E F "  . 01 ! WWQZFLM"U* >1XF1/LL !AB%'+   rZc.|jjS)z$ The `Buffer` text. )rxrras r[rz TextArea.texts {{rZc&t|d|_yNr)rrmrbvalues r[rz TextArea.text&s * rZc.|jjS)zA The `Buffer` document (text + cursor position). )rxrmras r[rmzTextArea.document*s {{###rZc>|jj|dy)NT)bypass_readonly)rx set_documentrs r[rmzTextArea.document1s    =rZc.|jjS)zM The accept handler. Called when the user accepts the input. rxroras r[rozTextArea.accept_handler5s {{)))rZc&||j_yr_rrs r[rozTextArea.accept_handler<s%* "rZc|jSr_rras r[__pt_container__zTextArea.__pt_container__@ {{rZ)TFNNNTNNNTFTFNNFFFNFrNTrNr)8rstrrnrrrrsz Lexer | NonerlzAutoSuggest | NonerezCompleter | NonerhrrjzValidator | NoneroBufferAcceptHandler | NonerpzHistory | Noner|rr}rrrr`rrr-rr-rrrrrboolrzGetLinePrefixCallable | NonerrrwrrzSearchToolbar | Noner{rrrryzlist[Processor] | NonerqrreturnNonerr)rrrr)rr)rrrr)rr)rr rrrr") rOrPrQrRrpropertyrsetterrmrorrYrZr[rArAps:|"&!&"+/&*.2&*59"&"&',#'"'"#+0*/"8<-1'+#%379p p  p  p  p ) p $p  ,p $p 3p  p  p %p !p  p !p "#p $)%p &('p ()p *6+p ,-p ./p 0+1p 2%3p 4!5p 617p 89p : ;p d   [[++$$ __>>** ++rZrAc`eZdZdZddddej df ddZd dZy) rBa Widget that displays the given text. It is not editable or focusable. :param text: Text to display. Can be multiline. All value types accepted by :class:`prompt_toolkit.layout.FormattedTextControl` are allowed, including a callable. :param style: A style string. :param width: When given, use this width, rather than calculating it from the text size. :param dont_extend_width: When `True`, don't take up more width than preferred, i.e. the length of the longest line of the text, or value of `width` parameter, if given. `True` by default :param dont_extend_height: When `True`, don't take up more width than the preferred height, i.e. the number of lines of the text. `False` by default. rNTFc |_dfd }tfd_tj|t dd|z||||_y) Nc[tj}t|}|r!td|j D}n t dSt |SS)Nc32K|]}t|ywr_r;).0lines r[ z4Label.__init__..get_width..js&VDz$'7&Vsr) preferred)rrrmax splitlinesr)text_fragmentsr longest_linerbrs r[ get_widthz!Label.__init__..get_widthesT}!2499!=,^<#&&VDOODU&V#VLq>)<00 rZcjSr_rrasr[rcz Label.__init__..qs  rZrr?rz class:label )rrrrwrralignrrr-)rr+formatted_text_controlr(rr) rbrrwrrrrrrs ` ` r[rzLabel.__init__WsT  ';@Q&R#//8 5(1/!   rZc|jSr_rras r[rzLabel.__pt_container__~rrZ)rrrwrrr-rrrrrz'WindowAlign | Callable[[], WindowAlign]rrrrr)rOrPrQrRr)LEFTrrrYrZr[rBrBDs|*"#'"'9D9I9I$(% % %  % ! %  % 7% !%  % NrZrBcPeZdZdZ d ddZd dZd dZd dZy) rCaS Clickable button. :param text: The caption for the button. :param handler: `None` or callable. Called when the button is clicked. No parameters are passed to this callable. Use for instance Python's `functools.partial` to pass parameters to this callable if needed. :param width: Width of the button. Nc  |_|_|_|_|_t j jd_dfd }tjtjd||dd_ y)NT) key_bindingsr|cNtjjryy)Nzclass:button.focusedz class:button)r layoutrrasr[ get_stylez"Button.__init__..get_stylesy))$/-%rZr?F)rrrrwrrr) r left_symbol right_symbolhandlerrr+_get_text_fragments_get_key_bindingsrr(r)CENTERr)rbrrrrrrs` r[rzButton.__init__s &(  +  $ $//1   & LL$$##  rZcpjtjtjzz t j tj z z}dt d|djj }dfd }dj|fdd||fdj|fgS) Nz{:^r}c|j/|jtjk(rjyyyr_)r event_typer:MOUSE_UP mouse_eventrbs r[rz+Button._get_text_fragments..handlers5 (**n.E.EE F)rZzclass:button.arrowz[SetCursorPosition]rzclass:button.textrr9rr)rr<rrlenrrformat)rbrrrs` r[rzButton._get_text_fragmentss JJ$**+j9J9J.KK M499~ 499 55 7  s1e}oR(00; "4#3#3W = ' $ 0 !4#4#4g >   rZcxt}|jd|jddfd }|S)zKey bindings for the Button. enterc@jjyyr_)reventrbs r[_z#Button._get_key_bindings.._s||' (rZrErr)radd)rbkbrs` r[rzButton._get_key_bindingss; ]       rZc|jSr_rras r[rzButton.__pt_container__rrZ)N <>) rrrzCallable[[], None] | Nonerintrrrrrrrr)rrr)rOrPrQrRrrrrrYrZr[rCrCsd.2 ' ' +'  '  '  '  ' R , rZrCcLeZdZdZ d ddZddZy)rDa Draw a border around any container, optionally with a title text. Changing the title and body of the frame is possible at runtime by assigning to the `body` and `title` attributes of this class. :param body: Another container object. :param title: Text to be displayed in the top of the frame (can be formatted text). :param style: Style string to be applied to this widget. Nc |_|_ttd}d|z}t |ddt j |t j|dddtfdd d |ddd|t j|ddt jgd } t |ddt j |t j|ddt jgd } tdfd } tt| | | t |dt jtfd|dt jgdt |ddt j|t j|ddt j gd g|||||_y)Nzclass:frame.borderrvz class:frame r?)rrchar)r|cLtdjjS)Nz {} )rrtitlerasr[rcz Frame.__init__..sHV,33DJJ?rZzclass:frame.labelT)rwrrc.tjSr_)rrrasr[ has_titlez!Frame.__init__..has_titles # #rZ)rrualternative_contentrrcjSr_)bodyrasr[rcz Frame.__init__.."s rZr)padding)rrrwrmodalrr)rrrr(r'rNrUrSrBrVrr&r!rTr#rWrX container) rbrrrwrrrrfilltop_row_with_titletop_row_without_titlers ` r[rzFrame.__init__s  v%9:&#1QV__=&++,1QS1?-&* 1QS1&++,1QV-=-=> ! &!'1QV__=&++,1QV-=-=>   !   $  $ $.$(= 16??;():;16??; 1QV5G5GH&"3"341QV5H5HI ! 4%?  rZc|jSr_rras r[rzFrame.__pt_container__: ~~rZ)rrNNNF)rr rrrwrrr-rr-rKeyBindings | NonerrrrrrOrPrQrRrrrYrZr[rDrDs} #%"#+/P P  P  P  P  P )P P  P drZrDc eZdZdZddZddZy)rEz Draw a shadow underneath/behind this container. (This applies `class:shadow` the the cells under the shadow. The Style should define the colors for the shadow.) :param body: Another container object. ct|tdddddtdtdddddtdg|_y) Nr?Tz class:shadowrv)bottomrleftright transparentr)r toprr rrrfloats)r%r$r(r)rbrs r[rzShadow.__init__GsV' $"8  $"8  rZc|jSr_rras r[rzShadow.__pt_container__^rrZN)rr rrrrrYrZr[rErE>s .rZrEcjeZdZdZ d ddZddZy)rFa@ Add padding around a container. This also makes sure that the parent can provide more space than required by the child. This is very useful when wrapping a small element with a fixed size into a ``VSplit`` or ``HSplit`` object. The ``HSplit`` and ``VSplit`` try to make sure to adapt respectively the width and height, possibly shrinking other elements. Wrapping something in a ``Box`` makes it flexible. :param body: Another container object. :param padding: The margin to be used around the body. This can be overridden by `padding_left`, padding_right`, `padding_top` and `padding_bottom`. :param style: A style string. :param char: Character to be used for filling the space around the body. (This is supposed to be a character with a terminal width of 1.) Nc ,|_|_|_|_|_|_dfd } dfd }dfd }dfd }t t|| tt| | |t|| gt|| g||| | d_ y) NcLj jSjSr_) padding_leftrrasr[r zBox.__init__..lefts%  (||#$$ $rZcLj jSjSr_) padding_rightrrasr[r zBox.__init__..rights%!!)||#%% %rZcLj jSjSr_) padding_toprrasr[rzBox.__init__..tops%'||### #rZcLj jSjSr_)padding_bottomrrasr[r zBox.__init__..bottoms%""*||#&& &rZ)rrr)rrrwrrr) rrrrrrr&r(r'r)rbrrrrrrrrrwrrrr r rr s` r[rz Box.__init__us (*&,  %  &  $  '  c-T5U6f40 ! rZc|jSr_rras r[rzBox.__pt_container__rrZ) NNNNNNNrNFN)rr rr-rr-rr-rr-rr-rr-rr-rwrrzNone | str | Callable[[], str]rrrrrrrrrYrZr[rFrFbs*!%%)&*$('+"#/3+/; ; ; # ; $ ; " ; %; ; ; ; -; ; );  ; zrZrF_TceZdZdZ d ddZd dZd dZd dZy) _DialogListz9 Common code for `RadioList` and `CheckboxList`. Nc ^t|dkDsJ|xsg}|_|_|_|_|_|_|_| _| _ | _ | _ | _ |Dcgc]\}}| }}}|Dcgc] }||vs| c}_ t|r |d|vr|dn|dd_tjdkDr$|jjd_nd_t#}|j%d|j%ddfd }|j%d|j%ddfd }|j%ddfd }|j%d dfd }|j%d |j%d dfd }|j%t&j(dfd }t+fd}t-ddD]*}|j%t/|||fdfd },t1j2|d|_t7j4j t9t;dt+fdgd_ycc}}wcc}w)Nrupkchtdjdz _rjyy)Nrr?)r_selected_index _handle_enterrselect_on_focusrbs r[_upz!_DialogList.__init__.._ups3$'q$*>*>*B#CD ""$rZdownjcttjdz jdz_rj yyNr?rrvaluesr%r&r's r[_downz#_DialogList.__init__.._downsB$'s4;;'7!';T=Q=QTU=U#VD ""$rZpageupc|jjj}|jr._pageupsP   //A}}'*t++c!--2O2O.PP($rZpagedownc|jjj}|jrRt t j dz jt |jjz_yyr-) r3rr4r5rrr/r%r6r7s r[ _pagedownz'_DialogList.__init__.._pagedown s_   //A}}'* $q(((3q}}/L/L+MM($rZrrc&jyr_)r&rs r[_clickz$_DialogList.__init__.._clicks    rZcDtj}|jdzd|zD]r}tt |dj }|j |jj sRjj|_yyr-) listr/r%rrlower startswithdataindex)rr/rrrbs r[_findz#_DialogList.__init__.._finds$++&F 4 4q 8 :;fD ,->uQx-HIOOQ??5::#3#3#56+/;;+<+.%s D,=,=rZr? )ructtjdz |dz _rj yyr-r.)rrDr(rbs r[ _select_iz'_DialogList.__init__.._select_i)s8'*3t{{+;a+?'K$"&&(#rZT)rr| show_cursorr~cjSr_)show_scrollbarrasr[rcz&_DialogList.__init__..=s T-@-@rZ)marginru)rrwrrr)rrrDrrr)rr/rGopen_characterselect_characterclose_charactercontainer_style default_style number_styleselected_style checked_stylemultiple_selectionrMcurrent_values current_valuerDr%rrrAnyrrangerr+rrr(r/r1r)rbr/default_valuesr(rOrPrQrRrSrTrUrVrWrMrKrGrrkeysrr)r0r9r<r>rEnumbers_visibleirJs` ` r[rz_DialogList.__init__s$6{Q'-2 (, 0..*(,*"4,399JUA%99-) $E)  >"~a'8D'@ 1 1  t"" #a '#'::d.A.A!.D#ED #$D ]   %   %   %   %             !   !     $$=>q" )A VVCF?V 312 )4 ) ),  $ $#   LL&&!*$?$%@A $   i:) s2 J$ J*J*c"|jrb|j|jd}||jvr|jj |y|jj |y|j|jd|_yr)rWr/r%rXremoveappendrY)rbvals r[r&z_DialogList._handle_enterCsv  " "++d223A6Cd)))##**3/##**3/!%T-A-A!B1!ED rZc d fd }g}tjD]\}}jr|djv}n|djk(}|j k(}d}|r|dj zz }|r|djzz }|j|jf|r|jd|r|j|jfn|j|df|j|jf|j|djdfjr)|j|dj|dzddf|jt!|d|dj |jd t#t%|D]}||d||d|f||<|j'|S) Nc|jtjk(r,|jj_j yy)z Set `_selected_index` and `current_value` according to the y position of the mouse click event. N)rr:rpositionyr%r&rs r[ mouse_handlerz6_DialogList._get_text_fragments..mouse_handlerNs? %%)@)@@'2';';'='=$""$ArZrrrrr?2dz. rv)r r) enumerater/rWrXrYr%rVrUrbrOrPrQrSrGrTextendrr[rpop)rbrhresultr_rcheckedselectedrws` r[rz_DialogList._get_text_fragmentsMs %&(!$++. &HAu&&(d&9&99(d&8&88D000HEt1111t2222 MM5$"5"56 7 9: ud&;&;<= ucl+ MM5$"6"67 8 MMeWAd&8&8%9:C@ A   %$*;*;)<=!a%2OP MM!%(UG1T=O=Od|fg}t||||_y)Nr)r/)ryrro)rbrror/r{s r[rzCheckbox.__init__s&D/" ' rZcd|jvSNrrXras r[rozCheckbox.checkeds$----rZc(|r dg|_yg|_yrrrs r[rozCheckbox.checkeds #*)D "$D rZ)rF)rrrorrrr)rrrr) rOrPrQrRrMrrrorrrs@r[rKrKs@ N .. ^^%%rZrKc eZdZdZddZddZy)rGz3 A simple vertical line with a width of 1. cFttjdd|_y)Nzclass:line,vertical-liner?)rrwr)r(rNrTrras r[rzVerticalLine.__init__s(B!  rZc|jSr_rras r[rzVerticalLine.__pt_container__rrZNrurrrYrZr[rGrG rZrGc eZdZdZddZddZy)rHz6 A simple horizontal line with a height of 1. cFttjdd|_y)Nzclass:line,horizontal-liner?)rrwr)r(rNrSrras r[rzHorizontalLine.__init__s""*Fq  rZc|jSr_rras r[rzHorizontalLine.__pt_container__rrZNrurrrYrZr[rHrHrrZrHcTeZdZddZeddZej ddZd dZy) rLcd_td_tt dt jddt ddddt t dfd t d fd  g g _y)N<z60%r?rr)rrr zclass:progress-bar.usedcBttjS)Nweightrr _percentagerasr[rcz&ProgressBar.__init__.."sas4;K;K7L.MrZ)rwrzclass:progress-barcHttdjz S)Ndrrrasr[rcz&ProgressBar.__init__..&sas3AQAQ;Q7R.SrZ)r rr r rr)rrBlabelr%r(r$r'rras`r[rzProgressBar.__init__ s5\ '!$ djja:""&?&M#&:&S     rZc|jSr_)rras r[ percentagezProgressBar.percentage.srZc:||_|d|j_y)N%)rrrrs r[rzProgressBar.percentage2s "G1+ rZc|jSr_rras r[rzProgressBar.__pt_container__7rrZNru)rr)rrrrr)rOrPrQrrrrrrYrZr[rLrL s; B  &&rZrLN)irR __future__r functoolsrtypingrrrr"prompt_toolkit.application.currentr prompt_toolkit.auto_suggestr r prompt_toolkit.bufferr r prompt_toolkit.completionrrprompt_toolkit.documentrprompt_toolkit.filtersrrrrrrprompt_toolkit.formatted_textrrrr#prompt_toolkit.formatted_text.utilsrprompt_toolkit.historyr'prompt_toolkit.key_binding.key_bindingsr(prompt_toolkit.key_binding.key_processorrprompt_toolkit.keysr prompt_toolkit.layout.containersr r!r"r#r$r%r&r'r(r)prompt_toolkit.layout.controlsr*r+r,prompt_toolkit.layout.dimensionr-r.rprompt_toolkit.layout.marginsr/r0r1 prompt_toolkit.layout.processorsr2r3r4r5r6prompt_toolkit.lexersr7r8prompt_toolkit.mouse_eventsr9r:prompt_toolkit.utilsr<prompt_toolkit.validationr=r>toolbarsr@__all__rrNrArBrCrDrErFrr rIrJrrKrGrHrLrYrZr[rsd #776G=A, F*?B$    9: 6B+A# QQh;;|WWt__D!!HQQh T]I'"+IX. B. b ;r? B%|C %2    ,,rZ