
    AHjj                       d dl mZ d dlZd dlmZ d dlmZ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 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  er	 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-m.Z. d dl/m0Z0 d dl1m2Z2m3Z3m4Z4 d dl5m6Z6m7Z7 d dl8m9Z9 d dl:m;Z;m<Z< ed   Z=	 h dZ>	 ddddZ?ed   Z@ G d de	      ZA G d  d!e      ZBy)"    )annotationsN)	dataclass)TYPE_CHECKINGClassVarIterable
NamedTuple)cell_lenget_character_cell_size)RenderableType)Highlighter)Text)Literal)events)
SkipAction)expand_tabs_inline)Screen)
ScrollView)Strip)BindingBindingType)friendly_list)BlurFocusMount)OffsetRegionSizeclamp)Message)Reactivereactivevar)	SuggesterSuggestionReady)Timer)ValidationResult	Validator)blurchanged	submitted>   r(   r)   r*   z[-+]?(?:\d*|\d+_)*z@[-+]?(?:\d*|\d+_)*\.?(?:\d*|\d+_)*(?:\d[eE]?[-+]?(?:\d*|\d+_)*)?)integernumbertextc                  J    e Zd ZU dZded<   ded<   edd       Zed	d       Zy)
	Selectiona  A range of selected text within the Input.

    Text can be selected by clicking and dragging the mouse, or by pressing
    shift+arrow keys.

    Attributes:
        start: The start index of the selection.
        end: The end index of the selection.
    intstartendc                     | ||      S )z*Create a selection from a cursor position. )clscursor_positions     N/root/tools/cai/cai_env/lib/python3.12/site-packages/textual/widgets/_input.pycursorzSelection.cursor<   s     ?O44    c                4    | j                   | j                  k(  S )z&Return True if the selection is empty.)r1   r2   selfs    r7   is_emptyzSelection.is_emptyA   s     zzTXX%%r9   N)r6   r0   returnr/   r>   bool)	__name__
__module____qualname____doc____annotations__classmethodr8   propertyr=   r4   r9   r7   r/   r/   .   s9     J	H5 5 & &r9   r/   c                      e Zd ZU dZ edddd       eddd	d       ed
ddd       edddd       edddd       edddd       edddd       edddd       edddd       edd d!d       ed"d#d$d       ed%d&d'd       ed(d)d*d       ed+d,d-d       ed.d/d0d       ed1d2d3d       ed4d5d6d       ed7d8d9d       ed:d;d<d       ed=d>d?d       ed@dAdBd       edCdDdEd       edFdGdHd      gZdIedJ<   	 h dKZdLedM<   	 dNZ e	dOdP      Z
 e	dQdP      ZdRedS<   eddT       Zej                  ddU       Z e	ej!                  dV            ZdWedX<   	  e	dQ      Z e	dO      Z e	d      ZdYedZ<   	  e	dQ      Z	  ed[   d\      Z	  ee   d]      Z	  ed^   d\      Z	  ed      Z	  e	dd_`      Z	 e G da dbe             Ze G dc dde             Z e G de dfe             Z!	 	 	 	 dd\d]dVd\d\d\ddOd\d\d\dd\ddg	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d fdhZ"ddiZ#eddj       Z$eddk       Z%eddl       Z&ddmZ'ddnZ(ddoZ)ddpZ*eddq       Z+ddrZ,ddsZ-ddtZ.eddu       Z/ddvZ0eddw       Z1eddx       Z2ddyZ3ddzZ4dd{Z5dd|Z6dd}Z7dd~Z8ddZ9ddZ:ddZ;ddZ<ddZ=ddZ>ddZ?ddZ@ddZAddZBdddZCddZDddZEddZFedd       ZGdddZHdddZIddZJddZKdddZLdddZM eNj                  d      ZPdddZQdddZRddZSddZTddZUddZVddZWddZXddZYddZZddZ[ddZ\ddZ]ddZ^ddZ_ddZ` xZaS )InputzA text input widget.leftcursor_leftzMove cursor leftF)showz
shift+leftzcursor_left(True)zMove cursor left and selectz	ctrl+leftcursor_left_wordzMove cursor left a wordzctrl+shift+leftzcursor_left_word(True)z"Move cursor left a word and selectrightcursor_rightz5Move cursor right or accept the completion suggestionzshift+rightzcursor_right(True)zMove cursor right and selectz
ctrl+rightcursor_right_wordzMove cursor right a wordzctrl+shift+rightzcursor_right_word(True)z#Move cursor right a word and select	backspacedelete_leftzDelete character leftzctrl+shift+a
select_allz
Select allzhome,ctrl+ahomezGo to startz
end,ctrl+er2   z	Go to endz
shift+homez
home(True)zSelect line startz	shift+endz	end(True)zSelect line endzdelete,ctrl+ddelete_rightzDelete character rightentersubmitSubmitzctrl+wdelete_left_wordzDelete left to start of wordzctrl+udelete_left_allzDelete all to the leftzctrl+fdelete_right_wordzDelete right to start of wordzctrl+kdelete_right_allzDelete all to the rightzctrl+xcutzCut selected textzctrl+ccopyzCopy selected textzctrl+vpastezPaste text from the clipboardzClassVar[list[BindingType]]BINDINGS>   input--cursorinput--selectioninput--suggestioninput--placeholderzClassVar[set[str]]COMPONENT_CLASSESa  
    Input {
        background: $surface;
        color: $foreground;
        padding: 0 2;
        border: tall $border-blurred;
        width: 100%;
        height: 3;
        scrollbar-size-horizontal: 0;

        &.-textual-compact {
            border: none !important;
            height: 1;
            padding: 0;
            &.-invalid {
                background-tint: $error 20%;
            }
        }

        &:focus {
            border: tall $border;
            background-tint: $foreground 5%;
        }
        &>.input--cursor {
            background: $input-cursor-background;
            color: $input-cursor-foreground;
            text-style: $input-cursor-text-style;
        }
        &>.input--selection {
            background: $input-selection-background;
        }
        &>.input--placeholder, &>.input--suggestion {
            color: $text-disabled;
        }
        &.-invalid {
            border: tall $error 60%;
        }
        &.-invalid:focus {
            border: tall $error;
        }

        &:ansi {
            background: ansi_default;
            color: ansi_default;
            &>.input--cursor {
                text-style: reverse;
            }
            &>.input--placeholder, &>.input--suggestion {
                text-style: dim;
                color: ansi_default;
            }
            &.-invalid {
                border: tall ansi_red;
            }
            &.-invalid:focus {
                border: tall ansi_red;
            }
        }
    }

    T)init zReactive[str]valuec                .    | j                   j                  S )zNThe current position of the cursor, corresponding to the end of the selection.)	selectionr2   r;   s    r7   r6   zInput.cursor_position   s     ~~!!!r9   c                8    t         j                  |      | _        y)z'Set the current position of the cursor.N)r/   r8   rj   r<   positions     r7   r6   zInput.cursor_position   s     #))(3r9   r   zReactive[Selection]rj   Suggester | None	suggester
str | NoneNr-   z
int | Nonez-textual-compact)toggle_classc                  L    e Zd ZU dZded<   	 ded<   	 dZded<   	 ed
d	       Zy)Input.ChangedzPosted when the value changes.

        Can be handled using `on_input_changed` in a subclass of `Input` or in a parent
        widget in the DOM.
        rI   inputstrrh   NValidationResult | Nonevalidation_resultc                    | j                   S zAlias for self.input.rt   r;   s    r7   controlzInput.Changed.control#       ::r9   r>   rI   rA   rB   rC   rD   rE   rw   rG   r{   r4   r9   r7   Changedrs     ?    	 2
65929	s 
	 
	r9   r   c                  L    e Zd ZU dZded<   	 ded<   	 dZded<   	 ed
d	       Zy)Input.SubmittedzPosted when the enter key is pressed within an `Input`.

        Can be handled using `on_input_submitted` in a subclass of `Input` or in a
        parent widget in the DOM.
        rI   rt   ru   rh   Nrv   rw   c                    | j                   S ry   rz   r;   s    r7   r{   zInput.Submitted.control9  r|   r9   r}   r~   r4   r9   r7   	Submittedr   (  s>    	 9
75929	0 
	 
	r9   r   c                  L    e Zd ZU dZded<   	 ded<   	 dZded<   	 ed
d	       Zy)Input.BlurredzPosted when the widget is blurred (loses focus).

        Can be handled using `on_input_blurred` in a subclass of `Input` or in a parent
        widget in the DOM.
        rI   rt   ru   rh   Nrv   rw   c                    | j                   S ry   rz   r;   s    r7   r{   zInput.Blurred.controlP  r|   r9   r}   r~   r4   r9   r7   Blurredr   >  r   r9   r   )restricttype
max_lengthro   
validatorsvalidate_onvalid_emptyselect_on_focusnameidclassesdisabledtooltipcompactc                  t         |   ||||       d| _        	 || _        || _        || _        || _        t        |	t              r	|	g| _	        n|	g | _	        nt        |	      | _	        |
t        t        |
      z  nt        | _        	 || _        d| _        || _        |t"        vr,t%        dt'        t"        j)                                d|      || _        || _        | j                  sgddlm}m} | j*                  dk(  r!| j                  j5                   |              n/| j*                  d	k(  r | j                  j5                   |              d
| _        	 d| _        	 ||| _        ||| _        || _        || _         y)a\  Initialise the `Input` widget.

        Args:
            value: An optional default value for the input.
            placeholder: Optional placeholder text for the input.
            highlighter: An optional highlighter for the input.
            password: Flag to say if the field should obfuscate its content.
            restrict: A regex to restrict character inputs.
            type: The type of the input.
            max_length: The maximum length of the input, or 0 for no maximum length.
            suggester: [`Suggester`][textual.suggester.Suggester] associated with this
                input instance.
            validators: An iterable of validators that the Input value will be checked against.
            validate_on: Zero or more of the values "blur", "changed", and "submitted",
                which determine when to do input validation. The default is to do
                validation for all messages.
            valid_empty: Empty values are valid.
            select_on_focus: Whether to select all text on focus.
            name: Optional name for the input widget.
            id: Optional ID for the widget.
            classes: Optional initial classes for the widget.
            disabled: Whether the input is disabled or not.
            tooltip: Optional tooltip.
            compact: Enable compact style (without borders).
        )r   r   r   r   NTzInput type must be one of z; not r   )IntegerNumberr+   r,   F)!super__init___blink_timerplaceholderhighlighterpasswordro   
isinstancer'   r   list_POSSIBLE_VALIDATE_ON_VALUESsetr   _reactive_valid_empty_validr   _RESTRICT_TYPES
ValueErrorr   keysr   r   textual.validationr   r   append
_selecting_initial_valuerh   r   r   r   )r<   rh   r   r   r   r   r   r   ro   r   r   r   r   r   r   r   r   r   r   r   r   	__class__s                        r7   r   zInput.__init__U  s   ^ 	dr7XN*.W&& " j),0:|DO DO":.DO & *C,<<- 	
	 &1" &,]?;O;O;Q-R,SSYZ^Yab  	$:yyI%&&wy1h&&&vx0@"IDJ"DL.r9   c                F    t        t        | j                  d| d            S )zConvert an index within the value to cell position.

        Args:
            position: The index within the value to convert.

        Returns:
            The cell position corresponding to the index.
        N   )r	   r   rh   rl   s     r7   _position_to_cellzInput._position_to_cell  s"     *4::ix+@!DEEr9   c                ^    | j                  | j                        }| j                  r|dz  }|S )zThe cell offset of the cursor.   )r   r6   cursor_at_end)r<   offsets     r7   _cursor_offsetzInput._cursor_offset  s1     ''(<(<=aKFr9   c                     | j                   dk(  S )z/Flag to indicate if the cursor is at the start.r   )r6   r;   s    r7   cursor_at_startzInput.cursor_at_start  s     ##q((r9   c                F    | j                   t        | j                        k(  S )z-Flag to indicate if the cursor is at the end.)r6   lenrh   r;   s    r7   r   zInput.cursor_at_end  s     ##s4::66r9   c                .    |duxr |j                         S )az  Check if the widget may consume the given key.

        As an input we are expecting to capture printable keys.

        Args:
            key: A key identifier.
            character: A character associated with the key, or `None` if there isn't one.

        Returns:
            `True` if the widget may capture the key in it's `Key` message, or `False` if it won't.
        N)isprintable)r<   key	characters      r7   check_consume_keyzInput.check_consume_key  s     $@)>)>)@@r9   c                z    |\  }}t        | j                        }t        t        |d|      t        |d|            S Nr   )r   rh   r/   r   )r<   rj   r1   r2   value_lengths        r7   validate_selectionzInput.validate_selection  s7    
s4::ua6c1l8STTr9   c                    | j                   j                          | j                  | j                   _        | j                  s,| j                  t        | j                  ddd      dd       y y )Nr   r   )widthheightTF)forceanimate)appclear_selectioncursor_screen_offsetr6   r   scroll_to_regionr   r   )r<   rj   s     r7   _watch_selectionzInput._watch_selection  s_      "#'#<#< ""!!t**AQqA "  #r9   c                    | j                   5|r| j                   j                          y| j                          d| _        yy)z6Ensure we handle updating the cursor blink at runtime.NT)r   resume_pause_blink_cursor_visible)r<   blinks     r7   _watch_cursor_blinkzInput._watch_cursor_blink  s<    (!!((*!!#'+$ )r9   c                z    | j                   \  }}}}| j                  \  }}t        || j                  z   |z
  |      S )zMThe offset of the cursor of this input in screen-space. (x, y)/(column, row).)content_regionscroll_offsetr   r   )r<   xy_width_heightscroll_x_s          r7   r   zInput.cursor_screen_offset  sD     !% 3 31fg((!a$---8!<<r9   c                   t        | j                  d      | _        d| _        | j                  r-|r+| j                  | j                  j                  | |             | j                  j                  r| j                  d       d| j                  v r| j                  |      nd}| j                  | j                  | ||             | j                  r"t        | j                         | _        d| _        y| j$                  | _        y)z>Update the virtual size and suggestion when the value changes.r   rg   T)layoutr)   NF)r   content_widthvirtual_size_suggestionro   
run_worker_get_suggestionstylesauto_dimensionsrefreshr   validatepost_messager   r   r   rh   r6   rj   )r<   rh   rw   s      r7   _watch_valuezInput._watch_value  s     !3!3Q7>>eOODNN::4GH;;&&LLL% %.1A1A$ADMM% t 	 	$,,tU4EFG #&tzz?D "'D "^^DNr9   c                :    | j                  | j                         y)z+Repeat validation when valid_empty changes.N)r   rh   r;   s    r7   _watch_valid_emptyzInput._watch_valid_empty)  s    $**%r9   c                8    d fd} j                   sd _         |        y j                  r|sd _         |        y j                   D cg c]  }|j                  |       }}t	        j
                  |      }|j                   _         |        |S c c}w )a  Run all the validators associated with this Input on the supplied value.

        Runs all validators, combines the result into one. If any of the validators
        failed, the combined result will be a failure. If no validators are present,
        None will be returned. This also sets the `-invalid` CSS class on the Input
        if the validation fails, and sets the `-valid` CSS class on the Input if
        the validation succeeds.

        Returns:
            A ValidationResult indicating whether *all* validators succeeded or not.
                That is, if *any* validator fails, the result will be an unsuccessful
                validation.
        c                 h    j                   } j                  |  d       j                  | d       y)zSet classes for valid flag.z-invalidz-validN)r   	set_class)validr<   s    r7   set_classesz#Input.validate.<locals>.set_classes<  s*    KKENNu9j1NN5(+r9   TNr>   None)r   r   r   r   r&   mergeis_valid)r<   rh   r   	validatorvalidation_resultscombined_results   `     r7   r   zInput.validate-  s    	, DKMEDKM 8<6
*3Iu%6
 6
 +001CD%..6
s   Bc                    | j                   S )z)Check if the value has passed validation.)r   r;   s    r7   r   zInput.is_validV  s     {{r9   c           	        |dk7  r4t        j                  | j                  j                  | j                        S | j
                  j                  }| j
                  j                  }| j                  j                  }| j                  st        | j                  dd      }|j                  | j                  d             | j                  rK| j                  d      }| j                  r.t!        |      dk(  rt        dd      }|j                  |dd	       t        |j#                  ||j%                  |d	z                     }n| j&                  }| j                  }	t!        |	      }
| j(                  }t!        |      |
kD  xr | j                  }|r#|t        ||
d  | j                  d
      d      z  }| j                  r| j*                  j,                  sC| j*                  \  }}t/        ||f      \  }}| j                  d      }|j1                  |||       | j                  rR| j                  d      }| j2                  }|s| j4                  r|j7                  d	       |j                  |||d	z          t9        |j#                  ||j%                  | j:                                    }t        |      }| j<                  \  }}|j?                  |||z   d	z         }|jA                  |d	z         }|jC                  | j                        S )Nr   rJ   rg   )justifyr2   rd   ra    )r2   r   rc   rb   )"r   blanksizer   
rich_styler   consoleconsole_optionsscrollable_content_regionrh   r   r   stylizeget_component_rich_style	has_focusr   r   renderupdate_width_valuer   rj   r=   sortedstylize_beforer6   r   	pad_rightr   r   r   cropextend_cell_lengthapply_style)r<   r   r   r   max_content_widthr   cursor_stylestripresultrh   r   
suggestionshow_suggestionr1   r2   selection_styler8   segmentsr   r   s                       r7   render_linezInput.render_line[  s   6;;tyy@@((""((22 ::@@zzt//RHK = =>R ST~~#<<_M'' ;'1,&*3B&7''a;!=!=>ORS>S!TE [[F JJEu:L))J!*o<OO$|}-112EF  ~~~~..!%JE3!'!5JE3&*&C&CDV&WO))/5#F''#'#@#@#QL!11F*t/A/A((+NN<!Dv'C'CDDVDV'WXH (OE,,KHaJJx4E)E)IJE,,->-BCE  11r9   c                    | j                   r%t        dt        | j                        z  ddd      S t        | j                  ddd      }| j                  | j	                  |      }|S )zValue rendered as text.u   •Tignorerg   )no_wrapoverflowr2   )r   r   r   rh   r   r<   r-   s     r7   r  zInput._value  s_     ==DJJ/VXYY

D8LD+''-Kr9   c                    | j                   r!| j                  st        | j                         S | j                  j                  dz   S )zThe width of the content.r   )r   rh   r	   r  r;   s    r7   r   zInput.content_width  s;     DJJD,,-- {{##a''r9   c                    | j                   S )zGet the widget of the content.)r   )r<   	containerviewports      r7   get_content_widthzInput.get_content_width  s    !!!r9   c                     y)Nr   r4   )r<   r  r  r   s       r7   get_content_heightzInput.get_content_height  s    r9   c                d    | j                   j                  r| j                   | _        yd| _        y)zToggle visibility of cursor.TN)screen	is_activer   r;   s    r7   _toggle_cursorzInput._toggle_cursor  s(    ;;  '+';';#;D #'D r9   c                     d fd} j                   j                  j                   |d        j                  d j                   j
                  xr  j                          _        y )Nc                N    t         j                  j                        _        y)zASignal callback to unselect when arbitrary text selection starts.N)r/   r8   r6   rj   )r"  r<   s    r7   text_selection_startedz/Input._on_mount.<locals>.text_selection_started  s    &--d.B.BCDNr9   T)	immediateg      ?)pause)r"  r   r>   r   )r"  text_selection_started_signal	subscribeset_intervalr$  cursor_blinkr  r   )r<   eventr'  s   `  r7   	_on_mountzInput._on_mount  sk    	D 	11;;(D 	< 	
 !--((;T^^< . 
r9   c                    | j                          d| j                  v r| j                  | j                        nd }| j	                  | j                  | | j                  |             y )Nr(   )r   r   r   rh   r   r   )r<   r.  rw   s      r7   _on_blurzInput._on_blur  sT    )/43C3C)CDMM$**% 	 	$,,tTZZ9JKLr9   c                    | j                          | j                  r0|j                  s$t        dt	        | j
                              | _        | j                  | j                  _	        d| _
        y )Nr   rg   )_restart_blinkr   from_app_focusr/   r   rh   rj   r   r   r6   r   r<   r.  s     r7   	_on_focuszInput._on_focus  sO    (<(<&q#djj/:DN#'#<#< r9   c                D  K   | j                          |j                  r|j                          |j                  J | j                  }|j
                  r| j                  |j                         n | j                  |j                  g|  |j                          y y wN)	r3  is_printablestopr   rj   r=   insert_text_at_cursorreplaceprevent_default)r<   r.  rj   s      r7   _on_keyzInput._on_key  s     JJL??...I!!**5??;U__9y9!!# s   BB c                    |j                   rZ|j                   j                         d   }| j                  }|j                  r| j	                  |       n | j
                  |g|  |j                          y r   )r-   
splitlinesrj   r=   r;  r<  r:  )r<   r.  linerj   s       r7   	_on_pastezInput._on_paste  s\    ::::((*1-DI!!**40T.I.

r9   c                    d}t         }| j                  \  }}||z  }t        | j                        D ]%  \  }} ||      }||cxk  r||z   k  r|c S  ||z  }' t	        |dt        | j                              S )zConvert a cell offset to a character index, accounting for character width.

        Args:
            offset: The cell offset to convert.

        Returns:
            The character index corresponding to the cell offset.
        r   )r
   r   	enumeraterh   r   r   )	r<   r   cell_offset
_cell_sizer   r   indexchar
cell_widths	            r7   _cell_offset_to_indexzInput._cell_offset_to_index  s     ,
((!($TZZ0 	&KE4#D)JfAj(@A B:%K		&
 VQDJJ00r9   c                   K   | j                  d       |j                  |       \  }}t        j                  | j	                  |            | _        d| _        | j                          y w)NT)visible)r   get_content_offset_capturer/   r8   rJ  rj   r   capture_mouse)r<   r.  offset_xr   s       r7   _on_mouse_downzInput._on_mouse_down  s[     $'66t<!"))$*D*DX*NOs   A(A*c                l    | j                   r(d| _         | j                          | j                          yy)z(End selecting if it is currently active.FN)r   release_mouser3  r;   s    r7   _end_selectingzInput._end_selecting  s-    ??#DO ! r9   c                ,   K   | j                          y wr8  rS  r<   _events     r7   _on_mouse_releasezInput._on_mouse_release          c                ,   K   | j                          y wr8  rU  rV  s     r7   _on_mouse_upzInput._on_mouse_up  rY  rZ  c                   K   | j                   rK|j                  |       }| j                  \  }}t        || j	                  |j
                              | _        y y wr8  )r   rM  rj   r/   rJ  r   )r<   r.  r   selection_startr   s        r7   _on_mouse_movezInput._on_mouse_move  sR     ?? 55d;F!%OQ&!;!;FHH!EDN    AAc                b   K   |j                   | j                   k(  r|j                  | _        yyw)z@Handle suggestion messages and set the suggestion when relevant.N)rh   r  r   r5  s     r7   _on_suggestion_readyzInput._on_suggestion_ready#  s)     ;;$**$$//D %s   -/c                z    d| _         | j                  r(| j                  r| j                  j                          yyy)zRestart the cursor blink cycle.TN)r   r-  r   resetr;   s    r7   r3  zInput._restart_blink(  s5    #!2!2##% "3r9   c                `    || _         | j                  r| j                  j                          yy)z3Hide the blinking cursor and pause the blink cycle.N)r   r   r)  )r<   rL  s     r7   r   zInput._pause_blink.  s*    &##% r9   c                <    | j                  || j                         y)zInsert new text at the cursor, move the cursor to the end of the new text.

        Args:
            text: New text to insert.
        N)insertr6   r  s     r7   r;  zInput.insert_text_at_cursor4  s     	D$../r9   c                8    | j                   j                          y)zCalled when a character has been restricted.

        The default behavior is to play the system bell.
        You may want to override this method if you want to disable the bell or do something else entirely.
        N)r   bellr;   s    r7   
restrictedzInput.restricted<  s     	r9   c                    d| _         y)zClear the input.rg   N)rh   r;   s    r7   clearzInput.clearD  s	    
r9   c                P    t        | j                        \  }}| j                  || S )zCThe text between the start and end points of the current selection.)r  rj   rh   r<   r1   r2   s      r7   selected_textzInput.selected_textH  s'     DNN+
szz%$$r9   c                    | j                   \  }}|rt        ||dz
        | _         y| j                   j                  r| xj                  dz  c_        yt	        ||      | _        y)zMove the cursor one position to the left.

        Args:
            select: If `True`, select the text to the left of the cursor.
        r   N)rj   r/   r=   r6   minr<   selectr1   r2   s       r7   action_cursor_leftzInput.action_cursor_leftN  sR     ^^
s&ucAg6DN~~&&$$)$'*5#$r9   c                R   | j                   \  }}|rt        ||dz         | _         y| j                  r8| j                  r,| j                  | _        t        | j                        | _        y| j                   j                  r| xj                  dz  c_        yt        ||      | _        y)zAccept an auto-completion or move the cursor one position to the right.

        Args:
            select: If `True`, select the text to the right of the cursor.
        r   N)	rj   r/   r   r   rh   r   r6   r=   maxrr  s       r7   action_cursor_rightzInput.action_cursor_right]  s     ^^
s&ucAg6DN!!d&6&6!--
'*4::$>>**((A-(+.uc?D(r9   c                Z    t        dt        | j                              | _        d| _        y)$Select all of the text in the Input.r   rg   N)r/   r   rh   rj   r   r;   s    r7   rS   zInput.select_allp  s     "1c$**o6r9   c                $    | j                          y)ry  N)rS   r;   s    r7   action_select_allzInput.action_select_allu  s    r9   c                N    |rt        | j                  d      | _        yd| _        y)zMove the cursor to the start of the input.

        Args:
            select: If `True`, select the text between the old and new cursor positions.
        r   N)r/   r6   rj   r<   rs  s     r7   action_homezInput.action_homey  s#     &t';';Q?DN#$D r9   c                    |r/t        | j                  t        | j                              | _        yt        | j                        | _        y)zMove the cursor to the end of the input.

        Args:
            select: If `True`, select the text between the old and new cursor positions.
        N)r/   r6   r   rh   rj   r}  s     r7   
action_endzInput.action_end  s3     &t';';S_MDN#&tzz?D r9   z	(?<=\W)\wc                L   | j                   r| j                  |       y| j                  \  }}	 t        j                  | j
                  | j                  d| j                         ^ }}|j                         }|rt        ||      | _        y|| _        y# t        $ r d}Y )w xY w)zMove the cursor left to the start of a word.

        Args:
            select: If `True`, select the text between the old and new cursor positions.
        Nr   )r   r~  rj   refinditer_WORD_STARTrh   r6   r1   r   r/   )r<   rs  r1   r   hittargets         r7   action_cursor_left_wordzInput.action_cursor_left_word  s     == V$~~HE1%++$$djj1G43G3G&HC !*5&!9'-$  s   :B B#"B#c                X   | j                   r| j                  |       yt        j                  | j                  | j
                  | j                  d       }| j                  \  }}|t        | j
                        }n||j                         z   }|rt        ||      | _        y|| _        y)zMove the cursor right to the start of a word.

        Args:
            select: If `True`, select the text between the old and new cursor positions.
        N)r   r  r  searchr  rh   r6   rj   r   r1   r/   )r<   rs  r  r1   r2   r  s         r7   action_cursor_right_wordzInput.action_cursor_right_word  s     == OOF#))D,,djj9M9M9O.PQCJE3{TZZsyy{*!*5&!9'-$r9   c                    d fd} j                   }t        t        d|      t        t	        |      |      f      \  }}|d|  | ||d  } ||      r| _         |t	        |      z    _        y j                          y)a  Replace the text between the start and end locations with the given text.

        Args:
            text: Text to replace the existing text with.
            start: Start index to replace (inclusive).
            end: End index to replace (inclusive).
        c                4   j                   rt        |       j                   kD  ryj                  r!t        j                  j                  |       yj
                  r9t        j                  j
                  d      }|t        j                  ||       yy)z!Check if new value is restricted.FNT)r   r   r   r  	fullmatchr   r   get)rh   type_restrictr<   s     r7   check_allowed_valuez*Input.replace.<locals>.check_allowed_value  sv     3u:#?}}dmmU!C!Kyy / 3 3DIIt D!-]E:B r9   r   N)rh   ru   r>   r@   )rh   r  rv  rq  r   r6   rj  )r<   r-   r1   r2   r  rh   	new_values   `      r7   r<  zInput.replace  s    	( 

SE]CE
C,@AB
sVe}odVE#$K=9	y)"DJ#(3t9#4D OOr9   c                *    | j                  |||       y)zInsert text at the given index.

        Args:
            text: Text to insert.
            index: Index to insert the text at (inclusive).
        Nr<  )r<   r-   rG  s      r7   rg  zInput.insert  s     	T5%(r9   c                *    | j                  d||       y)zDelete the text between the start and end locations.

        Args:
            start: Start index to delete (inclusive).
            end: End index to delete (inclusive).
        rg   Nr  rn  s      r7   deletezInput.delete  s     	R$r9   c                6     | j                   | j                    y)zDelete the current selection.N)r  rj   r;   s    r7   delete_selectionzInput.delete_selection  s    T^^$r9   c                    | j                   j                  r*| j                  | j                  | j                  dz          y| j	                          y)z4Delete one character at the current cursor position.r   Nrj   r=   r  r6   r  r;   s    r7   action_delete_rightzInput.action_delete_right  s:    >>""KK,,d.B.BQ.FG!!#r9   c                   | j                   j                  s| j                          y| j                  r| j	                          y| j
                  | j                  d }t        j                  | j                  |      }|| j	                          y| j                  }||j                         z   dz
  }| j                  ||       y)zMDelete the current character and all rightward to the start of the next word.Nr   )rj   r=   r  r   action_delete_right_allrh   r6   r  r  r  r2   r  )r<   afterr  r1   r2   s        r7   action_delete_right_wordzInput.action_delete_right_word  s    ~~&&!!#== ((*JJt3356E))D,,e4C{,,.,,cggi'!+E3'r9   c                    | j                   j                  r0| j                  | j                  t	        | j
                               y| j                          y)zTDelete the current character and all characters to the right of the cursor position.N)rj   r=   r  r6   r   rh   r  r;   s    r7   r  zInput.action_delete_right_all  s7    >>""KK,,c$**o>!!#r9   c                    | j                   j                  r*| j                  | j                  dz
  | j                         y| j	                          y)z@Delete one character to the left of the current cursor position.r   Nr  r;   s    r7   action_delete_leftzInput.action_delete_left!  s:    >>""KK,,q0$2F2FG!!#r9   c                |   | j                   j                  s| j                          y| j                  r| j	                          y	 t        j                  | j                  | j                  d| j                         ^ }}|j                         }| j                  || j                         y# t        $ r d}Y *w xY w)z>Delete leftward of the cursor position to the start of a word.Nr   )rj   r=   r  r   action_delete_left_allr  r  r  rh   r6   r1   r   r  )r<   r   r  r  s       r7   action_delete_left_wordzInput.action_delete_left_word(  s    ~~&&!!#== '')%++$$djj1G43G3G&HC KK 4 45  s   :B- -B;:B;c                    | j                   j                  r| j                  d| j                         y| j	                          y)z9Delete all characters to the left of the cursor position.r   Nr  r;   s    r7   r  zInput.action_delete_left_all>  s/    >>""KK4//0!!#r9   c                   K   d| j                   v r| j                  | j                        nd}| j                  | j	                  | | j                  |             yw)zzHandle a submit action.

        Normally triggered by the user pressing Enter. This may also run any validators.
        r*   N)r   r   rh   r   r   )r<   rw   s     r7   action_submitzInput.action_submitE  sN      *58H8H)HDMM$**%d 	 	$..tzz;LMNr`  c                n    | j                   j                  | j                         | j                          y)zDCut the current selection (copy to clipboard and remove from input).N)r   copy_to_clipboardro  r  r;   s    r7   
action_cutzInput.action_cutO  s&    ""4#5#56r9   c                j    | j                   }|r| j                  j                  |       yt               )z,Copy the current selection to the clipboard.N)ro  r   r  r   )r<   ro  s     r7   action_copyzInput.action_copyT  s*    **HH&&}5,r9   c                t    | j                   j                  }| j                  \  }}| j                  |||       y)zPaste from the local clipboard.N)r   	clipboardrj   r<  )r<   r  r1   r2   s       r7   action_pastezInput.action_paste\  s.    HH&&	^^
sYs+r9   )r>   r0   )rm   r0   r>   r   )Nrg   NF)&rh   rp   r   ru   r   zHighlighter | Noner   r@   r   rp   r   	InputTyper   r0   ro   rn   r   z&Validator | Iterable[Validator] | Noner   z"Iterable[InputValidationOn] | Noner   r@   r   r@   r   rp   r   rp   r   rp   r   r@   r   zRenderableType | Noner   r@   r>   r   )rm   r0   r>   r0   r?   )r   ru   r   rp   r>   r@   )rj   r/   r>   r/   )rj   r/   r>   r   )r   r@   r>   r   )r>   r   )rh   ru   r>   r   r   )rh   ru   r>   rv   )r   r0   r>   r   )r>   r   )r  r   r  r   r>   r0   )r  r   r  r   r   r0   r>   r0   )r.  r   r>   r   )r.  r   r>   r   )r.  r   r>   r   )r.  z
events.Keyr>   r   )r.  zevents.Paster>   r   )r   r0   r>   r0   )r.  zevents.MouseDownr>   r   )rW  zevents.MouseReleaser>   r   )rW  zevents.MouseUpr>   r   )r.  zevents.MouseMover>   r   )r.  r$   r>   r   )F)rL  r@   r>   r   )r-   ru   r>   r   )r>   ru   )rs  r@   r>   r   )r-   ru   r1   r0   r2   r0   r>   r   )r-   ru   rG  r0   r>   r   )r1   r0   r2   r0   r>   r   )brA   rB   rC   rD   r   r`   rE   re   DEFAULT_CSSr!   r-  rh   rG   r6   setterr/   r8   rj   r   r   r   r   r"   r   r  r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r  r  r   r  r   r$  r/  r1  r6  r>  rB  rJ  rP  rS  rX  r\  r_  rb  r3  r   r;  rj  rl  ro  rt  rw  rS   r{  r~  r  r  compiler  r  r  r<  rg  r  r  r  r  r  r  r  r  r  r  r  r  __classcell__)r   s   @r7   rI   rI   G   s    	'9F)		
 	/1JQVW$0		
 	C		
 	 *		
 	&		
 	%1		
 	],C%PlGv}5Ae[u=l,?eL[*;%H1IPUV8%8(*Hu	
 	+-EER)+JQV	
 	,.GeT%!45A&"6UC'#BOs:-H) :v8-) <K| Du-L#BU3E=3" " 4 4 &.i.>.>q.A%BI"B/2,KtnOHF2,KE s< &H93y>&!D "\"4(J9e*K.u+=>G3'  , G  * '  0 !*.q/  $ &*=A:>! $")-)q/q/ q/ (	q/
 q/ q/ q/ q/ $q/ ;q/ 8q/ q/ q/ q/  !q/" #q/$ %q/& ''q/( )q/* 
+q/f	F   ) ) 7 7AU
, = =,.&'R  ?2B   ( ("(
M$1("0
&&0 % %
7;&
	%	3 "**\*K.4.0$L)%%$(($$6,$O 
,r9   rI   )C
__future__r   r  dataclassesr   typingr   r   r   r   
rich.cellsr	   r
   rich.consoler   rich.highlighterr   	rich.textr   typing_extensionsr   textualr   textual.actionsr   textual.expand_tabsr   textual.screenr   textual.scroll_viewr   textual.stripr   textual.bindingr   r   textual.css._error_toolsr   textual.eventsr   r   r   textual.geometryr   r   r   r   textual.messager   textual.reactiver    r!   r"   textual.suggesterr#   r$   textual.timerr%   r   r&   r'   InputValidationOnr   r   r  r/   rI   r4   r9   r7   <module>r     s    " 	 ! @ @ 8 ' (  %  & 2 ! *  0 2 - - 8 8 # 4 4 8  ::;  6?  I %Q
 /0	&
 &2Y,J Y,r9   