
    ^h4                        S SK r S SKrS SKJr  S SKJrJrJrJrJ	r	J
r
  S SKrS SKJr  S SKJr  S SKJr  S SKJrJr  S SKJr  S S	KJr  S S
KJr  S SKJrJrJr  S SK J!r!  S SK"J#r#  SSK$J%r%  S\4S jr& " S S\5      r' " S S\5      r(S\4S jr)S\4S jr*S\4S jr+S\4S jr,S\4S jr-S\4S jr.S\4S jr/S\4S jr0S\4S  jr1S\4S! jr2S\4S" jr3S\4S# jr4S\4S$ jr5S\4S% jr6\\\(S4   r7S\S&\(S'\4S( jr8S\4S) jr9S\4S* jr:S+ r;g),    N)StringIO)CallableListOptionalUnion	GeneratorTuple)Buffer)KeyPressEvent)named_commands)AutoSuggestFromHistory
Suggestion)Document)History)PromptSession)	ProcessorTransformationTransformationInput)get_ipython)generate_tokens   )pass_throughdocumentc                 4    U R                   U R                     $ N)linescursor_position_row)r   s    a/home/james-whalen/.local/lib/python3.13/site-packages/IPython/terminal/shortcuts/auto_suggest.py
_get_queryr      s    >>(6677    c                   @    \ rS rSrSrS
S\SS4S jjrS\S\4S jr	S	r
g)AppendAutoSuggestionInAnyLine   z
Append the auto suggestion to lines other than the last (appending to the
last line is natively supported by the prompt toolkit).
stylereturnNc                     Xl         g r   r$   )selfr$   s     r   __init__&AppendAutoSuggestionInAnyLine.__init__$   s    
r    tic                    UR                   UR                  R                  S-
  :H  nUR                   UR                  R                  :H  nU(       d  U(       a~  UR                  R
                  nUR                  (       a2  UR                  R                  (       a  UR                  R                  nOSn[        UR                  U R                  U4/-   S9$ [        UR                  S9$ )Nr    )	fragments)linenor   
line_countr   buffer_controlbuffer
suggestionis_cursor_at_the_end_of_linetextr   r.   r$   )r(   r+   is_last_lineis_active_liner2   r3   s         r   apply_transformation2AppendAutoSuggestionInAnyLine.apply_transformation'   s    yyBKK$:$:Q$>>bkk&E&EE&&--F  R[[%M%M#..33

!BLLTZZ<T;U,UVV!BLL99r    r'   )zclass:auto-suggestion)__name__
__module____qualname____firstlineno____doc__strr)   r   r   r8   __static_attributes__ r    r   r"   r"      s.    
c  :': :~ :r    r"   c                      \ rS rSrSrS rS\4S jrS rS\	4S jr
S	\S
\S\\   4S jrS rS\S\S\S\S\\\\4   SS4   4
S jrS\S\S\S\\\\4   SS4   4S jrS\S\S\4S jrS\S\S\SS4S jrS\S\S\SS4S jrSrg)NavigableAutoSuggestFromHistory8   z
A subclass of AutoSuggestFromHistory that allow navigation to next/previous
suggestion from history. To do so it remembers the current position, but it
state need to carefully be cleared on the right events.
c                      SU l         / U l        g Nr   )
skip_lines_connected_apps)r(   s    r   r)   (NavigableAutoSuggestFromHistory.__init__?   s     !r    _c                     SU l         g rF   )rG   )r(   rJ   s     r   reset_history_position6NavigableAutoSuggestFromHistory.reset_history_positionE   s	    r    c                     U R                    H4  nUR                  R                  nUR                  U R                  5        M6     g r   )rH   default_bufferon_text_insertremove_handlerrL   )r(   pt_apptext_insert_events      r   
disconnect*NavigableAutoSuggestFromHistory.disconnectH   s8    **F & 5 5 D D,,T-H-HI +r    rR   c                     U R                   R                  U5        UR                  R                  R	                  U R
                  5        UR                  R                  R	                  U R                  5        g r   )rH   appendrO   rP   add_handlerrL   on_cursor_position_changed_dismiss)r(   rR   s     r   connect'NavigableAutoSuggestFromHistory.connectM   sV    ##F+ 	,,889T9TU88DDT]]Sr    r2   r   r%   c                     [        U5      nUR                  5       (       a:  U R                  X0R                  UR                  5       H  u  pE[        U5      s  $    g r   )r   strip_find_next_matchrG   historyr   )r(   r2   r   r5   r3   rJ   s         r   get_suggestion.NavigableAutoSuggestFromHistory.get_suggestionT   sO     (#::<<!%!6!6oov~~"
 "*--"
 r    c                     S Ul         g r   )r3   )r(   r2   argskwargss       r   rZ   (NavigableAutoSuggestFromHistory._dismissa   s
     r    r5   rG   r`   previousNc              #   j  #    Sn[        [        UR                  5       5      5       H  n[        UR                  5       5       Hg  nUS-  nU(       d  XR:  a  M  UR	                  U5      (       a*  [        U5      [        U5      :  a  U[        U5      S U4v   U(       d  M_  XR:  d  Mf      g   M     g7f)a  
text : str
    Text content to find a match for, the user cursor is most of the
    time at the end of this text.
skip_lines : float
    number of items to skip in the search, this is used to indicate how
    far in the list the user has navigated by pressing up or down.
    The float type is used as the base value is +inf
history : History
    prompt_toolkit History instance to fetch previous entries from.
previous : bool
    Direction of the search, whether we are looking previous match
    (True), or next match (False).

Yields
------
Tuple with:
str:
    current suggestion.
float:
    will actually yield only ints, which is passed back via skip_lines,
    which may be a +inf (float)


r   N)reversedlistget_strings
splitlines
startswithlen)r(   r5   rG   r`   rg   line_numberstringlines           r   _find_match+NavigableAutoSuggestFromHistory._find_matchd   s     8 tG$7$7$9:;F !2!2!45q K$< ??4((SYT-Bs4y{+[888 9 6 <s   BB3"B3)
B3c                 $    U R                  XUSS9$ )NFrg   )rs   r(   r5   rG   r`   s       r   r_   0NavigableAutoSuggestFromHistory._find_next_match   s     'EJJr    c                 H    [        [        U R                  XUSS95      5      $ )NTrv   )rj   rk   rs   rw   s       r   _find_previous_match4NavigableAutoSuggestFromHistory._find_previous_match   s)    !!$Gd!KL
 	
r    query
other_thanc                 |    U R                  XR                  U5       H  u  pEX-   U:w  d  M  XPl          g    SU l        g rF   )r_   rG   r(   r|   r}   r`   r3   rp   s         r   up"NavigableAutoSuggestFromHistory.up   sA    '+'<'<??G(
#J !Z/"-(
  DOr    c                     U R                  XR                  U5       H  u  pEX-   U:w  d  M  XPl          g    U R                  U[        S5      U5       H  u  pEX-   U:w  d  M  XPl          g    g )NInf)rz   rG   floatr   s         r   down$NavigableAutoSuggestFromHistory.down   sr    '+'@'@??G(
#J !Z/"-(
 ,0+D+DuU|W,'
 %3&1O,r    )rH   rG   )r:   r;   r<   r=   r>   r)   r
   rL   rT   r   r[   r   r   r   ra   rZ   r?   r   r   boolr   r	   rs   r_   rz   r   r   r@   rA   r    r   rC   rC   8   s1   " J
Tm T(0	*	!''%*'5<'HL'	5e$dD0	1'RKK%*K5<K	5e$dD0	1K

 
% 
' 

     w  4   # 3  T r    rC   eventc                 ^   U R                   nUR                  nUR                  UR                  S nUR	                  S5      nUS   R                  5       nUR                  nUb3  UR                  (       a"  US:X  a  UR                  UR                  5        g[        R                  " U 5        g)z,Apply autosuggestion or jump to end of line.N
r   r-   )
current_bufferr   r5   cursor_positionsplitr^   r3   insert_textncend_of_line)r   r2   dafter_cursorr   end_of_current_liner3   s          r   accept_or_jump_to_endr      s    !!FA66!++-.Lt$E(..*""JZ__;NRT;T:??+
ur    c                     [        U 5      $ )zmAccept autosuggestion or jump to end of line.

.. deprecated:: 8.12
    Use `accept_or_jump_to_end` instead.
)r   r   s    r   #_deprected_accept_in_vi_insert_moder      s     !''r    c                     U R                   nUR                  nU(       a  UR                  UR                  5        g[        R
                  " U 5        g)zAccept autosuggestionN)r   r3   r   r5   r   forward_char)r   r2   r3   s      r   acceptr      s9    !!F""J:??+
r    c                 *    U R                   nSUl        g)zDiscard autosuggestionN)r   r3   )r   r2   s     r   discardr      s    !!FFr    c                     U R                   nUR                  nU(       aD  [        R                  " SUR                  5      nUR                  [        S U 5       S5      5        g[        R                  " U 5        g)z#Fill partial autosuggestion by wordz(\S+\s+)c              3   6   #    U  H  o(       d  M  Uv   M     g 7fr   rA   ).0xs     r   	<genexpr>accept_word.<locals>.<genexpr>   s      3AqAs   
	r-   N)	r   r3   rer   r5   r   nextr   forward_word)r   r2   r3   ts       r   accept_wordr      sV    !!F""JHH[*//24 3A 3R89
r    c                     U R                   nUR                  nU(       a1  UR                  (       a  UR                  UR                  S   5        ggg)z(Fill partial autosuggestion by characterr   N)r   r3   r5   r   )r   br3   s      r   accept_characterr      s;    AJjoo	jooa() &zr    c                     U R                   nUR                  nUR                  nU(       a"  UR                  UR                  5        X!l        gg)z.Accept autosuggestion and keep cursor in placeN)r   r   r3   r   r5   )r   r2   old_positionr3   s       r   accept_and_keep_cursorr      sC    !!F))L""J:??+!- r    c                 F    [        U 5        [        R                  " U 5        g)z3Accept autosuggestion and move cursor left in placeN)r   r   backward_charr   s    r   accept_and_move_cursor_leftr      s    5!Ur    r2   c                 ~    U R                   (       a,  U R                   R                  X R                  5      nXl        g g r   )auto_suggestra   r   r3   )r2   r3   s     r   _update_hintr     s0    ((77P
& r    c                 Z    [         R                  " U 5        [        U R                  5        g)z4Resume autosuggestions after deleting last characterN)r   backward_delete_charr   r   r   s    r   backspace_and_resume_hintr     s    E"%%&r    c                 Z    [         R                  " U 5        [        U R                  5        g)zResume autosuggestionsN)r   replyr   r   r   s    r   resume_hintingr     s     u %%&r    c                 d    U R                   nUR                  U R                  S9  [        U5        g)zGo up and update hintcountN)r   auto_upargr   r   r   s     r   up_and_update_hintr     s*    ))N+ r    c                 d    U R                   nUR                  U R                  S9  [        U5        g)zGo down and update hintr   N)r   	auto_downr   r   r   s     r   down_and_update_hintr     s*    ))N599- r    c                 \   U R                   nUR                  nU(       Gav  [        UR                  5      nX2R                  -   n/ SQnS/nSn[        [        U5      R                  5       H  nUR                  [        R                  :X  a  [        U5      n	O!UR                  US   [        US   5      5      n	UR                  USU	 5        US   n
U
R                  U5      (       d  M  US:X  a?  [        U
5      [        U5      :  a'  U
[        U5      S US'   UR                  U
5        US-  nUS   XW'   US:X  a    O	US-  nM     US   (       aF  US   nUS   (       a  [        US   5      S:X  a  US   nU[        U5      S nUR                  U5        g[         R"                  " U 5        g)	z$Fill partial autosuggestion by token)NNNr-   r   r   ri   N   )r   r3   r   r   r5   r   r   readlinetypetokenizeNEWLINEro   indexrW   rn   r   r   r   )r   r   r3   prefixr5   tokens
substringsitokenr   tokenized_so_farr   	to_inserts                r   accept_tokenr   &  s   AJAJJ''&8T
$Xd^%<%<=EzzX---D	

58SB-@Ad6El+)"~**6226c"23c&kA 0V ?F1I%%&67FA!!H	6Q >" !9$R.KayS^q0(n#CKM2IMM)$OOEr    providerdirection_methodc                     U R                   nU(       d  g[        U R                  5      nXCR                  -   nU" XEU R                  S9  UR                  X R                  5      nX`l         g)a  
We skip most recent history entry (in either direction) if it equals the
current autosuggestion because if user cycles when auto-suggestion is shown
they most likely want something else than what was suggested (otherwise
they would have accepted the suggestion).
N)r|   r}   r`   )r3   r   r   r5   r`   ra   )r2   r   r   r3   r|   currentnew_suggestions          r   _swap_autosuggestionr   S  sW     ""Jv'Eoo%G5fnnM,,V__EN&r    c                     [        5       nUR                  n[        U[        5      (       d  g[	        U R
                  X"R                  S9$ )z%Get next autosuggestion from history.Nr2   r   r   )r   r   
isinstancerC   r   r   r   r   shellr   s      r   swap_autosuggestion_upr   k  sA    ME!!Hh ?@@##h r    c                     [        5       nUR                  n[        U[        5      (       d  g[	        U R
                  UUR                  S9$ )z)Get previous autosuggestion from history.Nr   )r   r   r   rC   r   r   r   r   s      r   swap_autosuggestion_downr   x  sE    ME!!Hh ?@@##! r    c                 Z    U S:X  a   [         R                  " S[        SS9  [        $ [        e)Naccept_in_vi_insert_modez`accept_in_vi_insert_mode` is deprecated since IPython 8.12 and renamed to `accept_or_jump_to_end`. Please update your configuration accordinglyr   )
stacklevel)warningswarnDeprecationWarningr   AttributeError)keys    r   __getattr__r     s2    
(( 	
 32
r    )<r   r   ior   typingr   r   r   r   r   r	   r   prompt_toolkit.bufferr
   prompt_toolkit.key_bindingr   #prompt_toolkit.key_binding.bindingsr   r   prompt_toolkit.auto_suggestr   r   prompt_toolkit.documentr   prompt_toolkit.historyr   prompt_toolkit.shortcutsr    prompt_toolkit.layout.processorsr   r   r   IPython.core.getipythonr   IPython.utils.tokenutilr   filtersr   r   r"   rC   r   r   r   r   r   r   r   r   r   r   r   r   r   r   Providerr   r   r   r   rA   r    r   <module>r      sc   	   D D  ( 4 D J , * 2  0 3 !8 8:I :4}&< }@ (} (- = } *M *.- .} ' ''] ''- '!m !! !' 'T ')H$NO''-' '0
- 
M 
r    