)L i;jddlmZddlZddlmZddlmZmZmZm Z m Z m Z ddl m Z ddlmZddlmZddlmZdd lmZdd lmZmZmZmZmZdd lmZmZmZdd l m!Z!dd l"m#Z#ddl$m%Z%m&Z&ddl'm(Z(ddl)m*Z*m+Z+m,Z,m-Z-ddl.m/Z/m0Z0m1Z1ddl2m3Z3ddl4m5Z5erddl6m7Z7m8Z8ddgZ9e!Z:Gdde1Z; d" d#dZ< d$dZ=Gdde*Z>Gdde1Z?Gdde+Z@Gd d!e1ZAy)%) annotationsN) zip_longest) TYPE_CHECKINGCallableIterableSequenceTypeVarcast)WeakKeyDictionary)get_app)CompletionState) Completion)Point) Condition FilterOrBoolhas_completionsis_done to_filter)StyleAndTextTuplesfragment_list_widthto_formatted_text) KeyPressEvent)explode_text_fragments) MouseEventMouseEventType) get_cwidth)ConditionalContainerHSplit ScrollOffsetsWindow)GetLinePrefixCallable UIContent UIControl) Dimension)ScrollbarMargin) KeyBindingsNotImplementedOrNoneCompletionsMenuMultiColumnCompletionsMenuceZdZdZdZd dZddZ ddZddZddZ ddZ dd Z dd Z dd Z y )CompletionsMenuControlaJ Helper for drawing the complete menu to the screen. :param scroll_offset: Number (integer) representing the preferred amount of completions to be displayed before and after the current one. When this is a very high number, the current completion will be shown in the middle most of the time. cyNFselfs a/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/prompt_toolkit/layout/menus.py has_focusz CompletionsMenuControl.has_focus@ctjj}|r)|jd|}|j d|}||zSy)Nir)r current_buffercomplete_state_get_menu_width_get_menu_meta_width)r2max_available_widthr9 menu_widthmenu_meta_widths r3preferred_widthz&CompletionsMenuControl.preferred_widthCsJ 11@@ --c>BJ"77^LO/ /r6cntjj}|rt|jSyNr)r r8r9len completions)r2widthmax_available_height wrap_linesget_line_prefixr9s r3preferred_heightz'CompletionsMenuControl.preferred_heightMs.!11@@ ~112 2r6cd tjj}|r|j|jj ||j |z |j| d fd }t|tdxsdtStS)z= Create a UIContent object for this control. cj|}|k(}t||d} r|j||z }|S)NT space_after)_get_menu_item_fragments_get_menu_item_meta_fragments) icis_current_completionresultrCindexr>r=r2 show_metas r3get_linez7CompletionsMenuControl.create_content..get_linejsUN()U %1,jdd@@0/F r6r)xy)rUcursor_position line_countrOintreturnr) r r8r9rCcomplete_indexr:r; _show_metar#rrB) r2rDheightr9rUrCrSr>r=rTs ` @@@@@r3create_contentz%CompletionsMenuControl.create_contentZs!11@@ (44K"11E--e^DJ"77 "NO7I  ! %UZa 8{+  {r6c:td|jDS)zT Return ``True`` if we need to show a column with meta information. c34K|]}|jywN)display_meta_text.0rPs r3 z4CompletionsMenuControl._show_meta..sK11&&K)anyrC)r2r9s r3r^z!CompletionsMenuControl._show_metasK0J0JKKKr6c |t|t|jtd|jDdzS)z6 Return the width of the main column. c3FK|]}t|jywrcr display_textres r3rgz9CompletionsMenuControl._get_menu_width..sS1Jq~~.S!)minmax MIN_WIDTHrC)r2 max_widthr9s r3r:z&CompletionsMenuControl._get_menu_widths=  S8R8RSSVWW   r6cdd|j|r@|j}t|dkDr|dd}t|t fd|DdzSy)z6 Return the width of the meta column. c,t|jSrcrrd) completions r3 meta_widthz?CompletionsMenuControl._get_menu_meta_width..meta_widthsj::; ;r6Nc3.K|] }|ywrcr0)rfrPrxs r3rgz>CompletionsMenuControl._get_menu_meta_width..s%Ijm%Isror)rwrr\r[)r^rCrBrprq)r2rsr9rCrxs @r3r;z+CompletionsMenuControl._get_menu_meta_widths\ < ??> *)44K;#%)$3/ y#%I[%I"IA"MN Nr6c|rd}nd}t|j|dz \}}d|dz |z z}tttgdgz|zd|fgz|S) Nz-class:completion-menu.meta.completion.currentz%class:completion-menu.meta.completionro rr|r~style)_trim_formatted_text display_metarr r)r2rwrQrD style_strtexttwpaddings r3rNz4CompletionsMenuControl._get_menu_item_meta_fragmentsso !GI?I' (?(?KbR( #R (I; 6 ="g O  r6ctj}|jtjk(r-|j |j jd|_y|jtjk(r|jddy|jtjk(r|jddy)z> Handle mouse events: clicking and scrolling. NTcountdisable_wrap_around) r r8 event_typerMOUSE_UPgo_to_completionpositionrWr9 SCROLL_DOWN complete_next SCROLL_UPcomplete_previous)r2 mouse_eventbs r3 mouse_handlerz$CompletionsMenuControl.mouse_handlers I $ $  ! !^%<%< <  {3355 6#A  # #~'A'A A OO!O >   # #~'?'? ?  aT  Br6Nr\boolr<r[r\ int | None rDr[rEr[rFrrGzGetLinePrefixCallable | Noner\rrDr[r_r[r\r#)r9r r\r)rsr[r9r r\r[)rwrrQrrDr[r\rrrr\r()__name__ __module__ __qualname____doc__rrr4r?rHr`r^r:r;rNrr0r6r3r,r,1sI  "   6   #JL  .= * $ =A JM  r6r,c |rd|jd|j}nd|jz}t|j|r|dz n|dz \}}d|dz |z z}t t t gdgz|zd|fgz|S) z_ Get the style/text tuples for a menu item, styled and trimmed to the given width. z)class:completion-menu.completion.current r|z!class:completion-menu.completion rorr}r~r)rselected_stylerdisplayrr r)rwrQrDrLrrrrs r3rMrMs? @P@P?QQRS]SlSlRmn 7*:J:JJ #+UQY519HD"UQY^$G  $ {2T9b']OK r6ct|}||kDrZg}|dz }t|D]-}t|d}||kr|j|||z}-n|jd|||z fS||fS)zo Trim the text to `max_width`, append dots when the text is too long. Returns (text, width) tuple. rr)r~z...)rrrappend)formatted_textrsrDrRremaining_width style_and_chch_widths r3rrs  /E y#a-2>B L!,q/2H?* l+8+   k"y?222u$$r6cBeZdZ d dfd ZxZS)r)c t|}t|}t| tt t dt d|t ||t|gdd| |tztz y) Nrpr)rprq)topbottom)display_arrowsTclass:completion-menu)contentrDr_scroll_offsets right_marginsdont_extend_widthrz_indexrfilter) rsuper__init__r!r,r%r r&rr)r2 max_height scroll_offset extra_filterrr __class__s r3rzCompletionsMenu.__init__ sz!. ">2 .0A& QJ7,}U.nMN"&-  /1WH<  r6)NrTF) rrrzint | Callable[[], int]rrrrrr[r\None)rrrr __classcell__rs@r3r)r)sX "&12%)',   / #  %       r6creZdZdZdZd ddZddZddZddZ ddZ ddZ dd Z dd Z dd Z y ) MultiColumnCompletionMenuControla Completion menu that displays all the completions in several columns. When there are more completions than space for them to be displayed, an arrow is shown on the left or right side. `min_rows` indicates how many rows will be available in any possible case. When this is larger than one, it will try to use less columns and more rows until this value is reached. Be careful passing in a too big value, if less than the given amount of rows are available, more columns would have been required, but `preferred_width` doesn't know about that and reports a too small value. This results in less completions displayed and additional scrolling. (It's a limitation of how the layout engine currently works: first the widths are calculated, then the heights.) :param suggested_max_column_width: The suggested max width of a column. The column can still be bigger than this, but if there is place for two columns of this width, we will display two columns. This to avoid that if there is one very wide completion, that it doesn't significantly reduce the amount of columns. rc|dk\sJ||_||_d|_t|_d|_d|_d|_i|_d|_ d|_ d|_ y)NrrF) min_rowssuggested_max_column_widthscrollr "_column_width_for_completion_state_rendered_rows_rendered_columns_total_columns_render_pos_to_completion_render_left_arrow_render_right_arrow _render_width)r2rrs r3rz)MultiColumnCompletionMenuControl.__init__>sn1}}  *D'    /  !"LN&"'#( r6cd|_yrA)rr1s r3resetz&MultiColumnCompletionMenuControl.resetXs  r6cyr/r0r1s r3r4z*MultiColumnCompletionMenuControl.has_focus[r5r6c tjj}|y|j|}t |t j t|jt|jz z}||kDr/|||jz kDr||z}||kDr|||jz kDr||jzS)z{ Preferred width: prefer to use at least min_rows, but otherwise as much as possible horizontally. r) r r8r9_get_column_widthr[mathceilrBrCfloatr_required_margin)r2r<r9 column_widthrRs r3r?z0MultiColumnCompletionMenuControl.preferred_width^s !11@@  !--n=  iiN667% :NNO P  \ !,t/D/DDD l "F \ !,t/D/DDD----r6ctjj}|y|j|}t d||j z |z}t tjt|jt|z S)z^ Preferred height: as much as needed in order to display all the completions. rr) r r8r9rrqrr[rrrBrCr)r2rDrErFrGr9r column_counts r3rHz1MultiColumnCompletionMenuControl.preferred_heightwsu!11@@  !--n= 1ut'<'<<MN 499S!;!; ABC DEF Gxx fillvalue)iterr)niterablerargss r3grouperz@MultiColumnCompletionMenuControl.create_content..groupers%N#a'DT:: :r6cNduxrjduxrjk(S)z@Returns True when this completion is the currently selected one.N)r]current_completion)rwrPr9s r3rQzNMultiColumnCompletionMenuControl.create_content..is_current_completions8d*;"11=;::: r6rrrrozclass:scrollbarrrc|Srcr0)rOfragments_for_lines r3rUzAMultiColumnCompletionMenuControl.create_content..get_lines%a( (r6rUrYrc)rr[rz Iterable[_T]rz _T | Noner\zIterable[Sequence[_T | None]])rwrr\rrZ)r r8r9r#rrr rprrqrlistrCzipr]rrB enumeraterrMrangerrrrrrr)r2rDr_rrrrQHORIZONTAL_MARGIN_REQUIREDvisible_columnscolumns_rows_selected_columnrender_left_arrowrender_right_arrow row_indexrow fragments middle_row column_indexrVrUrPr9rs @@@r3r`z/MultiColumnCompletionMenuControl.create_contentsE!11@@  !; --n= )+& T]DH ; ;* ;7@ ; * ; &'"5#==|L  $99 9 \T-L-LL LLa%$*?*?"?L!PQ(B(BCDS(^$*88=A&H So.ORS.ST  !KK!O![[3uQx=?+JJ '.) NIs,.I"c%jAo5J!  "3JSC!PQ#  +$-S-?@P-Q#R O a=!903\u"I #<066)L81 >AS SVW W  )(s5zBBr6c |j|\}}|t|jk7rt|S#t$rHt d|jDdz}t|j|f|j|<|cYSwxYw)z2 Return the width of each column. c3FK|]}t|jywrcrlres r3rgzEMultiColumnCompletionMenuControl._get_column_width.. sU1Jq~~.Urnr)rrBrCKeyErrorrq)r2completion_staterrDrRs r3rz2MultiColumnCompletionMenuControl._get_column_widths BBCSTLE5,8899L U8H8T8TUU  $001ID 3 34D EM s14ABBcPtjdfd }dfd }|jtjk(r|y|jtj k(r|y|jtj k(r|jj}|jj}|dk(rjr|y|jdz k(rjr|yjj||f}|rj|y)z1 Handle scroll and click events. c|jjdtdjdz _y)NTrrr)rrrqrrr2sr3 scroll_leftzCMultiColumnCompletionMenuControl.mouse_handler..scroll_lefts2  d&9&9t  Taq1DKr6cjjdtjjz j dz_y)NTrr)rrrprrrrsr3 scroll_rightzDMultiColumnCompletionMenuControl.mouse_handler..scroll_rightsC OO$"5"54O P##d&<&<'> >$$&&A$$&&AAv**Md((1,,++ N ";;??AG &&z2r6cddlm}|}td fd }d d fd |jdd|dfd }|jdd|dfd }|S)zo Expose key bindings that handle the left/right arrow keys when the menu is displayed. r)r'ct}|jj}| |jyt fd|j j DS)z1Only handle key bindings if this menu is visible.Fc3<K|]}|jk(ywrcr)rfwindowr2s r3rgzTMultiColumnCompletionMenuControl.get_key_bindings..filter..TsW&v~~-Ws)r r8r9r]rilayoutvisible_windows)appr9r2s r3rzAMultiColumnCompletionMenuControl.get_key_bindings..filterIsP)C //>>N%)F)F)NWCJJ.moveVs9++D!00N)n.K.K.W*99 !4!44I!4!44I CC(B(B$CC)))4D/X)r6leftT) is_globalrcyrcr0eventrs r3_leftz@MultiColumnCompletionMenuControl.get_key_bindings.._lefths Fr6cdy)NTr0rs r3_rightzAMultiColumnCompletionMenuControl.get_key_bindings.._rightls Jr6rF)rrr\r)rEr\r)'prompt_toolkit.key_binding.key_bindingsr'radd)r2r'kbrrr rs` @r3get_key_bindingsz1MultiColumnCompletionMenuControl.get_key_bindings@sv H ]  X  X 5$ $v 6  7  4 7  8  r6N)r)rr[rr[r\rr rrrr)rr r\r[r)r\r')rrrrrrrr4r?rHr`rrr&r0r6r3rr%sv,4.2UU"U U 6 U  U&sCj**X0r6rcFeZdZdZ d dfd ZxZS)r*z Container that displays the completions in several columns. When `show_meta` (a :class:`~prompt_toolkit.filters.Filter`) evaluates to True, it shows the meta information at the bottom. c Nt|}t|}|tztz}td d}t t t ||tdtd|}t t t||z|z} t |)|| g| y) Nctjj}|duxrtd|jDS)Nc34K|]}|jywrc)rres r3rgzWMultiColumnCompletionsMenu.__init__..any_completion_has_meta..s6#$6rh)r r8r9rirC)r9s r3any_completion_has_metazDMultiColumnCompletionsMenu.__init__..any_completion_has_metasA$Y55DDN!-#6(6(B(B63 r6)rrrrr)rrDr_rr)rr) rrrrrr!rr%_SelectedCompletionMetaControlrr) r2rrrTrr full_filterr,completions_window meta_windowrs r3rz#MultiColumnCompletionsMenu.__init__zsi(  . #_4x?    28%/I A& Q'   +#A#CD*-DD ,k:GLr6)rr'TTr) rr[rr[rTrrrrr[r\r)rrrrrrrs@r3r*r*sse*,"&%) .M.M%(.M .M # .M  .M .M.Mr6cDeZdZdZddZ ddZd dZd dZy) r-zM Control that shows the meta information of the selected completion. ct}|jjrR|jj}t|jdk\r|Sdt d|jddDzSy)a? Report the width of the longest meta text as the preferred width of this control. It could be that we use less width, but this way, we're sure that the layout doesn't change when we select another completion (E.g. that completions are suddenly shown in more or fewer columns.) r'roc3FK|]}t|jywrcrvres r3rgzA_SelectedCompletionMetaControl.preferred_width..s 45 1../rnNdr)r r8r9rBrCrq)r2r<rstates r3r?z._SelectedCompletionMetaControl.preferred_widthsyi    , ,&&55E5$$%++*s9>9J9J4C9P r6cy)Nrr0)r2rDrErFrGs r3rHz/_SelectedCompletionMetaControl.preferred_heightsr6c\|jdfd }t|rdSdS)NcSrcr0)rOrs r3rUz?_SelectedCompletionMetaControl.create_content..get_lines  r6rrrrZ)_get_text_fragmentsr#)r2rDr_rUrs @r3r`z-_SelectedCompletionMetaControl.create_contents/,,.  (IqMM1MMr6cd}tjj}|rY|jrM|jjr7t t tdg|jjzdgz|SgS)Nz'class:completion-menu.multi-column-metar}r) r r8r9rrdrr rr)r2rr5s r3r9z2_SelectedCompletionMetaControl._get_text_fragmentss{9 ((77 ((((::$')5**778+   r6Nrrr)r\r)rrrrr?rHr`r9r0r6r3r-r-sL6"  6   Nr6r-r!) rwrrQrrDr[rLrr\r)rrrsr[r\ztuple[StyleAndTextTuples, int])B __future__rr itertoolsrtypingrrrrr r weakrefr "prompt_toolkit.application.currentr prompt_toolkit.bufferr prompt_toolkit.completionrprompt_toolkit.data_structuresrprompt_toolkit.filtersrrrrrprompt_toolkit.formatted_textrrr(prompt_toolkit.key_binding.key_processorrprompt_toolkit.layout.utilsrprompt_toolkit.mouse_eventsrrprompt_toolkit.utilsr containersrrr r!controlsr"r#r$ dimensionr%marginsr&r#r'r(__all__r"r,rMrr)rr*r-r0r6r3rNs" !MM%6100 C>B+KKAA $   XYX~     6%&%36%#%< * @KyK\ 5M5MpAYAr6