
    tni+                     $   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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           e Zd ZdZ	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d0d	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%Zd	e	d$dfd&Zd1d)Zd2d*Z	 	 d3d+eee	e	f                  d,eee	e	f                  d$eee	e	f                  f fd-Zd$e	fd.Zd$efd/Z xZS )4r    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                     t                                          ||||||||||||||||           t           j        t                    s$t          t                     j         d          d  _        t          |	t                    rt          j        |	           _        nt          |	t                    r|	 _        | _        |
st          j        nt          j         _        t$           fd            }|si }t&          j        | dt&          j        t&          j        g|dgddigd| _        dd	 j        igi _                                          t5           j         j         j         j         j        d
|| j        tA           j!                  | j         j        ||rd|fgnd            _"        d S )N)r(   r*   r+   r,   r1   r2   r3   r4   r;   r)   r6   r9   r:   r7   z) argument 'default' should be type of strc                       j         S )N)
_multilineselfs   U/var/www/html/gpu-tools/venv/lib/python3.11/site-packages/InquirerPy/prompts/input.pyis_multilinez*InputPrompt.__init__.<locals>.is_multiline   s    ?"    )keyr4   rG   zc-space)answer
completionrI   funcFzclass:long_instruction)r&   key_bindingsr'   r.   	validatorvalidate_while_typingr<   r=   editing_modelexerr8   r0   complete_styler6   bottom_toolbar)#super__init__
isinstance_defaultstrr   type__name__
_completerdictr   from_nested_dictr   rA   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)rC   r&   r'   r(   r)   r*   r+   r,   r-   r.   r/   r0   r1   r2   r3   r4   r5   r6   r7   r8   r9   r:   r;   r<   r=   rE   	__class__s   `                         rD   rS   zInputPrompt.__init__U   s-   6 	#+#)!/%=! 	 	
 	
 	
$ $--- 	!::&QQQ   i&& 	(->yIIDOO	9-- 	('DO# (,M  + 	 
	# 	# 	# 	# 
	#  	K 
|m<<dj1\JJ "9-.
 
 
  ,vt7N.O-PQ  """%,+oo"'+dk**#o/!57GHII#
 
 
rF   c                 z    t           j        | j        j        _        t          |          | j        j        _        d S )N)r&   )r   INVALIDrk   default_buffervalidation_stater   validation_error)rC   r&   s     rD   
_set_errorzInputPrompt._set_error   s1    8G8O$58GPW8X8X8X$555rF   eventr   c                 l   	 | j         j                            | j         j                   d| j        d<   | j         j        j        | j        d<   d| j         j        _        |j                            | j        d                    d S # t          $ r" | j         j        	                                 Y d S w xY w)NTansweredresultr"   )rv   )
rk   rL   r1   ro   statustextappexitr   validate_and_handle)rC   rs   s     rD   _handle_enterzInputPrompt._handle_enter   s    	9M#,,T]-IJJJ '+DK
#$(M$@$EDK!02DM(-INN$+h"7N88888  	? 	? 	?M(<<>>>>>>	?s   )B (B32B3c                     | j         d S |j        j        }|j        r|                                 d S |                    d           d S )NF)select_first)rY   ry   current_buffercomplete_statecomplete_nextstart_completion)rC   rs   buffs      rD   rb   zInputPrompt._handle_completion   sY    ?"Fy' 	6     !!u!55555rF   
pre_answerpost_answerc                 f   |s&| j         r
| j        sd}nd| j        r
d| j        z  ndf}|s| j         r| j        d         r| j        d                             d          }t          |          dk    rIt          d                    |dd	                             }|d
xx         d|d|dk    rdnddz  cc<   dd|d
         z  f}ndd| j        d         z  f}t                                          ||          }| j        d         s&| j         r|	                    ddt          z  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  rv   
   r"   Nr   z...[z chars]zclass:answerz %sru   zclass:questionmarkz
%s )rA   _instructionr,   rw   splitlenjoinrR   re   appendr   )rC   r   r   linesnumber_of_charsformatted_messagerl   s         rD   re   zInputPrompt._get_prompt_message   s     	 t'8 R

 (151AJFT---s
  	N 
N4;x#8 
NH-33D99u::>>&)"''%)*<*<&=&=O!HHHH'.22::! HHH  .uuQx/?@-ut{87L/LM!GG77
KPP{:& 	4? 	$$%w1L'LM   ! rF   c                 B    | j                             | j                  S N)r)   )rk   promptrU   rB   s    rD   _runzInputPrompt._run   s    }##DM#:::rF   c                 R   K   | j                             | j                   d {V S r   )rk   prompt_asyncrU   rB   s    rD   
_run_asynczInputPrompt._run_async   s3      ]///FFFFFFFFFrF   )NFr"   r#   r#   r"   r"   NFFNr$   NNNTTFTr%   NNN)rs   r   r>   N)r>   N)NN)rX   
__module____qualname____doc__r   r   r   boolr   rV   r
   r   r   r   r   r   r   rS   rr   r|   rb   r	   r   re   r   r   __classcell__)rl   s   @rD   r    r    !   s	       1 1l ,0%' "LP%*15.6:157;)-!!3<@#'%)3`
 `
"`
 (`
 	`

 #`
 `
 `
 `
 `
 E$sHSM'9":K"GHI`
 #`
 `
 -.`
 `
 hucz23`
  3%*-.!`
" 34#`
$ %`
& #''`
( )`
* +`
, -`
. !!89/`
0  1`
2 "3`
4 
5`
 `
 `
 `
 `
 `
DY# Y$ Y Y Y Y	9 	9 	9 	96 6 6 6 1515(! (!U38_-(! eCHo.(! 
eCHo		(! (! (! (! (! (!T;c ; ; ; ;G# G G G G G G G GrF   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     rF   rD   <module>r      s   : : S S S S S S S S S S S S S S S S S S S S 1 1 1 1 1 1 5 5 5 5 5 5 4 4 4 4 4 4 1 1 1 1 1 1 $ $ $ $ $ $ - - - - - - H H H H H H H H 5 5 5 5 5 5 , , , , , , 7 7 7 7 7 7 1 1 1 1 1 1                 2//////FFFFFF111111/\G \G \G \G \G" \G \G \G \G \GrF   