
    BNe+                       d Z ddlmZ ddlmZ ddlmZ ddlmZm	Z	m
Z
mZmZmZmZmZmZmZ ddlmZmZ ddlmZmZmZ ddlmZ dd	lmZmZmZmZm Z m!Z! dd
l"m#Z#m$Z$m%Z%m&Z& ddl'm(Z( ddl)m*Z*m+Z+ ddl,m-Z- ddl.m/Z/ ddl0m1Z1m2Z2m3Z3m4Z4 ddl5m6Z6 ddl7m8Z8m9Z9m:Z: ddl;m<Z< ddl=m>Z> ddl?m@Z@ ddlAmBZB ddlCmDZDmEZEmFZF ddlGmHZHmIZI ddlJmKZKmLZLmMZMmNZNmOZOmPZP ddlQmRZR ddlSmTZTmUZU ddlVmWZWmXZXmYZY ddlZm[Z[ ddl\m]Z]m^Z^m_Z_ ddl`maZambZb dd lcmdZd dd!lemfZfmgZgmhZh dd"limjZjmkZkmlZl dd#lmmnZnmoZompZp dd$lqmrZr dd%lsmtZt  eud&          Zd'gZverdd(lwmxZx  G d) d*ex          Zy ed+d*,          Zz G d- d.eez                   Z{ G d/ d0eez                   Z|eHj}        d1eHj~        d2eHj        d3eHj        d4iZeee	f         Ze
g ef         Z G d5 d'          Zd6S )7zV
Application for reading Python input.
This can be used for creation of Python REPLs.
    )annotations)get_event_looppartial)
TYPE_CHECKINGAnyCallableDictGenericListMappingOptionalTupleTypeVar)Applicationget_app)AutoSuggestFromHistoryConditionalAutoSuggestThreadedAutoSuggest)Buffer)	CompleterConditionalCompleterDynamicCompleterFuzzyCompleterThreadedCompletermerge_completers)AnyCursorShapeConfigCursorShapeDynamicCursorShapeConfigModalCursorShapeConfig)Document)DEFAULT_BUFFEREditingMode)	Condition)AnyFormattedText)FileHistoryHistoryInMemoryHistoryThreadedHistory)Input)ConditionalKeyBindingsKeyBindingsmerge_key_bindings)load_auto_suggest_bindings)load_open_in_editor_bindings)	InputMode)AnyContainer)DynamicLexerLexerSimpleLexer)
ColorDepthOutput)#AdjustBrightnessStyleTransformation	BaseStyleConditionalStyleTransformationDynamicStyle#SwapLightAndDarkStyleTransformationmerge_style_transformations)
is_windows)ConditionalValidator	Validator   )CompletePrivateAttributesHidePrivateCompleterPythonCompleter)PythonHistory)load_confirm_exit_bindingsload_python_bindingsload_sidebar_bindings)CompletionVisualisationPtPythonLayout)PtpythonLexer)ClassicPromptIPythonPromptPromptStyle)	Signatureget_signatures_using_evalget_signatures_using_jedi)generate_styleget_all_code_stylesget_all_ui_styles)unindent_code)PythonValidator
__future__PythonInput)Protocolc                      e Zd ZddZdS )_SupportsLessThan_SupportsLessThan__otherr   returnboolc                    d S N )selfr[   s     /home/feoh/.cache/pypoetry/virtualenvs/veilid-python-play-bIboZq2W-py3.11/lib/python3.11/site-packages/ptpython/python_input.py__lt__z_SupportsLessThan.__lt__k   s    C    N)r[   r   r\   r]   )__name__
__module____qualname__rc   r`   rd   rb   rZ   rZ   h   s(        	 	 	 	 	 	rd   rZ   _T)boundc                      e Zd Zd	dZdS )
OptionCategorytitlestroptionslist[Option[_T]]r\   Nonec                "    || _         || _        d S r_   )rl   rn   )ra   rl   rn   s      rb   __init__zOptionCategory.__init__s   s    
rd   N)rl   rm   rn   ro   r\   rp   )re   rf   rg   rr   r`   rd   rb   rk   rk   r   s(             rd   rk   c                  D    e Zd ZdZddZedd            ZdddZddZdS )Optional  
    Ptpython configuration option that can be shown and modified from the
    sidebar.

    :param title: Text.
    :param description: Text.
    :param get_values: Callable that returns a dictionary mapping the
            possible values to callbacks that activate these value.
    :param get_current_value: Callable that returns the current, active value.
    rl   rm   descriptionget_current_valueCallable[[], _T]
get_values/Callable[[], Mapping[_T, Callable[[], object]]]r\   rp   c                >    || _         || _        || _        || _        d S r_   rl   ru   rv   rx   )ra   rl   ru   rv   rx   s        rb   rr   zOption.__init__   s&     
&!2$rd   !Mapping[_T, Callable[[], object]]c                *    |                                  S r_   )rx   ra   s    rb   valueszOption.values   s       rd   F	_previousr]   c                @   |                                  }t          | j                                                  }	 |                    |          }n# t
          $ r d}Y nw xY w|r|dz  }n|dz  }||t          |          z           } | j        |                      dS )z&
        Activate next value.
        r   r@   N)rv   sortedr   keysindex
ValueErrorlen)ra   r   currentrn   r   next_options         rb   activate_nextzOption.activate_next   s     ((**))++,,	MM'**EE 	 	 	EEE	  	QJEEQJE ec'll23 K """""s   A A! A!c                2    |                      d           dS )z*
        Activate previous value.
        T)r   N)r   r~   s    rb   activate_previouszOption.activate_previous   s!     	T*****rd   N)
rl   rm   ru   rm   rv   rw   rx   ry   r\   rp   )r\   r|   )F)r   r]   r\   rp   r\   rp   )	re   rf   rg   __doc__rr   propertyr   r   r   r`   rd   rb   rt   rt   x   s        	 	% % % % ! ! ! X!# # # # #.+ + + + + +rd   rt   
MonochromezANSI Colorsz
256 colorsz
True colorc                     e Zd ZdZ	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 dIdJdZdKd"ZedLd$            ZedMd&            ZdLd'Z	edNd)            Z
dOd.ZdPd/ZdOd0ZdPd1ZdQd4ZdRd7ZdRd8ZdSd9ZdTd;ZdUd=ZdVd>ZedWd@            Zej        dXdA            ZedYdB            Zej        dZdC            Zed[dD            Zd\dEZd]dFZd]dGZd^dHZdS )_rW   a  
    Prompt for reading Python input.

    ::

        python_input = PythonInput(...)
        python_code = python_input.app.run()

    :param create_app: When `False`, don't create and manage a prompt_toolkit
                       application. The default is `True` and should only be set
                       to false if PythonInput is being embedded in a separate
                       prompt_toolkit application.
    NFTget_globals_GetNamespace | None
get_localshistory_filename
str | Nonevi_moder]   color_depthColorDepth | NoneinputInput | NoneoutputOutput | Noneextra_key_bindingsKeyBindings | None
create_app
_completerCompleter | None
_validatorValidator | None_lexerLexer | None_extra_layout_bodyAnyContainer | Noner\   rp   c                	    |pd  _         |p j          _        |
pt           j          j         fd           _        t	          t          t          t          t           fd                    t           fd                    t           fd          gd           fd           _
        |pt           j                   _        t          |           _          |r"t!          t#          |                     _        nt'                       _        | _        | _        |pg  _        |pg  _        |pt1                       _        d	 _        d
 _        d
 _        d _        t<          j         _         d _!        d
 _"        d _#        d _$        d _%        d
 _&        d _'        d _(        d _)        d _*        d _+        d
 _,        d
 _-        d
 _.        d _/        d
 _0        d
 _1        td          j3         _4        d
 _5        d
 _6        d
 _7        d
 _8        d
 _9        d _:        d
 _;        d  _<        d _=        d _>        d
 _?         @                                 _A        t                       _C        t          d           _D        d _E        t          jG        t          jH        t          jI        t                      t          jK        t          jL        t          jM        d _N        d _O        t                     t                      d _R         fd _S         fd _T        t                       _V        t                       _X        d _Y        d _Z        t                      rd _Y         \                                 _]        |pt          j_                     _`        d _a        d _b         c                                 _d        d _e        d _f        g  _g        d
 _h        d
 _i        d
 _j        t          t          t                      t           fd                    t           fd fd          g           _o        t           t           fd           j         j         j         j                   _r        |	r7 s                    ||           _t        |rt          jv         jw        _x        d S d S d  _t        d S ) Nc                     i S r_   r`   r`   rd   rb   <lambda>z&PythonInput.__init__.<locals>.<lambda>   s    " rd   c                      j         S r_   enable_dictionary_completionr~   s   rb   r   z&PythonInput.__init__.<locals>.<lambda>   s
    D5 rd   c                      j         S r_   	completerr~   s   rb   r   z&PythonInput.__init__.<locals>.<lambda>   s	     rd   c                      j         S r_   enable_fuzzy_completionr~   s   rb   r   z&PythonInput.__init__.<locals>.<lambda>   s
    $*F rd   c                      j         S r_   r   r~   s   rb   r   z&PythonInput.__init__.<locals>.<lambda>   s	    T^ rd   T)deduplicatec                      j         S r_   )complete_private_attributesr~   s   rb   r   z&PythonInput.__init__.<locals>.<lambda>   s
    D4 rd    Fr@      zDo you really want to exit?)	read_onlyBlock)r   	UnderlineBeamz
Modal (vi)zBlink blockzBlink underz
Blink beamclassic)ipythonr   c                 L     j          j                                                 S r_   )all_prompt_stylesprompt_style	in_promptr~   s   rb   r   z&PythonInput.__init__.<locals>.<lambda>c  s!    (>)

)++ rd   c                 L     j          j                                                 S r_   )r   r   
out_promptr~   s   rb   r   z&PythonInput.__init__.<locals>.<lambda>g  s!    )?*

*,, rd   defaultwin32g      ?g        r   c                      j         S r_   )swap_light_and_darkr~   s   rb   r   z&PythonInput.__init__.<locals>.<lambda>  s
    T-E rd   )filterc                      j         S r_   min_brightnessr~   s   rb   r   z&PythonInput.__init__.<locals>.<lambda>  s
    D/ rd   c                      j         S r_   max_brightnessr~   s   rb   r   z&PythonInput.__init__.<locals>.<lambda>  s
    9L rd   c                 <     j         r j        nt                      S r_   )enable_syntax_highlightingr   r4   r~   s   rb   r   z&PythonInput.__init__.<locals>.<lambda>  s     2# ]] rd   )lexerinput_buffer_heightextra_buffer_processors
extra_bodyextra_toolbars)yr   r   rC   r   rB   r   r   r   r   r$   r   rU   get_compiler_flagsr   rJ   r   r)   r&   historyr(   _input_buffer_heightr   _extra_toolbars_extra_buffer_processorsr,   r   rl   show_signatureshow_docstringshow_meta_enter_messagerH   MULTI_COLUMNcompletion_visualisationcompletion_menu_scroll_offsetshow_line_numbersshow_status_bar
wrap_linescomplete_while_typing
paste_modeconfirm_exitaccept_input_on_enterenable_open_in_editorenable_system_bindingsenable_input_validationenable_auto_suggestenable_mouse_supportenable_history_searchr   r   r   rA   ALWAYSr   r   highlight_matching_parenthesisshow_sidebarenable_output_formattingenable_pagershow_sidebar_helpshow_exit_confirmationterminal_titleexit_messageinsert_blank_line_after_outputinsert_blank_line_after_input_create_bufferdefault_bufferr   search_bufferdocstring_buffercursor_shape_configr   BLOCK	UNDERLINEBEAMr    BLINKING_BLOCKBLINKING_UNDERLINEBLINKING_BEAMall_cursor_shape_configsr   rL   rK   r   get_input_promptget_output_promptrR   code_stylesrS   	ui_styles_current_code_style_name_current_ui_style_namer=   _generate_style_current_styler5   r   r   r   r   _create_optionsrn   selected_option_indexcurrent_statement_index
signatures_get_signatures_thread_runningvi_start_in_navigation_modevi_keep_last_used_moder<   r9   r;   r7   style_transformationrI   r2   ptpython_layout_create_application_appr#   VIappediting_mode)ra   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   s   `                rb   rr   zPythonInput.__init__   ss   * +6*E**)3)Gt7G# 
O5555(
 (
 / (&'78N8N8N8N'O'OPP!"F"F"F"FGG  %%;%;%;%;<< !	 	 	 5444!
 
$ %P8O(P(P#F++ 	-*;7G+H+HIIDLL*,,DL$8!"4.4"(@(FB%"4"E (*
$)$)-1$#0 	% 34*',%) $+/" 	  	 +,"+/",0#-1$). */!+0"
 15'-2$27)%, 	( */ 49+"' /4%"' (, -2# +/!>48+38* #1133%+XX(.(>(>(> $+  &$.$022&5&9%3J
 J
% "+ %T**$:
 :

! ! ! !" " " "
 2E1F1F*,,-6%+4#<< 	4,3D)"2244'2'Jj6H6J6J%(%( ++--*+" -.$ ,. 5:+ 27( -2#$?.799$%E%E%E%EFF   4////1L1L1L1L 
%
 
%
!  .# # # # 
 !% 9$($A./ 
  
  
  	151I1I%QW1X1XDI  7(3%%%7 7 DIIIrd   buffr   c                    t                      }|                    |j                   |j                            |j                   dS )N)resultT)r   exittextpre_run_callablesappendreset)ra   r  r  s      rb   _accept_handlerzPythonInput._accept_handler  s?    ii	"""$$TZ000trd   intc                >    t          d | j        D                       S )zAReturn the total amount of options. (In all categories together.)c              3  >   K   | ]}t          |j                  V  d S r_   )r   rn   ).0categorys     rb   	<genexpr>z+PythonInput.option_count.<locals>.<genexpr>  s-      FFX3x'((FFFFFFrd   )sumrn   r~   s    rb   option_countzPythonInput.option_count  s#     FFFFFFFFrd   Option[Any]c                x    d}| j         D ]"}|j         D ]}|| j        k    r|c c S |dz  }#t          d          )z%Return the currently selected option.r   r@   zNothing selected)rn   r  r   )ra   ir*  os       rb   selected_optionzPythonInput.selected_option  sh      	 	H%  222HHHHHFAA	 +,,,rd   c                    d}|                                                                  D ]9}	 t          |t          j                  r|j        }||z  }*# t          $ r Y 6w xY w|S )zk
        Give the current compiler flags by looking for _Feature instances
        in the globals.
        r   )r   r   
isinstancerV   _Featurecompiler_flagBaseException)ra   flagsvaluefs       rb   r   zPythonInput.get_compiler_flags  s    
 %%''..00 	 	EeZ%899 +AQJE      s   &A
A A Callable[[_T], _T]c                      fd}|S )a'  
        Shortcut for adding new key bindings.
        (Mostly useful for a config.py file, that receives
        a PythonInput/Repl instance as input.)

        ::

            @python_input.add_key_binding(Keys.ControlX, filter=...)
            def handler(event):
                ...
        c                 (     j         j        | i |S r_   )r   add)kkwra   s     rb   add_binding_decoratorz:PythonInput.add_key_binding.<locals>.add_binding_decorator  s    .4*.8R888rd   r`   )ra   rA  s   ` rb   add_key_bindingzPythonInput.add_key_binding  s$    	9 	9 	9 	9 	9 %$rd   namerm   styler8   c                    || j         |<   dS )z2
        Install a new code color scheme.
        Nr	  ra   rC  rD  s      rb   install_code_colorschemez$PythonInput.install_code_colorscheme  s     "'rd   c                \    || j         v sJ || _        |                                 | _        dS z3
        Apply new colorscheme. (By name.)
        N)r	  r  r  r  ra   rC  s     rb   use_code_colorschemez PythonInput.use_code_colorscheme  s:     t'''''(,%"2244rd   c                    || j         |<   dS )z0
        Install a new UI color scheme.
        Nr
  rG  s      rb   install_ui_colorschemez"PythonInput.install_ui_colorscheme  s      %trd   c                \    || j         v sJ || _        |                                 | _        dS rJ  )r
  r  r  r  rK  s     rb   use_ui_colorschemezPythonInput.use_ui_colorscheme  s9     t~%%%%&*#"2244rd   depthr5   c                    || _         d S r_   r   )ra   rR  s     rb   _use_color_depthzPythonInput._use_color_depth  s     rd   r9  floatc                H    || _         t          | j        |          | _        d S r_   )r   maxr   ra   r9  s     rb   _set_min_brightnesszPythonInput._set_min_brightness  %    #!$"5u==rd   c                H    || _         t          | j        |          | _        d S r_   )r   minr   rY  s     rb   _set_max_brightnesszPythonInput._set_max_brightness  r[  rd   c                b    t          | j        | j                 | j        | j                           S )z
        Create new Style instance.
        (We don't want to do this on every key press, because each time the
        renderer receives a new style class, he will redraw everything.)
        )rQ   r	  r  r
  r  r~   s    rb   r  zPythonInput._generate_style  s1     T:;N467
 
 	
rd   list[OptionCategory[Any]]c                    dd fdd fd		 dd fd}d t          dd          D             t          dt          dd fdfd          t          dd fd fd           |dd d!"          t          d#d$ fd%fd&          t          d'd( fd)fd*          t          d+d, fd-fd.          t          d/d0 fd1fd2          t          d3d4 fd5fd6           |d7d8d9"           |d:d;d<"           |d=d>d?"           |d@dAdB"          t          dCdD fdEfdF          g          t          dGt          dHdI fdJfdK          t          dLdM fdN fdO           |dPdQdR"           |dSdTdU"           |dVdWdX"           |dYdZd["           |d\d]d^"           |d_d`da"           |dbdcdd"           |dedfdg"           |dhdidj"           |dkdldm"           |dndodp"           |dqdrds"          g          t          dt |dudvdw"           |dxdydz"          t          d{d| fd} fd~          t          dd fd fd          t          dd fd fd          t          dd fd fd          t          dd fd fd          g          gS )zN
        Create a list of `Option` instances for the options sidebar.
        T	attributerm   r9  r   r\   r]   c                *    t          | |           dS )NTsetattr)rb  r9  ra   s     rb   enablez+PythonInput._create_options.<locals>.enable,  s    D)U+++ 4rd   c                *    t          | d           dS )NFTrd  )rb  ra   s    rb   disablez,PythonInput._create_options.<locals>.disable2  s    D)U+++4rd   offonrl   ru   
field_namer   tuple[str, str]Option[str]c                P    dfd}dfd}t          | |||          S )	zCreate Simple on/of option.r\   rm   c                 J    t          t                                        S r_   )r]   getattr)rl  ra   r   s   rb   rv   zMPythonInput._create_options.<locals>.simple_option.<locals>.get_current_value>  s     d74#<#<==>>rd   dict[str, Callable[[], bool]]c                 8    d         fdd          fdiS )Nr@   c                                 S r_   r`   )rf  rl  s   rb   r   zXPythonInput._create_options.<locals>.simple_option.<locals>.get_values.<locals>.<lambda>C  s    vvj'9'9 rd   r   c                                 S r_   r`   )rh  rl  s   rb   r   zXPythonInput._create_options.<locals>.simple_option.<locals>.get_values.<locals>.<lambda>D  s    wwz':': rd   r`   )rh  rf  rl  r   s   rb   rx   zFPythonInput._create_options.<locals>.simple_option.<locals>.get_valuesA  s9    1I999991I::::: rd   )rl   ru   rx   rv   r\   rm   )r\   rr  )rt   )	rl   ru   rl  r   rv   rx   rh  rf  ra   s	     ``  rb   simple_optionz2PythonInput._create_options.<locals>.simple_option6  s    ? ? ? ? ? ? ? ?         '%"3	   rd   c                    g | ]}d |z  S )g?r`   )r)  r9  s     rb   
<listcomp>z/PythonInput._create_options.<locals>.<listcomp>N  s    HHH%X-HHHrd   r      r*   zEditing modezVi or emacs key bindings.c                 "    ddg j                  S )NEmacsVi)r   r~   s   rb   r   z-PythonInput._create_options.<locals>.<lambda>W  s    7D/$,2O rd   c                      fdfddS )Nc                       d          S Nr   r`   rh  s   rb   r   z?PythonInput._create_options.<locals>.<lambda>.<locals>.<lambda>Y  s    WWY-?-? rd   c                       d          S r  r`   rf  s   rb   r   z?PythonInput._create_options.<locals>.<lambda>.<locals>.<lambda>Z  s    &&*;*; rd   )r|  r}  r`   rh  rf  s   rb   r   z-PythonInput._create_options.<locals>.<lambda>X  s'    %?%?%?%?";";";";, , rd   r{   zCursor shapezAChange the cursor style, possibly according to the Vi input mode.c                      j         S r_   )r   r~   s   rb   r   z-PythonInput._create_options.<locals>.<lambda>a  s
    $2J rd   c                 D    t           fdj        D                       S )Nc              3  >   K   | ]}|t          d |          fV  dS )r   Nr   r)  srf  s     rb   r+  z@PythonInput._create_options.<locals>.<lambda>.<locals>.<genexpr>b  sI       0 0 ! 0Eq I IJ0 0 0 0 0 0rd   )dictr  rf  ra   s   rb   r   z-PythonInput._create_options.<locals>.<lambda>b  s:    4 0 0 0 0%)%B0 0 0 , , rd   z
Paste modez)When enabled, don't indent automatically.r   )rl   ru   rl  zComplete while typingzxGenerate autocompletions automatically while typing. Don't require pressing TAB. (Not compatible with "History search".)c                 "    ddg j                  S Nrj  rk  r   r~   s   rb   r   z-PythonInput._create_options.<locals>.<lambda>p      5$- 63 rd   c                      fd fddS )Nc                 0     d          o
  d          S )Nr   r   r`   r  s   rb   r   z?PythonInput._create_options.<locals>.<lambda>.<locals>.<lambda>t  )    &&1H*I*I +A '(? @ @ rd   c                       d          S )Nr   r`   r  s   rb   r   z?PythonInput._create_options.<locals>.<lambda>.<locals>.<lambda>v      773J+K+K rd   rk  rj  r`   r  s   rb   r   z-PythonInput._create_options.<locals>.<lambda>s  9    #A #A #A #A #A#K#K#K#K, , rd   zComplete private attrszShow or hide private attributes in the completions. 'If no public' means: show private attributes only if no public matches are found or if an underscore was typed.c                 f    t           j        dt           j        dt           j        di j                 S )NNeverAlwaysIf no public)rA   NEVERr   IF_NO_PUBLICr   r~   s   rb   r   z-PythonInput._create_options.<locals>.<lambda>~  s/    5;W5<h5BN3 :	3< rd   c                 "     fd fd fddS )Nc                 0      dt           j                  S Nr   )rA   r  r  s   rb   r   z?PythonInput._create_options.<locals>.<lambda>.<locals>.<lambda>  s    VV = 9 ?. . rd   c                 0      dt           j                  S r  )rA   r   r  s   rb   r   z?PythonInput._create_options.<locals>.<lambda>.<locals>.<lambda>  s    ff = 9 @/ / rd   c                 0      dt           j                  S r  )rA   r  r  s   rb   r   z?PythonInput._create_options.<locals>.<lambda>.<locals>.<lambda>  s    FF = 9 F5 5 rd   )r  r  r  r`   r  s   rb   r   z-PythonInput._create_options.<locals>.<lambda>  sK    & & & &' ' ' '- - - -, , rd   zEnable fuzzy completionzEnable fuzzy completion.c                 "    ddg j                  S r  r   r~   s   rb   r   z-PythonInput._create_options.<locals>.<lambda>  s    5$- 83 rd   c                     fd fddS )Nc                       d          S Nr   r`   r  s   rb   r   z?PythonInput._create_options.<locals>.<lambda>.<locals>.<lambda>  s    &&1J*K*K rd   c                       d          S r  r`   r  s   rb   r   z?PythonInput._create_options.<locals>.<lambda>.<locals>.<lambda>  s    773L+M+M rd   r  r`   r  s   rb   r   z-PythonInput._create_options.<locals>.<lambda>  s'    "K"K"K"K#M#M#M#M, , rd   zDictionary completionzEnable experimental dictionary/list completion.
WARNING: this does "eval" on fragments of
         your Python input and is
         potentially unsafe.c                 "    ddg j                  S r  r   r~   s   rb   r   z-PythonInput._create_options.<locals>.<lambda>  s    5$- =3 rd   c                     fd fddS )Nc                       d          S Nr   r`   r  s   rb   r   z?PythonInput._create_options.<locals>.<lambda>.<locals>.<lambda>  s    &&1O*P*P rd   c                       d          S r  r`   r  s   rb   r   z?PythonInput._create_options.<locals>.<lambda>.<locals>.<lambda>  s    773Q+R+R rd   r  r`   r  s   rb   r   z-PythonInput._create_options.<locals>.<lambda>  s'    "P"P"P"P#R#R#R#R, , rd   zHistory searchzWhen pressing the up-arrow, filter the history on input starting with the current text. (Not compatible with "Complete while typing".)c                 "    ddg j                  S r  r   r~   s   rb   r   z-PythonInput._create_options.<locals>.<lambda>  r  rd   c                      fd fddS )Nc                 0     d          o
  d          S )Nr   r   r`   r  s   rb   r   z?PythonInput._create_options.<locals>.<lambda>.<locals>.<lambda>  r  rd   c                       d          S )Nr   r`   r  s   rb   r   z?PythonInput._create_options.<locals>.<lambda>.<locals>.<lambda>  r  rd   r  r`   r  s   rb   r   z-PythonInput._create_options.<locals>.<lambda>  r  rd   zMouse supportzoRespond to mouse clicks and scrolling for positioning the cursor, selecting text and scrolling through windows.r   zConfirm on exitz"Require confirmation when exiting.r   zInput validationzgIn case of syntax errors, move the cursor to the error instead of showing a traceback of a SyntaxError.r   zAuto suggestionzfAuto suggest inputs by looking at the history. Pressing right arrow or Ctrl-E will complete the entry.r   zAccept input on enterzAmount of ENTER presses required to execute input when the cursor is at the end of the input. (Note that META+ENTER will always execute.)c                 0    t           j        pd          S )N
meta-enter)rm   r   r~   s   rb   r   z-PythonInput._create_options.<locals>.<lambda>  s    # 6F,3 3 rd   c                 *     fd fd fd fddS )Nc                       dd          S )Nr   r   r`   r  s   rb   r   z?PythonInput._create_options.<locals>.<lambda>.<locals>.<lambda>      0G)K)K rd   c                       dd          S )Nr      r`   r  s   rb   r   z?PythonInput._create_options.<locals>.<lambda>.<locals>.<lambda>  r  rd   c                       dd          S )Nr      r`   r  s   rb   r   z?PythonInput._create_options.<locals>.<lambda>.<locals>.<lambda>  r  rd   c                       dd           S )Nr   r`   r  s   rb   r   z?PythonInput._create_options.<locals>.<lambda>.<locals>.<lambda>  s    &&9PRV2W2W rd   )234r  r`   r  s   rb   r   z-PythonInput._create_options.<locals>.<lambda>  s?    !K!K!K!K!K!K!K!K!K!K!K!K*W*W*W*W	, , rd   DisplayCompletionszjVisualisation to use for displaying the completions. (Multiple columns, one column, a toolbar or nothing.)c                      j         j        S r_   )r   r9  r~   s   rb   r   z-PythonInput._create_options.<locals>.<lambda>  s    $2O2U rd   c            	         t           j        j         fdt           j        j         fdt           j        j         fdt           j        j         fdiS )Nc                 0      dt           j                  S Nr   )rH   NONEr  s   rb   r   z?PythonInput._create_options.<locals>.<lambda>.<locals>.<lambda>  s     :<S<XI I rd   c                 0      dt           j                  S r  )rH   POP_UPr  s   rb   r   z?PythonInput._create_options.<locals>.<lambda>.<locals>.<lambda>  s    && : 7 >K K rd   c                 0      dt           j                  S r  )rH   r   r  s   rb   r   z?PythonInput._create_options.<locals>.<lambda>.<locals>.<lambda>  s     PVPV : 7 DQ Q rd   c                 0      dt           j                  S r  )rH   TOOLBARr  s   rb   r   z?PythonInput._create_options.<locals>.<lambda>.<locals>.<lambda>  s    66 : 7 ?L L rd   )rH   r  r9  r  r   r  r  s   rb   r   z-PythonInput._create_options.<locals>.<lambda>  s    38> A A A A 4:@ C C C C 4@F I I I I 4;A D D D D, rd   Promptz1Visualisation of the prompt. ('>>>' or 'In [1]:')c                      j         S r_   r   r~   s   rb   r   z-PythonInput._create_options.<locals>.<lambda>  s
    $2C rd   c                 *     fdj         D             S )Nc                4    i | ]}|t          d |          S r  r   r  s     rb   
<dictcomp>zAPythonInput._create_options.<locals>.<lambda>.<locals>.<dictcomp>  s7     , , , ! wv~qAA, , ,rd   )r   r  s   rb   r   z-PythonInput._create_options.<locals>.<lambda>  s.     , , , ,%)%;, , , rd   zBlank line after inputz$Insert a blank line after the input.r   zBlank line after outputz%Insert a blank line after the output.r   zShow signaturezDisplay function signatures.r   zShow docstringzDisplay function docstrings.r   zShow line numbersz<Show line numbers when the input consists of multiple lines.r   zShow Meta+Enter messagezShow the [Meta+Enter] message when this key combination is required to execute commands. (This is the case when a simple [Enter] key press will insert a newline.r   z
Wrap linesz-Wrap lines instead of scrolling horizontally.r   zShow status barz2Show the status bar at the bottom of the terminal.r   zShow sidebar helpz6When the sidebar is visible, also show this help text.r   zHighlight parenthesiszIHighlight matching parenthesis, when the cursor is on or right after one.r   zReformat output (black)z9Reformat outputs using Black, if possible (experimental).r   zEnable pager for outputz@Use a pager for displaying outputs that don't fit on the screen.r   ColorszSyntax highlightingz"Use colors for syntax highligthingr   zSwap light/dark colorszSwap light and dark colors.r   Codez(Color scheme to use for the Python code.c                      j         S r_   )r  r~   s   rb   r   z-PythonInput._create_options.<locals>.<lambda>Q  s
    $2O rd   c                 *     fd j         D             S )Nc                <    i | ]}|t          j        |          S r`   )r   rL  r)  rC  ra   s     rb   r  zAPythonInput._create_options.<locals>.<lambda>.<locals>.<dictcomp>R  s8     , , , $ !'$*CT"J"J, , ,rd   rF  r~   s   rb   r   z-PythonInput._create_options.<locals>.<lambda>R  s.     , , , ,(,(8, , , rd   zUser interfacez+Color scheme to use for the user interface.c                      j         S r_   )r  r~   s   rb   r   z-PythonInput._create_options.<locals>.<lambda>Z  s
    $2M rd   c                 *     fd j         D             S )Nc                <    i | ]}|t          j        |          S r`   )r   rQ  r  s     rb   r  zAPythonInput._create_options.<locals>.<lambda>.<locals>.<dictcomp>[  s8     , , , $ !'$*A4"H"H, , ,rd   rN  r~   s   rb   r   z-PythonInput._create_options.<locals>.<lambda>[  s-     , , , ,(,, , , rd   zColor depthzJMonochrome (1 bit), 16 ANSI colors (4 bit),
256 colors (8 bit), or 24 bit.c                 (    t            j                 S r_   )COLOR_DEPTHSr   r~   s   rb   r   z-PythonInput._create_options.<locals>.<lambda>c  s    ,t?O2P rd   c                 N     fdt                                           D             S )Nc                B    i | ]\  }}|t          j        |          S r`   )r   rU  )r)  rR  rC  ra   s      rb   r  zAPythonInput._create_options.<locals>.<lambda>.<locals>.<dictcomp>d  s<     , , , +t !'$*?"G"G, , ,rd   )r  itemsr~   s   rb   r   z-PythonInput._create_options.<locals>.<lambda>d  s7     , , , ,/;/A/A/C/C, , , rd   zMin brightnessz6Minimum brightness for the color scheme (default=0.0).c                     d j         z  S N%.2fr   r~   s   rb   r   z-PythonInput._create_options.<locals>.<lambda>l      &4;N2N rd   c                      fd D             S )Nc                B    i | ]}d |z  t          j        |          S r  )r   rZ  r)  r9  ra   s     rb   r  zAPythonInput._create_options.<locals>.<lambda>.<locals>.<dictcomp>m  <     , , , % #UNGD4Le,T,T, , ,rd   r`   brightness_valuesra   s   rb   r   z-PythonInput._create_options.<locals>.<lambda>m  +     , , , ,):, , , rd   zMax brightnessz6Maximum brightness for the color scheme (default=1.0).c                     d j         z  S r  r   r~   s   rb   r   z-PythonInput._create_options.<locals>.<lambda>u  r  rd   c                      fd D             S )Nc                B    i | ]}d |z  t          j        |          S r  )r   r^  r  s     rb   r  zAPythonInput._create_options.<locals>.<lambda>.<locals>.<dictcomp>v  r  rd   r`   r  s   rb   r   z-PythonInput._create_options.<locals>.<lambda>v  r  rd   )T)rb  rm   r9  r   r\   r]   )rb  rm   r\   r]   )ri  )
rl   rm   ru   rm   rl  rm   r   rm  r\   rn  )rangerk   rt   )ra   rw  r  rh  rf  s   ` @@@rb   r  zPythonInput._create_options'  s    
	 	 	 	 	 	 		 	 	 	 	 	 '4		 	 	 	 	 	 	 	 	0 IH5B<<HHH ,$?*O*O*O*O$ $ $ $ $	   ,%0*J*J*J*J$ $ $ $ $	 	 	 "M*$O#/  
 5%_+ + + +$ $ $ $ $   6%K+< +< +< +<
$ $ $ $  2 7$>+ + + +$ $ $ $ $
 
 
 5%7+ + + +$ $ $ $ $   .%`+ + + +$ $ $ $ $   "M-%H#9	   "M/$H#1  
 "M0%K#<	   "M/%R#8	   5%b+ + + +$ $ $ $  yJM M\ + %Q*U*U*U*U$ $ $ $	  , &$W*C*C*C*C$ $ $ $ $	   "M6$J#B  
 "M7$K#C  
 "M.$B#3  
 "M.$B#3  
 "M1$b#6  
 "M7%e#<	   "M*$S#/  
 "M/$X#4  
 "M1$\#6  
 "M5$o#C  
 "M7$_#=  
 "M7%-#1	  q^a aD !M3$H#?  
 "M6$A#8  
 $$N*O*O*O*O$ $ $ $	   .$Q*M*M*M*M$ $ $ $	   +$q*P*P*P*P$ $ $ $	   .$\*N*N*N*N$ $ $ $ $	   .$\*N*N*N*N$ $ $ $ $	  _8; ;cm
 m	
rd   Application[str]c                    t           j        j        t          t	                     t                      t                     t                     t          t                      t           fd                    t           j        t           fd                    g           fdt           fd          t           fd          t           fd           j        ddt           fd	          ||
          S )z3
        Create an `Application` instance.
        c                      j         S r_   )r   r~   s   rb   r   z1PythonInput._create_application.<locals>.<lambda>  s
    $*D rd   c                      j          S r_   )r   r~   s   rb   r   z1PythonInput._create_application.<locals>.<lambda>  s    d.?*? rd   c                      j         S r_   rT  r~   s   rb   r   z1PythonInput._create_application.<locals>.<lambda>  s
     0 rd   c                      j         S r_   )r   r~   s   rb   r   z1PythonInput._create_application.<locals>.<lambda>  s	     rd   c                      j         S r_   )r   r~   s   rb   r   z1PythonInput._create_application.<locals>.<lambda>  s
    D,E rd   c                      j         S r_   )r  r~   s   rb   r   z1PythonInput._create_application.<locals>.<lambda>  s
    t': rd   FTc                 (     j          j                 S r_   )r  r   r~   s   rb   r   z1PythonInput._create_application.<locals>.<lambda>  s    5d6NO rd   )layoutkey_bindingsr   r   mouse_supportrD  r  include_default_pygments_stylereverse_vi_search_directioncursorr   r   )r   r  r  r-   rF   r.   rG   rE   r+   r/   r$   r   r:   r  r   )ra   r   r   s   `  rb   r  zPythonInput._create_application  s0    '.+(...00)$//.t44*466!"D"D"D"DEE 
 +/!"?"?"?"?@@  " 1000 !8!8!8!899#$E$E$E$EFF::::;;!%!:+0(,+OOOO  =
 
 
 	
rd   c                z    t          t          t           fd          t           fd          d j        t	           j                  t           j        t           fd                    t          t          t                                t           fd                     j         j        
  
        }|S )z;
        Create the `Buffer` for the Python input.
        c                      j         S r_   r  r~   s   rb   r   z,PythonInput._create_buffer.<locals>.<lambda>  
    D4N rd   c                      j         S r_   r  r~   s   rb   r   z,PythonInput._create_buffer.<locals>.<lambda>  r  rd   z.pyc                      j         S r_   )r   r~   s   rb   r   z,PythonInput._create_buffer.<locals>.<lambda>  s
    43O rd   c                      j         S r_   )r   r~   s   rb   r   z,PythonInput._create_buffer.<locals>.<lambda>  s
    $": rd   )
rC  r   r   tempfile_suffixr   r   	validatorauto_suggestaccept_handleron_text_changed)r   r"   r$   r   r   r   r>   r   r   r   r   r%  _on_input_timeout)ra   python_buffers   ` rb   r   zPythonInput._create_buffer  s     "+,N,N,N,N"O"O"+,N,N,N,N"O"O!L'88*+O+O+O+O!P!P  0#$:$<$<==::::;;   / 2
 
 
$ rd   r#   c                    | j         j        S r_   r  r  r~   s    rb   r  zPythonInput.editing_mode  s    x$$rd   c                    || j         _        d S r_   r  rY  s     rb   r  zPythonInput.editing_mode  s     %rd   c                ,    | j         t          j        k    S r_   )r  r#   r  r~   s    rb   r   zPythonInput.vi_mode  s     KN22rd   c                R    |rt           j        | _        d S t           j        | _        d S r_   )r#   r  r  EMACSrY  s     rb   r   zPythonInput.vi_mode  s+     	2 +D + 1Drd   c                :    | j         t                      S | j         S r_   )r  r   r~   s    rb   r  zPythonInput.app  s    999yrd   c                     d	 fd j         d
 fd}j        r                     |                       dS dS )zt
        When there is no input activity,
        in another thread, get the signature of the current code.
        documentr!   r\   list[Signature]c                    t          |                                                                           }|s<j        r5t	          |                                                                           }|S r_   )rP   r   r   r   rO   )r  r  ra   s     rb   get_signatures_in_executorzAPythonInput._on_input_timeout.<locals>.get_signatures_in_executor  sy     3$//++T-=-=-?-? J  $"C 6doo//1A1A1C1C 
 rd   rp   c                   K   t                      } j        rd S d_        	 	 j        }|                     d |           d {V }j        |j        k    rn6	 d_        n# d_        w xY w|_        |r6j                            t          |d         j	        d                     nj                                         
                                 d S )NTFr   )cursor_position)r  )r   r  r  run_in_executorr!  r  r   r$  r!   	docstring
invalidate)loopr  r  r  r  r  ra   s      rb   on_timeout_taskz6PythonInput._on_input_timeout.<locals>.on_timeout_task  s1     !##D 2 26D/<	#}H'+';';8(( ( " " " " " "J yHM11	 6;33e3;;;; )DO  .%++%jm&=qQQQ ,     %++---NNs   7A# #	A,N)r  r!   r\   r  r   )r  
is_runningcreate_background_task)ra   r  r  r  r  s   `` @@rb   r  zPythonInput._on_input_timeout  s    	 	 	 	 	 	 h!	 !	 !	 !	 !	 !	 !	 !	 !	F > 	:&&'8'899999	: 	:rd   c                    g | _         d S r_   )r  r~   s    rb   on_resetzPythonInput.on_reset  s    rd   c                      j         t          j        j        _        t            j        j                  ddl}ddl	m
 d fd}|                     |                       dS )z&
        Display the history.
        r   N)in_terminalr\   rp   c                    K                4 d {V  j                                          d {V } | | j        _        t          j        j        _        d d d           d {V  d S # 1 d {V swxY w Y   d S r_   )r  	run_asyncr   r!  r0   INSERTvi_state
input_mode)r  r  r   r"  ra   s    rb   do_in_terminalz1PythonInput.enter_history.<locals>.do_in_terminal#  s     "{}} ; ; ; ; ; ; ; ;&{4466666666%/5D',*3*:'; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ;s   AA++
A58A5r   )r  r0   
NAVIGATIONr&  r'  rD   r   r  asyncioprompt_toolkit.applicationr"  ensure_future)ra   r*  r(  r  r   r"  s   `  @@@rb   enter_historyzPythonInput.enter_history  s     h"+"6d&9&BCC::::::	; 	; 	; 	; 	; 	; 	; 	; 	; 	nn../////rd   c                     j         j        j        fd fd}	 	  j                             |d          }|                                                    d          rt          t          |          }|r<|                                s( j	        r j         j
                            d	           |S n(# t          $ r t                       j        _        Y nw xY w)aC  
        Read the input.

        This will run the Python input user interface in another thread, wait
        for input to be accepted and return that. By running the UI in another
        thread, we avoid issues regarding possibly nested event loops.

        This can raise EOFError, when Control-D is pressed.
        last_input_moder0   r\   rp   c                    j         r| j        j        _        j         s$j        rt
          j        j        j        _        d S d S d S r_   )r  r  r&  r'  r  r0   r)  )r/  ra   s    rb   pre_runz!PythonInput.read.<locals>.pre_run;  sb     * ?/>!,. D43S D/8/C!,,,D D D Drd   T)r1  	in_thread
N)r/  r0   r\   rp   )r  r&  r'  runlstrip
startswithEOFErrorrT   isspacer   r   writeKeyboardInterruptr!   r   r  )ra   r1  r  s   `  rb   readzPythonInput.read-  s    *.):)E	D 	D 	D 	D 	D 	D 	D	::gFF==??--f55 # #N
 'v.. "&.."2"2 "9 4--d333!M$ : : :/7zz#,,,:'	:s   BB3 3"CC)NNNFNNNNTNNNNNNN)r   r   r   r   r   r   r   r]   r   r   r   r   r   r   r   r   r   r]   r   r   r   r   r   r   r   r   r\   rp   )r  r   r\   r]   )r\   r&  )r\   r.  )r\   r;  )rC  rm   rD  r8   r\   rp   )rC  rm   r\   rp   )rR  r5   r\   rp   )r9  rV  r\   rp   )r\   r8   )r\   r`  )r   r   r   r   r\   r  )r\   r   )r\   r#   )r9  r#   r\   rp   )r\   r]   )r9  r]   r\   rp   )r\   r  )r  r   r\   rp   r   rv  )re   rf   rg   r   rr   r%  r   r-  r2  r   rB  rH  rL  rO  rQ  rU  rZ  r^  r  r  r  r   r  setterr   r  r  r   r-  r<  r`   rd   rb   rW   rW      s          -1+/'+)-" $15'+'+#!%26!'a a a a aF    G G G XG 
- 
- 
- X
-   . % % % X%$' ' ' '5 5 5 5% % % %5 5 5 5! ! ! !> > > >> > > >	
 	
 	
 	
V
 V
 V
 V
p
%
 %
 %
 %
N   0 % % % X% & & & & 3 3 3 X3 ^2 2 2 ^2    X
:: :: :: ::x   0 0 0 0.-: -: -: -: -: -:rd   N)r   rV   r   r*  r   	functoolsr   typingr   r   r	   r
   r   r   r   r   r   r   r+  r   r   prompt_toolkit.auto_suggestr   r   r   prompt_toolkit.bufferr   prompt_toolkit.completionr   r   r   r   r   r   prompt_toolkit.cursor_shapesr   r   r   r    prompt_toolkit.documentr!   prompt_toolkit.enumsr"   r#   prompt_toolkit.filtersr$   prompt_toolkit.formatted_textr%   prompt_toolkit.historyr&   r'   r(   r)   prompt_toolkit.inputr*   prompt_toolkit.key_bindingr+   r,   r-   0prompt_toolkit.key_binding.bindings.auto_suggestr.   2prompt_toolkit.key_binding.bindings.open_in_editorr/   #prompt_toolkit.key_binding.vi_stater0    prompt_toolkit.layout.containersr1   prompt_toolkit.lexersr2   r3   r4   prompt_toolkit.outputr5   r6   prompt_toolkit.stylesr7   r8   r9   r:   r;   r<   prompt_toolkit.utilsr=   prompt_toolkit.validationr>   r?   r   rA   rB   rC   history_browserrD   r  rE   rF   rG   r  rH   rI   r   rJ   r   rK   rL   rM   r  rN   rO   rP   rD  rQ   rR   rS   utilsrT   r  rU   
__import____all__typing_extensionsrX   rZ   rh   rk   rt   DEPTH_1_BITDEPTH_4_BITDEPTH_8_BITDEPTH_24_BITr  rm   
_Namespace_GetNamespacerW   r`   rd   rb   <module>r_     s    # " " " " " " " " " " "                              < ; ; ; ; ; ; ;         
 ) ( ( ( ( (                           - , , , , , < < < < < < < < , , , , , , : : : : : :            ' & & & & &         
 X W W W W W      : 9 9 9 9 9 9 9 9 9 9 9 B B B B B B B B B B 4 4 4 4 4 4 4 4                , + + + + + E E E E E E E E W W W W W W W W W W * * * * * *         
 < ; ; ; ; ; ; ;             C C C C C C C C C C W W W W W W W W W W I I I I I I I I I I             & & & & & & Z%%
 /  ******    H    WT,---    WR[   9+ 9+ 9+ 9+ 9+WR[ 9+ 9+ 9+z LML\	 #s(^
Z([: [: [: [: [: [: [: [: [: [:rd   