o
    i+                     @   s  d Z ddl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 ddl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 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' er~ddl(m)Z) ddl*m+Z+ ddl,m-Z- dgZ.G dd deZ/dS )z4Module contains the class to create an input prompt.    )TYPE_CHECKINGAnyCallableDictListOptionalTupleUnion)ValidationState)NestedCompleter)	Completer)	Condition)Keys)SimpleLexer)CompleteStylePromptSession)ValidationError)BaseSimplePrompt)INQUIRERPY_POINTER_SEQUENCE)InvalidArgument)InquirerPyDefaultInquirerPyKeybindingsInquirerPyMessageInquirerPySessionResultInquirerPyStyleInquirerPyValidate)Input)KeyPressEvent)OutputInputPromptc                3       s  e Zd ZdZ																							d7d	ed
ee dedede	de	de	de	dee
ee	ee	 f df  dededee de	deee	gef  deee	gef  dee dedededede	dee d ed! d"ed# d$df2 fd%d&Zd	e	d$dfd'd(Zd8d+d,Zd9d-d.Z		d:d/eee	e	f  d0eee	e	f  d$eee	e	f  f fd1d2Zd$e	fd3d4Zd$efd5d6Z  ZS );r   u  Create a text prompt that accepts user input.

    A wrapper class around :class:`~prompt_toolkit.shortcuts.PromptSession`.

    Args:
        message: The question to ask the user.
            Refer to :ref:`pages/dynamic:message` documentation for more details.
        style: An :class:`InquirerPyStyle` instance.
            Refer to :ref:`Style <pages/style:Alternate Syntax>` documentation for more details.
        vi_mode: Use vim keybinding for the prompt.
            Refer to :ref:`pages/kb:Keybindings` documentation for more details.
        default: Set the default text value of the prompt.
            Refer to :ref:`pages/dynamic:default` documentation for more details.
        qmark: Question mark symbol. Custom symbol that will be displayed infront of the question before its answered.
        amark: Answer mark symbol. Custom symbol that will be displayed infront of the question after its answered.
        instruction: Short instruction to display next to the question.
        long_instruction: Long instructions to display at the bottom of the prompt.
        completer: Add auto completion to the prompt.
            Refer to :ref:`pages/prompts/input:Auto Completion` documentation for more details.
        multicolumn_complete: Change the auto-completion UI to a multi column display.
        multiline: Enable multiline edit. While multiline edit is active, pressing `enter` won't complete the answer.
            and will create a new line. Use `esc` followd by `enter` to complete the question.
        validate: Add validation to user input.
            Refer to :ref:`pages/validator:Validator` documentation for more details.
        invalid_message: Error message to display when user input is invalid.
            Refer to :ref:`pages/validator:Validator` documentation for more details.
        transformer: A function which performs additional transformation on the value that gets printed to the terminal.
            Different than `filter` parameter, this is only visual effect and won’t affect the actual value returned by :meth:`~InquirerPy.base.simple.BaseSimplePrompt.execute`.
            Refer to :ref:`pages/dynamic:transformer` documentation for more details.
        filter: A function which performs additional transformation on the result.
            This affects the actual value returned by :meth:`~InquirerPy.base.simple.BaseSimplePrompt.execute`.
            Refer to :ref:`pages/dynamic:filter` documentation for more details.
        keybindings: Customise the builtin keybindings.
            Refer to :ref:`pages/kb:Keybindings` for more details.
        wrap_lines: Soft wrap question lines when question exceeds the terminal width.
        raise_keyboard_interrupt: Raise the :class:`KeyboardInterrupt` exception when `ctrl-c` is pressed. If false, the result
            will be `None` and the question is skiped.
        is_password: Used internally for :class:`~InquirerPy.prompts.secret.SecretPrompt`.
        mandatory: Indicate if the prompt is mandatory. If True, then the question cannot be skipped.
        mandatory_message: Error message to show when user attempts to skip mandatory prompt.
        session_result: Used internally for :ref:`index:Classic Syntax (PyInquirer)`.
        input: Used internally and will be removed in future updates.
        output: Used internally and will be removed in future updates.

    Examples:
        >>> from InquirerPy import inquirer
        >>> result = inquirer.text(message="Enter your name:").execute()
        >>> print(f"Name: {result}")
        Name: Michael
    NF ?Invalid inputTMandatory promptmessagestylevi_modedefaultqmarkamarkinstructionlong_instruction	completerr   multicolumn_complete	multilinevalidateinvalid_messagetransformerfilterkeybindings
wrap_linesraise_keyboard_interruptis_password	mandatorymandatory_messagesession_resultinputr   outputr   returnc                    sF  t  j||||||||||||||||d t jts&tt j dd  _t|	t	r5t
|	 _nt|	tr=|	 _| _|
sEtjntj _t fdd}|sUi }tj| dtjtjg|dgddigd| _d	d
 jigi _   t j j j j jd|| jt  j!| j j||rd|fgnd d _"d S )N)r&   r(   r)   r*   r/   r0   r1   r2   r9   r'   r4   r7   r8   r5   z) argument 'default' should be type of strc                      s    j S )N)
_multiline selfr>   U/home/ubuntu/veenaModal/venv/lib/python3.10/site-packages/InquirerPy/prompts/input.pyis_multiline   s   z*InputPrompt.__init__.<locals>.is_multiline)keyr2   rC   zc-space)answer
completionrE   funcFzclass:long_instruction)r$   key_bindingsr%   r,   	validatorvalidate_while_typingr:   r;   editing_modelexerr6   r.   complete_styler4   bottom_toolbar)#super__init__
isinstance_defaultstrr   type__name__
_completerdictr   from_nested_dictr   r=   r   COLUMNMULTI_COLUMN_complete_styler   r   EnterEscapekb_maps_handle_completionkb_func_lookup_keybinding_factoryr   _get_prompt_message_kb_style
_validator_editing_moder   _lexer_session)r@   r$   r%   r&   r'   r(   r)   r*   r+   r,   r-   r.   r/   r0   r1   r2   r3   r4   r5   r6   r7   r8   r9   r:   r;   rB   	__class__r?   rA   rO   U   s   

zInputPrompt.__init__c                 C   s    t j| jj_t|d| jj_d S )N)r$   )r
   INVALIDrg   default_buffervalidation_stater   validation_error)r@   r$   r>   r>   rA   
_set_error   s   zInputPrompt._set_erroreventr   c                 C   st   z| j j| j j W n ty   | j j  Y d S w d| jd< | j jj| jd< d| j j_|jj	| jd d d S )NTansweredresultr    )rq   )
rg   rH   r/   rk   r   validate_and_handlestatustextappexit)r@   ro   r>   r>   rA   _handle_enter   s   

zInputPrompt._handle_enterc                 C   s8   | j d u rd S |jj}|jr|  d S |jdd d S )NF)select_first)rU   ru   current_buffercomplete_statecomplete_nextstart_completion)r@   ro   buffr>   r>   rA   r^      s   
zInputPrompt._handle_completion
pre_answerpost_answerc                    s   |s| j r| jsd}nd| jrd| j ndf}|s^| j rU| jd rU| jd d}t|dkrLtd|dd	 }|d
  d||dkrFdndf 7  < dd|d
  f}n	dd| jd  f}t ||}| jd sv| j rv|	ddt
 f |S )a;  Get message to display infront of the input buffer.

        Args:
            pre_answer: The formatted text to display before answering the question.
            post_answer: The formatted text to display after answering the question.

        Returns:
            Formatted text in list of tuple format.
        )class:instructionz ESC + Enter to finish inputr   z %s  rq   
   r    Nr   z...[%s char%s]szclass:answerz %srp   zclass:questionmarkz
%s )r=   _instructionr*   rs   splitlenjoinrN   ra   appendr   )r@   r~   r   linesnumber_of_charsformatted_messagerh   r>   rA   ra      s.   


zInputPrompt._get_prompt_messagec                 C   s   | j j| jdS N)r'   )rg   promptrQ   r?   r>   r>   rA   _run   s   zInputPrompt._runc                    s   | j j| jdI d H S r   )rg   prompt_asyncrQ   r?   r>   r>   rA   
_run_async   s   zInputPrompt._run_async)NFr    r!   r!   r    r    NFFNr"   NNNTTFTr#   NNN)ro   r   r<   N)r<   N)NN)rT   
__module____qualname____doc__r   r   r   boolr   rR   r	   r   r   r   r   r   r   rO   rn   rw   r^   r   r   ra   r   r   __classcell__r>   r>   rh   rA   r   !   s    6	
b

*N)0r   typingr   r   r   r   r   r   r   r	   prompt_toolkit.bufferr
   prompt_toolkit.completionr   prompt_toolkit.completion.baser   prompt_toolkit.filters.baser   prompt_toolkit.keysr   prompt_toolkit.lexersr   prompt_toolkit.shortcuts.promptr   r   prompt_toolkit.validationr   InquirerPy.baser   InquirerPy.enumr   InquirerPy.exceptionsr   InquirerPy.utilsr   r   r   r   r   r   prompt_toolkit.input.baser   (prompt_toolkit.key_binding.key_processorr   prompt_toolkit.output.baser   __all__r   r>   r>   r>   rA   <module>   s(    ( 	