
    ^iBb                     l   d Z ddlZddlmZ ddl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mZmZmZmZ ddlmZmZ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*m+Z+ ddl,m-Z- ddl.m/Z/ ddl0m1Z1 ddl2m3Z3 ddl4m5Z5m6Z6m7Z7m8Z8m9Z9m:Z: erddl;m<Z< dgZ= G d de*      Z>y)z4Module contains the class to create a number prompt.    N)Decimal)TYPE_CHECKINGAnyCallableOptionalTupleUnioncast)Application)Buffer)	Condition)IsDone)Keys)ConditionalContainerHorizontalAlignHSplitVSplitWindow)BufferControlDummyControlFormattedTextControl)	DimensionLayoutDimension)Layout)SimpleLexer)ValidationError)BaseComplexPromptFakeDocument)InstructionWindow)ValidationWindow)INQUIRERPY_QMARK_SEQUENCE)InvalidArgument)InquirerPyDefaultInquirerPyKeybindingsInquirerPyMessageInquirerPySessionResultInquirerPyStyleInquirerPyValidate)KeyPressEventNumberPromptc            1           e Zd ZdZddddddddeddddddddd	d	d	d
dfdedee   dede	dedee
eef      dee
eef      dededede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e   d"df0 fd#Zd$ed"eeef   fd%Zd?d&Zd'ed"dfd(Zd?d)Zd?d*Zd?d+Zd?d,Zd@d-Zd?d.ZdAd/ee   d"dfd0Zd@d1Z d?d2Z!d3e"d"dfd4Z#d3e"d"dfd5Z$d3e"d"dfd6Z%d3e"d"dfd7Z&e'd"efd8       Z(e(jR                  d?d9       Z(e'd"e"fd:       Z*e'd"efd;       Z+e+jR                  d$ed"dfd<       Z+e'd"e
eee,f   fd=       Z-e-jR                  d$e
eee,f   d"dfd>       Z- xZ.S )Br*   u`  Create a input prompts that only takes number as input.

    A wrapper class around :class:`~prompt_toolkit.application.Application`.

    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 value of the prompt.
            You can enter either the floating value or integer value as the default.
            Refer to :ref:`pages/dynamic:default` documentation for more details.
        float_allowed: Allow decimal input. This will change the prompt to have 2 input buffer, one for the
            whole value and one for the integral value.
        min_allowed: Set the minimum value of the prompt. When the input value goes below this value, it
            will automatically reset to this value.
        max_allowed: Set the maximum value of the prompt. When the inptu value goes above this value, it
            will automatically reset to this value.
        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.
        decimal_symbol: Decimal point symbol. Custom symbol to display as the decimal point.
        replace_mode: Start each input buffer in replace mode if default value is 0.
            When typing, it will replace the 0 with the new value. The replace mode will be disabled once the value
            is changed.
        instruction: Short instruction to display next to the question.
        long_instruction: Long instructions to display at the bottom of the prompt.
        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.
        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.
        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)`.

    Examples:
        >>> from InquirerPy import inquirer
        >>> result = inquirer.number(message="Enter number:").execute()
        >>> print(result)
        0
    NFr   z. ? zInvalid inputTzMandatory promptmessagestylevi_modedefaultfloat_allowedmax_allowedmin_alloweddecimal_symbolreplace_modeqmarkamarkinstructionlong_instructionvalidateinvalid_messagetransformerfilterkeybindings
wrap_linesraise_keyboard_interrupt	mandatorymandatory_messagesession_resultreturnc                     t            ||||
||||||||||||       | _        t         fd       _        | _        | _        d _        | _        d _	        d _
        |	 _        t        j                  d       _        t        j                  d       _        d _        |	d}d _        t#        |t$              r t'        t$        |      |      } j                  r+t)        t+        t-        t'        t.        |                        } j                  rAt#        |t,              sbt#        |t(              sRt1        t3               j4                   d	      t#        |t.              s!t1        t3               j4                   d
      | _        |i }ddid j8                   dd j8                  dgddid j8                   dd j8                  dgddid j8                   dd j8                  dgddid j8                   dd j8                  dgddigdt:        j<                  iddigt?        d      D cg c]  }dt+        |      i c}ddigd| _         d jB                  igd jD                  igd jF                  igd jH                  igd jJ                  igd jL                  igd jN                  igd jP                  igd _)         jU                  t:        jV                        d         }d! _,        t[         j\                   j^                  "       _0        d! _1        t[         jd                   j^                  "       _3        ti         jj                  stm        jn                  d!      nd tq         j`                  ts        d#      $       fd%d&       _:        ti         jj                  stm        jn                  d!      nd tq         jf                  ts        d#      $       fd'(       _;        ty        t{        t}        ti         jj                  stm        jn                  d!      nd t         j                         jj                  dd)      t         jt                  t                *      t        ti         jj                  stm        jn                  d!      nd t        d+ j                  fg       jj                  dd)       j                  t                z  *      t         jv                   j                  t                z  *      gt        j                  ,      t        ti        t               -      t                 j                  z  *      t         j                   j                  t                z   jj                  .      t         j                  t                 j                  z   jj                  /      g             _L         jt                   _M        t         j                   j                   j                   j                   j                  0       _S        y c c}w )1N)r.   r/   r0   r7   r8   r=   r>   r<   r;   r9   r:   r@   rA   rB   rC   rD   c                       j                   S N)_floatselfs   c/mnt/e/genesis-system/.venvs/browser-army/lib/python3.12/site-packages/InquirerPy/prompts/number.py<lambda>z'NumberPrompt.__init__.<locals>.<lambda>   s    4;;     zRemove any non-integer valueFz^(0*)[0-9]+.*z^.*E-.*r   Tz: argument 'default' should return type of float or Decimalz- argument 'default' should return type of intkeydownzc-n)rO   r>   jupzc-pkleftzc-bhrightzc-fl.zs-tab
   -)rP   rR   rT   rV   dotfocusinputnegative_togglefunc)rP   rR   rT   rV   r\   r]   r^   r[   c                      y rH    )_s    rL   rb   z NumberPrompt.__init__.<locals>._   s    rN      )on_text_changedon_cursor_position_changedzclass:input)bufferlexerc                  \    t         j                   j                   j                        S N)minmax	preferred)r   _whole_widthrJ   s   rL   rM   z'NumberPrompt.__init__.<locals>.<lambda>   s'    )%%%%++ rN   )heightcontentwidthdont_extend_widthc                  \    t         j                   j                   j                        S ri   )r   _integral_widthrJ   s   rL   rM   z'NumberPrompt.__init__.<locals>.<lambda>  s'    )((((.. rN   )rn   ro   rp   )rn   ro   r@   dont_extend_heightrq   )r>   r-   )align)ro   )r<   r>   r@   )r.   r>   r@   )layoutr/   key_bindingsafter_renderediting_mode)Tsuper__init__rI   r   	_is_float_max_min_value_error_message_decimal_symbol_whole_replace_integral_replace_replace_moderecompile_leading_zero_pattern_sn_pattern_no_default
isinstancer   r
   r   strfloatintr"   type__name___default_is_vim_editr   Tabrangekb_maps_handle_down
_handle_up_handle_left_handle_right_handle_focus_handle_input_handle_negative_toggle_handle_dotkb_func_lookupregister_kbr   rm   r   _on_whole_text_change_on_cursor_position_change_whole_bufferrs   _on_integral_text_change_integral_bufferr   _wrap_linesr   exactr   r   _whole_window_integral_windowr   r   r   r   _get_prompt_messager   r   r   LEFTr   _is_displaying_long_instructionr    _get_error_message_is_invalidr   _long_instruction_layoutr\   r   _style_kb_after_render_editing_mode_application)rK   r.   r/   r0   r1   r2   r3   r4   r5   r6   r7   r8   r9   r:   r;   r<   r=   r>   r?   r@   rA   rB   rC   rD   irb   	__class__s   `                         rL   r{   zNumberPrompt.__init__i   s   4 	#+#-!%=/)! 	 	
& $"#67		$B!-#!&)%'ZZ0@%A"::j1 ?G#Dgx(-d8W-n=G;;c%S'(:";<=G;;gu-j'6R%Dz**++ef  GS)!:&&''TU   K $*;*;);<t'8'89 $*;*;);<t'8'89 $*;*;);<t'8'89  $*;*;);<t'8'89
 CL>dhh'%)9:/4Ry9!uc!fo9!&~1
2 3
8 d//01DOO,-d//01t1123t1123t1123!')E)E FGT--./	
 
		$((	#	 
$	 # 66'+'F'F

  ! & 99'+'F'F!

 $373C3C?((+!))!-0
 #
 !'373C3C?((+!,,!-0!
 "'+'7'7 (7'<'<Q'?%)(<T=U=U(V+/+;+;3726 11C1CVXIV0 &+/+;+; ,;+@+@+C)-,@*,d.B.B)C(D-& 04/?/?7;6:
!" (,~~	'A 1 $ 5 5dnnPVPXy>X3: .22=@ )|~6 &y4+O+OO %(,(?(?#//68);#'#3#3
 & $ 6 6 &y4+O+OO#'#3#3U/13
j ''
'<<++++++
c :s   Y valuec                     |j                  d      \  }}d}t        |      dz
  dz   |j                  dd       }||fS )zFix sciencetific notation format.

        Args:
            value: Value to fix.

        Returns:
            A tuple of whole buffer text and integral buffer text.
        zE-0rc   rX   r-   )splitr   replace)rK   r   rT   rV   whole_buffer_textintegral_buffer_texts         rL   _fix_snzNumberPrompt._fix_snI  sQ     kk$'e#&u:>S"8!9$,,sB:O9PQ "666rN   c                 x   | j                   ry| j                  s6t        | j                        | j                  _        d| j                  _        n| j                  j                  t        | j                              (t        | j                        j                  d      \  }}n'| j                  t        | j                              \  }}|| j                  _        || j                  _        t        | j                  j
                        | j                  _        t        | j                  j
                        | j                  _        | j                  rd| j                  j
                  dk(  rd| _        d| j                  _        | j                  j
                  dk(  rd| _        d| j                  _        yyy)z<Additional processing to adjust buffer content after render.Nr   rX   Tr   )r   rI   r   r   r   textr   r   matchr   r   lencursor_positionr   r   r   )rK   rb   r   r   s       rL   _on_renderedzNumberPrompt._on_renderedW  s_   {{&)$--&8D#),D!!&%%c$--&89A:=dmm:L:R:RSV:W7!#7:>,,&;7!#7 *>D!!&&7D#-01C1C1H1H-I*03D4I4I4N4N0O-!!&&#-&*#56""2$$))S0)-&89%%5 1 rN   	incrementc                    | j                   r&d| _         | j                  xj                  dz  c_        	 d}| j                  | j                  k(  rB| j                  j                  | j                  j                        }||j                  d      }t        | j                  j                        }| j                  j                  sd}d}n|sk| j                  | j                  k(  r#t        | j                  j                        dk(  ry|t        t        | j                  j                        dz
        z   }n.|t        t        | j                  j                        dz         z   }t        |      }| j                  j                  |z   |z
  }|| j                  _        || j                  _        | j                  j                  |k7  r|| j                  _        yy# t        $ r | j                  | j                         Y yw xY w)zHandle number increment and decrement.

        Additional processing to handle leading zeros in integral buffer
        as well as SN notation.

        Args:
            increment: Indicate if the operation should increment or decrement.
        Frc   r-   Nr   r   )r.   )buffer_replacefocus_bufferr   r   r   r   r   groupr   r   r   
ValueError
_set_errorr   )rK   r   leading_zeroszeroscurrent_text_len	next_textnext_text_lendesired_positions           rL   _handle_numberzNumberPrompt._handle_numberr  s    "'D--2-	?M  D$9$9922889N9N9S9ST$$)KKNM"4#4#4#9#9:$$))	 ! ))T-B-BB 1 1 6 671< -C8I8I8N8N4ORS4S0T TI -C8I8I8N8N4ORS4S0T TI #I!!11MADTT  1AD-%.D"  004DD4D!!1 E 	?OOD$=$=O>	?s   CG 	CG %HHc                 (    | j                  d       y)zHandle down key press.Fr   Nr   rK   rb   s     rL   r   zNumberPrompt._handle_down  s    e,rN   c                 (    | j                  d       y)zHandle up key press.Tr   Nr   r   s     rL   r   zNumberPrompt._handle_up  s    d+rN   c                     d| _         | j                  | j                  k(  r+| j                  j                  dk(  r| j
                  | _        y| j                  xj                  dz  c_        y)zHandle left key press.

        Move to the left by one cursor position and focus the whole window
        if applicable.
        Fr   rc   N)r   r\   r   r   r   r   r   s     rL   r   zNumberPrompt._handle_left  sV     $JJ$///!!11Q6++DJ--2-rN   c                 *   d| _         | j                  | j                  k(  rT| j                  j                  t        | j                  j                        k(  r| j                  r| j                  | _        y| j                  xj                  dz  c_        y)zHandle right key press.

        Move to the right by one cursor position and focus the integral window
        if applicable.
        Frc   N)	r   r\   r   r   r   r   r   rI   r   r   s     rL   r   zNumberPrompt._handle_right  sn     $JJ$,,,!!11S9J9J9O9O5PP..DJ--2-rN   c                    | j                   s| j                  j                  sd}nP| j                   r/| j                  j                  s| j                  j                  sd}nt	        | j
                        }	 t        |      }| j                  j                  |       d| j                  d<   || j                  d<   |j                  j                  |       y# t        $ r$}| j                  t	        |             Y d}~yd}~ww xY w)z/Handle enter event and answer/close the prompt.r-   Tansweredresult)r   N)rI   r   r   r   r   r   r   
_validatorr;   statusappexitr   r   )rK   eventr   fake_documentes        rL   _handle_enterzNumberPrompt._handle_enter  s    {{4#5#5#:#:FKK&&++))..F_F	*(0MOO$$]3 '+DKK
#$*DKK!IINN&N)  	$OOCF##	$s   7&C 	D!D  Dc                 <    | j                  || j                         y)z-Focus the integral window if `float_allowed`.N)r   r   r   s     rL   r   zNumberPrompt._handle_dot  s    1d334rN   windowc                     | j                   sy||| _        y| j                  | j                  k(  r| j                  | _        y| j                  | _        y)z1Focus either the integral window or whole window.N)rI   r\   r   r   )rK   rb   r   s      rL   r   zNumberPrompt._handle_focus  sH    {{DJ::+++..DJ++DJrN   c                    | j                   rOd| _         |j                  d   j                  | j                  _        | j                  xj
                  dz  c_        y| j                  j                  |j                  d   j                         y)zHandle user input of numbers.

        Buffer will start as replace mode if the value is zero, once
        cursor is moved or content is changed, disable replace mode.
        Fr   rc   N)r   key_sequencedatar   r   r   insert_text)rK   r   s     rL   r   zNumberPrompt._handle_input  sp     "'D%*%7%7%:%?%?D"--2-))%*<*<Q*?*D*DErN   c                 l   | j                   j                  dk(  rd| j                   _        y| j                   j                  j                  d      r| j                   j                  t	        | j                   j                        k  }| j                   j                  dd | j                   _        |r | j                   xj                  dz  c_        yy| j                   j                  dk7  }d| j                   j                   | j                   _        |r | j                   xj                  dz  c_        yy)zYToggle negativity of the prompt value.

        Force the `-` sign at the start.
        rZ   r   Nrc   r   )r   r   
startswithr   r   )rK   rb   move_cursors      rL   r   z$NumberPrompt._handle_negative_toggle  s   
 ""c)&)D#""--c2,,<<s""''@ K '+&8&8&=&=ab&AD#""22a72  ,,<<AK()$*<*<*A*A)B&CD#""22a72 rN   rf   c                 `    t        |j                        dz   | _        | j                  |       yz'Handle event of text changes in buffer.rc   N)r   r   rm   _on_text_changerK   rf   s     rL   r   z"NumberPrompt._on_whole_text_change  s&    ,q0V$rN   c                 `    t        |j                        dz   | _        | j                  |       yr   )r   r   rs   r   r   s     rL   r   z%NumberPrompt._on_integral_text_change  s&    "6;;/!3V$rN   c                     d| _         |j                  r |j                  dk7  r| j                  | _        |j                  j                  d      r|j                  dk(  rd|_        yyy)z=Disable replace mode and fix cursor position on text changes.FrZ   r   rc   N)r   r   r   r   r   r   s     rL   r   zNumberPrompt._on_text_change  sW    #;;6;;#-DJ;;!!#&6+A+AQ+F%&F" ,G&rN   c                 ~    | j                   j                  j                  d      r|j                  dk(  rd|_        yyy)z'Fix cursor position on cursor movement.rZ   r   rc   N)r   r   r   r   r   s     rL   r   z'NumberPrompt._on_cursor_position_change  s;    !!,,S1f6L6LPQ6Q%&F" 7R1rN   c                 d    | j                   | j                  k(  r| j                  S | j                  S )z"bool: Current buffer replace mode.r   r   r   r   rJ   s    rL   r   zNumberPrompt.buffer_replace$  s0      2 22&&&)))rN   c                 T    | j                   | j                  k(  r|| _        y || _        y rH   r   rK   r   s     rL   r   zNumberPrompt.buffer_replace,  s&     2 22"'D%*D"rN   c                 d    | j                   | j                  k(  r| j                  S | j                  S )z Buffer: Current editable buffer.)r\   r   r   r   rJ   s    rL   r   zNumberPrompt.focus_buffer3  s.     ::+++%%%(((rN   c                     | j                   S )zWindow: Current focused window.)_focusrJ   s    rL   r\   zNumberPrompt.focus;  s     {{rN   c                 \    || _         | j                  j                  | j                          y rH   )r   r   r\   r   s     rL   r\   zNumberPrompt.focus@  s    4;;'rN   c                 f   	 | j                   st        | j                  j                        S t	        | j                  j                   d| j
                  j                  r| j
                  j                  nd       S # t        $ r* | j                  | j                         | j                  cY S w xY w)zfUnion[int, float]: The actual value of the prompt, combining and transforming all input buffer values.rX   r   )
rI   r   r   r   r   r   r   r   r   r   rJ   s    rL   r   zNumberPrompt.valueE  s    		!;;4--2233))../qtOdOdOiOi1F1F1K1Kop0qr   	!OOD556== 	!s   *A= AA= =0B0/B0c                    | j                   @t        || j                  s| j                   nt        t	        | j                                     }| j
                  @t        || j                  s| j
                  nt        t	        | j
                                    }| j                  st	        |      | j                  _        y | j                  j                  t	        |            t	        |      j                  d      \  }}n| j                  t	        |            \  }}| j                  j                  r|| j                  _        | j                  j                  r|| j                  _        y y )NrX   )r~   rk   rI   r   r   r}   rj   r   r   r   r   r   r   r   )rK   r   r   r   s       rL   r   zNumberPrompt.valueS  s   99 tyyTYY9PE 99 tyyTYY9PE {{&)%jD#%%c%j19:=e*:J:J3:O7!#7:>,,s5z:R7!#7!!&&*;""'$$))-A%%* *rN   )rE   N)r   r)   rE   NrH   )/r   
__module____qualname____doc__r!   r%   r   r'   boolr#   r	   r   r   r   r(   r   r   r$   r&   r{   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   propertyr   setterr   r\   r   r   __classcell__)r   s   @rL   r*   r*   0   s\   6v ,0%&#3737"". "15.6:157;)-!3<@1^
"^
 (^
 	^

 #^
 ^
 eCJ/0^
 eCJ/0^
 ^
 ^
 ^
 ^
 ^
 ^
 -.^
  !^
" hucz23#^
$ 3%*-.%^
& 34'^
( )^
* #'+^
, -^
. /^
0 !!891^
2 
3^
@7S 7U38_ 7:6)? )? )?V-,33 *.5
,x'7 
,4 
,F8*%F %t %
%v %$ %
'f ' '' 'D '
 * * * + + )f ) ) v   \\(6 (d ( ( !uS%01 ! ! \\B5eW!45 B$ B BrN   )?r   r   decimalr   typingr   r   r   r   r   r	   r
   &prompt_toolkit.application.applicationr   prompt_toolkit.bufferr   prompt_toolkit.filters.baser   prompt_toolkit.filters.clir   prompt_toolkit.keysr    prompt_toolkit.layout.containersr   r   r   r   r   prompt_toolkit.layout.controlsr   r   r   prompt_toolkit.layout.dimensionr   r   prompt_toolkit.layout.layoutr   prompt_toolkit.lexers.baser   prompt_toolkit.validationr   InquirerPy.base.complexr   r   !InquirerPy.containers.instructionr    InquirerPy.containers.validationr    InquirerPy.enumr!   InquirerPy.exceptionsr"   InquirerPy.utilsr#   r$   r%   r&   r'   r(   (prompt_toolkit.key_binding.key_processorr)   __all__r*   ra   rN   rL   <module>r     s    : 	  M M M > ( 1 - $  
 G / 2 5 C ? = 5 1  F
xB$ xBrN   