a
    lc                  .   @   s0  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 ddlmZ ddlmZmZ dd	lmZ dd
lmZmZmZ ddlm Z 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, ddl-m.Z. ddl/m0Z0m1Z1m2Z2m3Z3m4Z4m5Z5m6Z6m7Z7 ddl8m9Z9m:Z:m;Z;m<Z<m=Z= ddl>m?Z?m@Z@ ddlAmBZB ddlCmDZD ddlEmFZF ddlGmHZH ddlImJZJmKZKmLZLmMZMmNZN ddlOmPZP ddlQmRZR ddlSmTZTmUZUmVZVmWZW ddlXmYZYmZZZ ddl[m\Z\m]Z]m^Z^ ddl_m`Z` ddlambZb ddlcmdZdmeZe dd lfmgZgmhZhmiZimjZjmkZkmlZlmmZmmnZnmoZompZpmqZq dd!lrmsZs dd"ltmuZumvZv dd#lwmxZxmyZymzZz dd$l{m|Z|m}Z}m~Z~mZmZmZmZ dd%lmZmZmZmZ dd&lmZmZ dd'lmZmZmZ erdd(lmZ g d)Ze	g e:f ZePZeee	g ef eef d*d+d,ZG d-d. d.eWZG d/d0 d0eeZeed1e:e	eeege9f f Zed2ZG d3d4 d4e
e ZdCd5d5d5d5d5d5d5d5d5d5d5d5d5d5d5d5d5d5d5d5d5d5d5d5d5d5d5d5d5d5d5d5d5d5d5d5d5d6d7d5d8(ee9 ee? ee, ee ee eev ee  ee ee eeM ee9 ee| eex e$ee1 ee ee1 ee9 ee1 ee ee1 ee1 ee1 ee1 ee1 ee ee ee ee ee1 eeeo  ee9 ee ee1 ee1 ee1 eeee	g ef f  eeee	g ef f  eeee	g d5f  ed9*d:d;Zejj e_ dDeeee d=d>d?ZdEeeed=dAdBZd5S )Fao  
Line editing functionality.
---------------------------

This provides a UI for a line input, similar to GNU Readline, libedit and
linenoise.

Either call the `prompt` function for every line input. Or create an instance
of the :class:`.PromptSession` class and call the `prompt` method from that
class. In the second case, we'll have a 'session' that keeps all the state like
the history in between several calls.

There is a lot of overlap between the arguments taken by the `prompt` function
and the `PromptSession` (like `completer`, `style`, etcetera). There we have
the freedom to decide which settings we want for the whole 'session', and which
we want for an individual `prompt`.

Example::

        # Simple `prompt` call.
        result = prompt('Say something: ')

        # Using a 'session'.
        s = PromptSession()
        result = s.prompt('Say something: ')
    )contextmanager)Enum)partial)
TYPE_CHECKINGCallableGenericIteratorListOptionalTupleTypeVarUnioncast)Application)get_app)AutoSuggestDynamicAutoSuggest)Buffer)	ClipboardDynamicClipboardInMemoryClipboard)	CompleterDynamicCompleterThreadedCompleter)AnyCursorShapeConfigCursorShapeConfigDynamicCursorShapeConfig)Document)DEFAULT_BUFFERSEARCH_BUFFEREditingMode)get_event_loop)	ConditionFilterOrBoolhas_arg	has_focusis_doneis_truerenderer_height_is_known	to_filter)AnyFormattedTextStyleAndTextTuplesfragment_list_to_textmerge_formatted_textto_formatted_text)HistoryInMemoryHistory)Input)load_auto_suggest_bindings!display_completions_like_readline)load_open_in_editor_bindings)ConditionalKeyBindingsDynamicKeyBindingsKeyBindingsKeyBindingsBasemerge_key_bindings)KeyPressEvent)Keys)FloatFloatContainerHSplitWindow)ConditionalContainerWindowAlign)BufferControlFormattedTextControlSearchBufferControl)	Dimension)Layout)CompletionsMenuMultiColumnCompletionsMenu)
AfterInputAppendAutoSuggestionConditionalProcessorDisplayMultipleCursorsDynamicProcessor#HighlightIncrementalSearchProcessorHighlightSelectionProcessorPasswordProcessor	ProcessorReverseSearchProcessormerge_processors)explode_text_fragments)DynamicLexerLexer)
ColorDepthDummyOutputOutput)	BaseStyleConditionalStyleTransformationDynamicStyleDynamicStyleTransformationStyleTransformation#SwapLightAndDarkStyleTransformationmerge_style_transformations)
get_cwidthis_dumb_terminalsuspend_to_background_supportedto_str)DynamicValidator	Validator)SearchToolbarSystemToolbarValidationToolbar)MagicFormattedText)PromptSessionpromptconfirmcreate_confirm_sessionCompleteStyle)get_prompt_textreturnc                    s@   t d fdd}td fdd}td fdd}|||fS )a6  
    Take a `get_prompt_text` function and return three new functions instead.
    One that tells whether this prompt consists of multiple lines; one that
    returns the fragments to be shown on the lines above the input; and another
    one with the fragments to be shown at the first line of the input.
    rr   c                     s$     D ]^} }}d|v r dS qdS )N
TF )fragmentchar_rq   ru   [/var/www/html/django/DPS/env/lib/python3.9/site-packages/prompt_toolkit/shortcuts/prompt.pyhas_before_fragments   s    z5_split_multiline_prompt.<locals>.has_before_fragmentsc                     sH   g } d}t t  D ],^}}}|r6| d||f q|dkrd}q| S )NFr   rt   TreversedrU   insert)resultZfound_nlrv   rw   rx   ry   ru   rz   before   s    z'_split_multiline_prompt.<locals>.beforec                     s@   g } t t  D ](^}}}|dkr* q<q| d||f q| S )Nrt   r   r|   )r   rv   rw   rx   ry   ru   rz   first_input_line   s    z1_split_multiline_prompt.<locals>.first_input_line)boolr+   )rq   r{   r   r   ru   ry   rz   _split_multiline_prompt   s    
	r   c                       s(   e Zd ZdZedd fddZ  ZS )_RPromptzG
    The prompt that is displayed on the right side of the Window.
    N)textrr   c                    s   t  jt|dtjdd d S )N)r   zclass:rprompt)alignstyle)super__init__rD   rB   RIGHT)selfr   	__class__ru   rz   r      s
    z_RPrompt.__init__)__name__
__module____qualname____doc__r*   r   __classcell__ru   ru   r   rz   r      s   r   c                   @   s&   e Zd ZU dZeed< dZdZdZdS )rp   z8
    How to display autocompletions for the prompt.
    valueCOLUMNMULTI_COLUMNREADLINE_LIKEN)	r   r   r   r   str__annotations__r   r   r   ru   ru   ru   rz   rp      s
   
rp   rk   _Tc                /   @   s  e Zd ZdZdZdAddddejddddddddddddejdddddddddddddddddddd	ddd
(e	e
e
e
eee
e
e
e
ee e
e
e
ee ee eeeee ee ee e
ee ee
ee ee ee e	e	e
eee  ee	 ee eeeeeg ef f  eeeeg ef f  eee  ee! dd*ddZ"ee#dddZ$e%dddZ&e%dddZ'e(dddZ)eee*e+ dddZ,e-dddZ.dBddddddddddddddddddddddddddddddddddddddddddd*ee	 ee ee ee ee ee ee ee ee ee	 ee ee ee ee
 ee ee
 ee	 ee
 ee ee
 ee
 ee
 ee
 ee
 ee ee ee ee ee
 eee  ee	 ee ee
 ee
 ee
 eeeeg ef f  eeeeg ef f  eee/f eeeg df  eeee+d,dd Z0e1dCe	e2e*e+  d!d"d#Z3dDdddddddddddddddddddddddddddddddddddddddddd$)ee	 ee ee ee ee ee ee ee ee ee	 ee ee ee4 ee
 ee ee
 ee	 ee
 ee ee
 ee
 ee
 ee
 ee
 ee ee ee ee ee
 eee  ee	 ee ee
 ee
 ee
 eeeeg ef f  eeeeg ef f  eee/f eeeg df  eee+d%+d&d'Z5eeg df  edd(d)d*Z6e7edd+d,Z8e8j9edd-d.d,Z8e:dd/d0Z;e<dd1d2Z=eeee<d3d4d5Z>eee?e<d6d7d8Z@e<dd9d:ZAe<dd;d<ZBe7e dd=d>ZCe7e!dd?d@ZDdS )Erl   a  
    PromptSession for a prompt application, which can be used as a GNU Readline
    replacement.

    This is a wrapper around a lot of ``prompt_toolkit`` functionality and can
    be a replacement for `raw_input`.

    All parameters that expect "formatted text" can take either just plain text
    (a unicode object), a list of ``(style_str, text)`` tuples or an HTML object.

    Example usage::

        s = PromptSession(message='>')
        text = s.prompt()

    :param message: Plain text or formatted text to be shown before the prompt.
        This can also be a callable that returns formatted text.
    :param multiline: `bool` or :class:`~prompt_toolkit.filters.Filter`.
        When True, prefer a layout that is more adapted for multiline input.
        Text after newlines is automatically indented, and search/arg input is
        shown below the input, instead of replacing the prompt.
    :param wrap_lines: `bool` or :class:`~prompt_toolkit.filters.Filter`.
        When True (the default), automatically wrap long lines instead of
        scrolling horizontally.
    :param is_password: Show asterisks instead of the actual typed characters.
    :param editing_mode: ``EditingMode.VI`` or ``EditingMode.EMACS``.
    :param vi_mode: `bool`, if True, Identical to ``editing_mode=EditingMode.VI``.
    :param complete_while_typing: `bool` or
        :class:`~prompt_toolkit.filters.Filter`. Enable autocompletion while
        typing.
    :param validate_while_typing: `bool` or
        :class:`~prompt_toolkit.filters.Filter`. Enable input validation while
        typing.
    :param enable_history_search: `bool` or
        :class:`~prompt_toolkit.filters.Filter`. Enable up-arrow parting
        string matching.
    :param search_ignore_case:
        :class:`~prompt_toolkit.filters.Filter`. Search case insensitive.
    :param lexer: :class:`~prompt_toolkit.lexers.Lexer` to be used for the
        syntax highlighting.
    :param validator: :class:`~prompt_toolkit.validation.Validator` instance
        for input validation.
    :param completer: :class:`~prompt_toolkit.completion.Completer` instance
        for input completion.
    :param complete_in_thread: `bool` or
        :class:`~prompt_toolkit.filters.Filter`. Run the completer code in a
        background thread in order to avoid blocking the user interface.
        For ``CompleteStyle.READLINE_LIKE``, this setting has no effect. There
        we always run the completions in the main thread.
    :param reserve_space_for_menu: Space to be reserved for displaying the menu.
        (0 means that no space needs to be reserved.)
    :param auto_suggest: :class:`~prompt_toolkit.auto_suggest.AutoSuggest`
        instance for input suggestions.
    :param style: :class:`.Style` instance for the color scheme.
    :param include_default_pygments_style: `bool` or
        :class:`~prompt_toolkit.filters.Filter`. Tell whether the default
        styling for Pygments lexers has to be included. By default, this is
        true, but it is recommended to be disabled if another Pygments style is
        passed as the `style` argument, otherwise, two Pygments styles will be
        merged.
    :param style_transformation:
        :class:`~prompt_toolkit.style.StyleTransformation` instance.
    :param swap_light_and_dark_colors: `bool` or
        :class:`~prompt_toolkit.filters.Filter`. When enabled, apply
        :class:`~prompt_toolkit.style.SwapLightAndDarkStyleTransformation`.
        This is useful for switching between dark and light terminal
        backgrounds.
    :param enable_system_prompt: `bool` or
        :class:`~prompt_toolkit.filters.Filter`. Pressing Meta+'!' will show
        a system prompt.
    :param enable_suspend: `bool` or :class:`~prompt_toolkit.filters.Filter`.
        Enable Control-Z style suspension.
    :param enable_open_in_editor: `bool` or
        :class:`~prompt_toolkit.filters.Filter`. Pressing 'v' in Vi mode or
        C-X C-E in emacs mode will open an external editor.
    :param history: :class:`~prompt_toolkit.history.History` instance.
    :param clipboard: :class:`~prompt_toolkit.clipboard.Clipboard` instance.
        (e.g. :class:`~prompt_toolkit.clipboard.InMemoryClipboard`)
    :param rprompt: Text or formatted text to be displayed on the right side.
        This can also be a callable that returns (formatted) text.
    :param bottom_toolbar: Formatted text or callable which is supposed to
        return formatted text.
    :param prompt_continuation: Text that needs to be displayed for a multiline
        prompt continuation. This can either be formatted text or a callable
        that takes a `prompt_width`, `line_number` and `wrap_count` as input
        and returns formatted text. When this is `None` (the default), then
        `prompt_width` spaces will be used.
    :param complete_style: ``CompleteStyle.COLUMN``,
        ``CompleteStyle.MULTI_COLUMN`` or ``CompleteStyle.READLINE_LIKE``.
    :param mouse_support: `bool` or :class:`~prompt_toolkit.filters.Filter`
        to enable mouse support.
    :param placeholder: Text to be displayed when no input has been given
        yet. Unlike the `default` parameter, this won't be returned as part of
        the output ever. This can be formatted text or a callable that returns
        formatted text.
    :param refresh_interval: (number; in seconds) When given, refresh the UI
        every so many seconds.
    :param input: `Input` object. (Note that the preferred way to change the
        input/output is by creating an `AppSession`.)
    :param output: `Output` object.
    )%messagelexer	completercomplete_in_threadis_passwordediting_modekey_bindingsr   bottom_toolbarr   style_transformationswap_light_and_dark_colorscolor_depthcursorinclude_default_pygments_stylerprompt	multilineprompt_continuation
wrap_linesenable_history_searchsearch_ignore_casecomplete_while_typingvalidate_while_typingcomplete_stylemouse_supportauto_suggest	clipboard	validatorrefresh_intervalinput_processorsplaceholderenable_system_promptenable_suspendenable_open_in_editorreserve_space_for_menutempfile_suffixtempfile FTN   z.txtr   )(r   r   r   vi_moder   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   historyr   r   r   r   r   r   r   r   erase_when_doner   r   r   inputoutput)*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   r   r   r   r   r   r   r   r   r   r   r   r   r   r   rr   c       (   *      C   s2  |pt  }|pt }|rtj}|(| _|)| _|| _|| _|| _|| _	|| _
|#| _|| _|| _|| _|| _|| _|| _|| _|| _|| _|| _|| _|	| _|
| _|| _|| _|| _| | _|| _|| _|| _|'| _ |!| _!|"| _"|| _#|| _$|| _%|| _&|%| _'|&| _(|| _)| * | _+| , | _-| . | _/| 0||$| _1d S N)2r0   r   r    VI_input_outputr   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   r   r   r   r   r   r   r   r   _create_default_bufferdefault_buffer_create_search_buffersearch_buffer_create_layoutlayout_create_applicationapp)*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   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   ru   ru   rz   r   x  s\    .




zPromptSession.__init__)	attr_namerr   c                    s   t td fdd}|S )a$  
        Dynamically take this setting from this 'PromptSession' class.
        `attr_name` represents an attribute name of this class. Its value
        can either be a boolean or a `Filter`.

        This returns something that can be used as either a `Filter`
        or `Filter`.
        rs   c                     s   t tt } t|  S r   )r   r#   getattrr)   )r   r   r   ru   rz   dynamic  s    z'PromptSession._dyncond.<locals>.dynamic)r"   r   )r   r   r   ru   r   rz   _dyncond  s    
zPromptSession._dyncondrs   c                    s~    j }ttddd}ttt fdd|d|dt fddt fd	d jt fd
d| fdd fdddS )z=
        Create and return the default input buffer.
        )buffrr   c                 S   s    t tt t j| jjd dS )zbAccept the content of the default buffer. This is called when
            the validation succeeds.r   T)r   r   r   r   exitdocumentr   )r   ru   ru   rz   accept  s    z4PromptSession._create_default_buffer.<locals>.acceptc                      s$   t  jo"t  j o" jtjk S r   )r'   r   r   r   rp   r   ru   r   ru   rz   <lambda>  s   

z6PromptSession._create_default_buffer.<locals>.<lambda>r   r   c                      s    j S r   )r   ru   r   ru   rz   r         c                      s    j r jrt jS  jS r   )r   r   r   ru   r   ru   rz   r   
  s
    c                      s    j S r   )r   ru   r   ru   rz   r     r   c                      s   t  jp
dS Nr   )re   r   ru   r   ru   rz   r     r   c                      s   t  jp
dS r   )re   r   ru   r   ru   rz   r     r   )namer   r   r   r   r   r   r   Zaccept_handlerr   r   )	r   r   r   r   r"   rf   r   r   r   )r   dyncondr   ru   r   rz   r     s&    



z$PromptSession._create_default_bufferc                 C   s
   t tdS )N)r   )r   r   r   ru   ru   rz   r     s    z#PromptSession._create_search_bufferc                    s  j }tj\}}}j}j}ttdfdd}t t t	t
 t|t @ t	t |dt tfddt	tfdd|dg}tttfd	dd
dddtdddt t@ tfdd@ d}	t||ddt|t g|dd t|dd}
td fdd}t|||dtfdddd}t|jtj|d|dd}ttdfdd }tt tttt|dd!t|t|t fd"dtt t fd#dgt!dddt"d$dt|| @ d%d&t!dddt#dt||@ d'd&t!d(d(dt$fd)dd*gtt% t dt|
|dt @ tttj&dd+|d,t'@ t|d,t @ |	g}t(||S )-z2
        Create `Layout` for this prompt.
        rs   c                      s    j d uo jjdkS r   )r   r   r   ru   r   ru   rz   display_placeholder*  s    z9PromptSession._create_layout.<locals>.display_placeholderr   c                      s   t  jp
g S r   )rT   r   ru   r   ru   rz   r   7  r   z.PromptSession._create_layout.<locals>.<lambda>c                      s    j S r   )r   ru   r   ru   rz   r   9  r   filterc                      s    j S r   r   ru   r   ru   rz   r   B  r   zclass:bottom-toolbar.textr   zclass:bottom-toolbarT   min)r   dont_extend_heightheightc                      s
    j d uS r   r   ru   r   ru   rz   r   J  r   r   )ignore_case)bufferr   r   r   )Zenable_global_bindingsc                      s   t jrjS  S dS )z8Return the UIControl to be focused when searching start.N)r'   r   controlru   search_buffer_controlZsearch_toolbarr   ru   rz   get_search_buffer_control[  s    
z?PromptSession._create_layout.<locals>.get_search_buffer_controlFc                      s    j S r   )r   ru   r   ru   rz   r   g  r   )r   r   r   Z include_default_input_processorsr   Zpreview_search)get_prompt_text_2r   )r   Zget_line_prefixr   c                      s    j tjkS r   )r   rp   r   ru   r   ru   rz   multi_column_complete_stylet  s    zAPromptSession._create_layout.<locals>.multi_column_complete_style)r   c                      s   t  jj kS r   r   r   Zcurrent_controlru   r   ru   rz   r     s   c                      s   t  jj kS r   r   ru   r   ru   rz   r     s      )
max_heightZscroll_offsetextra_filter)ZxcursorZycursortransparentcontent)Z	show_metar   r   c                      s    j S r   )r   ru   r   ru   rz   r     r   )rightbottomZhide_when_covering_contentr   )r   r   ))r   r   _get_promptr   r   r"   r   rO   rP   rL   rK   r%   r&   rQ   rM   rN   rJ   rA   r@   rD   rF   r(   rh   rE   rS   ri   rC   rV   "_get_default_buffer_control_heightr   _get_line_prefixr?   r>   r=   rH   rI   r   rj   _get_arg_textr$   rG   )r   r   r{   Zget_prompt_text_1r   r   r   r   Zall_input_processorsr   Zsystem_toolbarr   Zdefault_buffer_controlZdefault_buffer_windowr   r   ru   r   rz   r     s   		

=
NzPromptSession._create_layout)r   r   rr   c                    s    j }t }t }  }t jt fddtt fddt	t
 |dg|dt fddtt|t||dtt@ |gt fddg|d	||d
 fddt fdd j j jd}|S )z2
        Create the `Application` object.
        c                      s    j S r   r   ru   r   ru   rz   r     r   z3PromptSession._create_application.<locals>.<lambda>c                      s    j S r   )r   ru   r   ru   rz   r     r   r   r   c                      s    j S r   )r   ru   r   ru   rz   r     r   r   c                      s    j S r   r   ru   r   ru   rz   r     r   r   Tc                      s    j S r   )r   ru   r   ru   rz   r     r   c                      s    j S r   )r   ru   r   ru   rz   r     r   )r   r   r   r   r   r   r   r   r   Zreverse_vi_search_directionr   r   r   r   r   )r   r2   r5   _create_prompt_bindingsr   r   r]   ra   r^   r\   r`   r   r:   r6   r%   r   r7   r   r   r   r   )r   r   r   r   Zauto_suggest_bindingsZopen_in_editor_bindingsZprompt_bindingsapplicationru   r   rz   r     sV    	
=z!PromptSession._create_applicationc                    s  t  }|j}tt}ttd fdd}|d||@ dtdd fdd	}ttd fd
d}|d||@ dtdddd}|d|d|dtdddd}ttddd}	|d|	|@ dtdddd}
tt}ttd fdd}|d||@ dtdddd}|S )zB
        Create the KeyBindings for a prompt application.
        rs   c                      s   t  j o jjtS r   )r'   r   r   r   r%   r   ru   r   ru   rz   	do_accept  s    z8PromptSession._create_prompt_bindings.<locals>.do_acceptZenterr   Neventrr   c                    s    j   dS )z)Accept input when enter has been pressed.N)r   validate_and_handler  r   ru   rz   _accept_input$  s    z<PromptSession._create_prompt_bindings.<locals>._accept_inputc                      s    j tjkS r   )r   rp   r   ru   r   ru   rz   readline_complete_style)  s    zFPromptSession._create_prompt_bindings.<locals>.readline_complete_styletabc                 S   s   t |  dS )z$Display completions (like Readline).Nr3   r  ru   ru   rz   _complete_like_readline-  s    zFPromptSession._create_prompt_bindings.<locals>._complete_like_readlinezc-cz<sigint>c                 S   s   | j jtdd dS )z&Abort when Control-C has been pressed.zclass:aborting	exceptionr   N)r   r   KeyboardInterruptr  ru   ru   rz   _keyboard_interrupt2  s    zBPromptSession._create_prompt_bindings.<locals>._keyboard_interruptc                  S   s   t  } | jjtko| jj S )zXCtrl-D binding is only active when the default buffer is selected
            and empty.)r   Zcurrent_bufferr   r   r   )r   ru   ru   rz   ctrl_d_condition8  s    z?PromptSession._create_prompt_bindings.<locals>.ctrl_d_conditionzc-dc                 S   s   | j jtdd dS )z%Exit when Control-D has been pressed.zclass:exitingr  N)r   r   EOFErrorr  ru   ru   rz   _eofB  s    z3PromptSession._create_prompt_bindings.<locals>._eofc                      s   t  j S r   )r)   r   ru   r   ru   rz   r   I  s    z=PromptSession._create_prompt_bindings.<locals>.enable_suspendzc-zc                 S   s   | j   dS )z8
            Suspend process to background.
            N)r   Zsuspend_to_backgroundr  ru   ru   rz   _suspendM  s    z7PromptSession._create_prompt_bindings.<locals>._suspend)r8   addr%   r   r"   r   Erd   )r   kbhandleZdefault_focusedr  r  r  r
  r  r  r  Zsuspend_supportedr   r  ru   r   rz   r     s0    
	z%PromptSession._create_prompt_bindings)*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   r   r   r   r   r   r   r   r   r   defaultaccept_defaultpre_runset_exception_handlerhandle_sigint	in_thread),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   r   r   r   r   r   r   r   r   r   r   r  r  r  r  r  r  rr   c       *   -      C   s  |dur|| _ |dur|| _|dur*|| _|r6tj| _|durD|| _|durR|| _|dur`|| _|durn|| _|	dur||	| _	|
dur|
| _
|dur|| _|dur|| _|dur|| _|dur|| _|dur|| _|dur|| _|dur|| _|dur|| _|dur
|| _|dur|| _|dur*|| _|dur:|| _|durJ|| _|durZ|| _|durj|| _|durz|| _|dur|| _|dur|| _|dur|| _|dur|| _|dur|| _| dur| | _ |!dur|!| _!|"dur|"| _"|#dur
|#| _#|$dur|$| _$|%dur*|%| _%| &|(|' | j'(t)|&t*rL|&nt*|& | j| j+_| j,du rt- r| .| j },|,j/|+|*dW  d   S 1 s0    Y  | j+j/|)|+|*dS )a  
        Display the prompt.

        The first set of arguments is a subset of the :class:`~.PromptSession`
        class itself. For these, passing in ``None`` will keep the current
        values that are active in the session. Passing in a value will set the
        attribute for the session, which means that it applies to the current,
        but also to the next prompts.

        Note that in order to erase a ``Completer``, ``Validator`` or
        ``AutoSuggest``, you can't use ``None``. Instead pass in a
        ``DummyCompleter``, ``DummyValidator`` or ``DummyAutoSuggest`` instance
        respectively. For a ``Lexer`` you can pass in an empty ``SimpleLexer``.

        Additional arguments, specific for this prompt:

        :param default: The default input text to be shown. (This can be edited
            by the user).
        :param accept_default: When `True`, automatically accept the default
            value without allowing the user to edit the input.
        :param pre_run: Callable, called at the start of `Application.run`.
        :param in_thread: Run the prompt in a background thread; block the
            current thread. This avoids interference with an event loop in the
            current thread. Like `Application.run(in_thread=True)`.

        This method will raise ``KeyboardInterrupt`` when control-c has been
        pressed (for abort) and ``EOFError`` when control-d has been pressed
        (for exit).
        N)r  r  )r  r  r  )0r   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   r   r   r   r   r   r   r   r   r   r   _add_pre_run_callablesr   reset
isinstancer   r   r   rc   _dumb_promptrun)-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   r   r   r   r   r   r   r   r   r   r   r   r  r  r  r  r  r  dump_appru   ru   rz   rm   V  s    ]



















.zPromptSession.prompt)r   rr   c              	   #   s    j tt j  j     } jr<t j|g}t	t
t t
 jt  j|d}tdd fdd} j j|7  _z0|V  W  j d  j    j j|8  _n( j d  j    j j|8  _0 dS )a@  
        Create prompt `Application` for prompt function for dumb terminals.

        Dumb terminals have minimum rendering capabilities. We can only print
        text to the screen. We can't use colors, and we can't do cursor
        movements. The Emacs inferior shell is an example of a dumb terminal.

        We will show the prompt, and wait for the input. We still handle arrow
        keys, and all custom key bindings, but we don't really render the
        cursor movements. Instead we only print the typed character that's
        right before the cursor.
        )r   r   r   r   N)rx   rr   c                    s(    j  jjjdd    j   d S )N)r   writer   r   Ztext_before_cursorflush)rx   r   ru   rz   on_text_changed2  s    z3PromptSession._dumb_prompt.<locals>.on_text_changedz
)r   r$  r,   r.   r   r%  r   r   r:   r   r   r   r   rY   r   objectr   r&  )r   r   r   r  r&  ru   r   rz   r     s0    



zPromptSession._dumb_prompt))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   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   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  r  r  rr   c       )   ,         s  |d ur|| _ |d ur|| _|d ur*|| _|r6tj| _|d urD|| _|d urR|| _|d ur`|| _|d urn|| _|	d ur||	| _	|
d ur|
| _
|d ur|| _|d ur|| _|d ur|| _|d ur|| _|d ur|| _|d ur|| _|d ur|| _|d ur|| _|d ur
|| _|d ur|| _|d ur*|| _|d ur:|| _|d urJ|| _|d urZ|| _|d urj|| _|d urz|| _|d ur|| _|d ur|| _|d ur|| _|d ur|| _|d ur|| _| d ur| | _ |!d ur|!| _!|"d ur|"| _"|#d ur
|#| _#|$d ur|$| _$|%d ur*|%| _%| &|(|' | j'(t)|&t*rL|&nt*|& | j| j+_| j,d u rt- r| .| j "}+|+j/|*dI d H W  d    S 1 s0    Y  | j+j/|)|*dI d H S )N)r  )r  r  )0r   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   r   r   r   r   r   r   r   r   r   r   r  r   r  r  r   r   r   rc   r   Z	run_async),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   r   r   r   r   r   r   r   r   r   r   r   r  r  r  r  r  r"  ru   ru   rz   prompt_asyncA  s    4



















2zPromptSession.prompt_async)r  r  rr   c                    s(   d d fdd}j j| d S )Nrs   c                      s"   r
   rt  jj d S r   )r!   	call_soonr   r  ru   r  r  r   ru   rz   pre_run2  s    z6PromptSession._add_pre_run_callables.<locals>.pre_run2)r   Zpre_run_callablesappend)r   r  r  r+  ru   r*  rz   r    s    z$PromptSession._add_pre_run_callablesc                 C   s   | j jS r   r   r   r   ru   ru   rz   r     s    zPromptSession.editing_mode)r   rr   c                 C   s   || j _d S r   r-  )r   r   ru   ru   rz   r     s    c                 C   sV   | j d ur| jtjkr| j}nd}|rPt jsP| j}| sF|j	d urPt
|dS t
 S )Nr   r   )r   r   rp   r   r   r   r&   r   r   Zcomplete_staterF   )r   spacer   ru   ru   rz   r     s    

z0PromptSession._get_default_buffer_control_heightc                 C   s   t | jddS )Nzclass:promptr   )r.   r   r   ru   ru   rz   r     s    zPromptSession._get_prompt)widthline_number
wrap_countrr   c                 C   sF   | j }t|r||||}n|}|du r:t| jr:d| }t|ddS )z
        Insert the prompt continuation.

        :param width: The width that was used for the prompt. (more or less can
            be used.)
        :param line_number:
        :param wrap_count: Amount of times that the line has been wrapped.
        N zclass:prompt-continuationr   )r   callabler'   r   r.   )r   r/  r0  r1  r   Zcontinuationru   ru   rz   _get_continuation  s    zPromptSession._get_continuation)r0  r1  r   rr   c                 C   sR   |dkr6|dkr6t | js0t jjdur0|  S | S tt| }| |||S )zw
        Return whatever needs to be inserted before every line.
        (the prompt, or a line continuation.)
        r   N)	r'   r   r   key_processorarg_inline_argrb   r,   r4  )r   r0  r1  r   Zprompt_widthru   ru   rz   r     s    zPromptSession._get_line_prefixc                 C   s.   | j jj}|du rg S |dkr"d}dd|fgS )z%'arg' toolbar, for in multiline mode.N-z-1)zclass:arg-toolbarzRepeat: zclass:arg-toolbar.text)r   r5  r6  )r   r6  ru   ru   rz   r   1  s    
zPromptSession._get_arg_textc                 C   s4   t  }|jjdu rg S |jj}ddt|fdgS dS )z&'arg' prefix, for in single line mode.N)class:prompt.argz(arg: zclass:prompt.arg.text)r9  z) )r   r5  r6  r   )r   r   r6  ru   ru   rz   r7  =  s    
zPromptSession._inline_argc                 C   s   | j jS r   )r   r   r   ru   ru   rz   r   N  s    zPromptSession.inputc                 C   s   | j jS r   )r   r   r   ru   ru   rz   r   R  s    zPromptSession.output)r   )N)r   )N)Er   r   r   r   _fieldsr    ZEMACSrp   r   r*   r#   r   r
   rW   rg   r   intr   r[   r_   rX   r   r/   r   PromptContinuationTextr	   rR   r9   r   r   r   floatr1   rZ   r   r"   r   r   r   r   rG   r   r   r   r   r8   r   r   rm   r   r   r   r   r(  r  propertyr   setterrF   r   r+   r   r4  _StyleAndTextTuplesCallabler   r   r7  r   r   ru   ru   ru   rz   rl      s\  f* 
f& 3MD 

 ;4 

 rl   Nr   F)(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   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   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  rr   c       (   *   *   C   sd   t |d})|)j| ||||||||	|
|||||||||||||||||||||| |!|"|#|$|%|&|'|(d(S )zk
    The global `prompt` function. This will create a new `PromptSession`
    instance for every call.
    )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   r   r   r   r   r   r   r   r   r   r   r  r  r  )rl   rm   )*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   r   r   r   r   r   r   r   r   r   r   r   r  r  r  sessionru   ru   rz   rm   W  sV    3
rm    (y/n) )r   suffixrr   c                    s   t  }|d|dtdd fdd}|d|dtdd fd	d
}|tjtdddd}t| |g}t||d  S )zE
    Create a `PromptSession` object for the 'confirm' function.
    yYNr  c                    s   d j _| jjdd d S )NrD  Tr   r   r   r   r   r  rA  ru   rz   yes  s    z#create_confirm_session.<locals>.yesnNc                    s   d j _| jjdd d S )NrI  Fr   rF  r  rG  ru   rz   no  s    z"create_confirm_session.<locals>.noc                 S   s   dS )zDisallow inserting other text.Nru   r  ru   ru   rz   rx     s    z!create_confirm_session.<locals>._r   )r8   r  r  r<   Anyr-   rl   )r   rC  ZbindingsrH  rK  rx   Zcomplete_messageru   rG  rz   ro     s    
ro   Confirm?c                 C   s   t | |}| S )z@
    Display a confirmation prompt that returns True/False.
    )ro   rm   )r   rC  rA  ru   ru   rz   rn     s    
rn   )N)rB  )rM  rB  )r   
contextlibr   enumr   	functoolsr   typingr   r   r   r   r	   r
   r   r   r   r   Zprompt_toolkit.applicationr   Z"prompt_toolkit.application.currentr   Zprompt_toolkit.auto_suggestr   r   Zprompt_toolkit.bufferr   Zprompt_toolkit.clipboardr   r   r   Zprompt_toolkit.completionr   r   r   Zprompt_toolkit.cursor_shapesr   r   r   Zprompt_toolkit.documentr   Zprompt_toolkit.enumsr   r   r    Zprompt_toolkit.eventloopr!   Zprompt_toolkit.filtersr"   r#   r$   r%   r&   r'   r(   r)   Zprompt_toolkit.formatted_textr*   r+   r,   r-   r.   Zprompt_toolkit.historyr/   r0   Zprompt_toolkit.input.baser1   Z0prompt_toolkit.key_binding.bindings.auto_suggestr2   Z.prompt_toolkit.key_binding.bindings.completionr4   Z2prompt_toolkit.key_binding.bindings.open_in_editorr5   Z'prompt_toolkit.key_binding.key_bindingsr6   r7   r8   r9   r:   Z(prompt_toolkit.key_binding.key_processorr;   Zprompt_toolkit.keysr<   Zprompt_toolkit.layoutr=   r>   r?   r@   Z prompt_toolkit.layout.containersrA   rB   Zprompt_toolkit.layout.controlsrC   rD   rE   Zprompt_toolkit.layout.dimensionrF   Zprompt_toolkit.layout.layoutrG   Zprompt_toolkit.layout.menusrH   rI   Z prompt_toolkit.layout.processorsrJ   rK   rL   rM   rN   rO   rP   rQ   rR   rS   rT   Zprompt_toolkit.layout.utilsrU   Zprompt_toolkit.lexersrV   rW   Zprompt_toolkit.outputrX   rY   rZ   Zprompt_toolkit.stylesr[   r\   r]   r^   r_   r`   ra   Zprompt_toolkit.utilsrb   rc   rd   re   Zprompt_toolkit.validationrf   rg   Zprompt_toolkit.widgets.toolbarsrh   ri   rj   Z"prompt_toolkit.formatted_text.baserk   __all__r@  r  r   r   r   r   rp   r;  r<  r   rl   r=  rm   ro   rn   ru   ru   ru   rz   <module>   s@  0(
4$	(        w 
a
  