
    ^h9              	          S r SSKrSSKJr  SSKJrJr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  SSKrSSKrSSKr\" 5       rS	S
.S\S\4S jjrS	S
.S\S\S\S\4S jjrSS\S\S\4S jjrS r " S S\5      r " S S\5      rg)zfprompt-toolkit utilities

Everything in this module is a private API,
not to be used outside IPython.
    N)wcwidth)provisionalcompletercursor_to_position_deduplicate_completions)	Completer
Completion)Lexer)PygmentsLexer)patch_stdout   	min_elidestringreturnc                &   U R                  SS5      n U R                  SS5      n [        U 5      U:  a  U $ U R                  S5      nU R                  [        R                  5      nUS   S:X  a  UR                  5         [        U5      S:  a&  S	R                  US
   US   SS US   SS US   5      $ [        U5      S:  aN  S[        R                  -   S-   [        R                  -   S-   R                  US
   US   SS US   SS US   5      $ U $ )ao  
If a string is long enough, and has at least 3 dots,
replace the middle part with ellipses.

If a string naming a file is long enough, and has at least 3 slashes,
replace the middle part with ellipses.

If three consecutive dots, or two consecutive dots are encountered these are
replaced by the equivalents HORIZONTAL ELLIPSIS or TWO DOT LEADER unicode
equivalents
z...   …z..u   ‥.    u   {}.{}…{}.{}r      Nz{}u   {}…{})replacelensplitosseppopformat)r   r   object_parts
file_partss       R/home/james-whalen/.local/lib/python3.13/site-packages/IPython/terminal/ptutils.py_elide_pointr#      s$    ^^E";<F^^D!56F
6{Y<<$Lbff%J"~
<1299OOBQRS!	
 	
 
Z1	rvv ==FMUUqM:a=!,jnRS.A:b>
 	
 M    typedr   c                    [        U 5      U:  a  U $ [        U5      S-
  nUS:  a  U $ U R                  U5      (       a$  [        U 5      [        U5      :  a  U SS  SXS  3$ U $ )zL
Elide the middle of a long string if the beginning has already been typed.
r      Nr   )r   
startswith)r   r%   r   cut_how_muchs       r"   _elide_typedr*   A   sr    
 6{Yu:a<LaCKU$;!*4VM5J4KLLMr$   c                 $    [        [        XS9XS9$ )Nr   )r*   r#   )r   r%   r   s      r"   _elider,   O   s    V1$ $r$   c                 j    U R                  S5      (       a  [        U5      U:  a  X   S:X  a  U S S $ U $ )N=r   )endswithr   )textbodyoffsets      r"   (_adjust_completion_text_based_on_contextr3   V   s6    }}Sc$i&0T\S5HCRyr$   c                   H    \ rS rSrSrS	S jr\S 5       rS r\	S 5       r
Srg)
IPythonPTCompleter]   z8Adaptor to provide IPython completions to prompt_toolkitNc                 >    Uc  Uc  [        S5      eXl        X l        g )Nz/Please pass shell=an InteractiveShell instance.)	TypeError_ipy_completershell)selfipy_completerr:   s      r"   __init__IPythonPTCompleter.__init___   s#    =]2MNN+
r$   c                 h    U R                   (       a  U R                   $ U R                  R                  $ )N)r9   r:   r   )r;   s    r"   r<    IPythonPTCompleter.ipy_completere   s'    &&&::'''r$   c              #   n  #    UR                   R                  5       (       d  g [        5          [        5          UR                  nUR
                  nUR                  nUR                  n[        X4U5      n U R                  X7X`R                  5       S h  vN   S S S 5        S S S 5        g  N! [         aY  n [        R                  " 5       u  pn[        R                  " XU5         S nANR! [          a    [#        S5          S nANmf = fS nAff = f! , (       d  f       N= f! , (       d  f       g = f7f)Nz"Unrecoverable Error in completions)current_linestripr   r   r0   cursor_position_rowcursor_position_colcursor_positionr   _get_completionsr<   	Exceptionsysexc_info	tracebackprint_exceptionAttributeErrorprint)r;   documentcomplete_eventr1   
cursor_row
cursor_colrF   r2   eexc_type	exc_valueexc_tbs               r"   get_completions"IPythonPTCompleter.get_completionsl   s     $$**,,
 ^13==D!55J!55J&66O'*EF@00PbPbccc 4^^ d @@25,,./H--h6JJ% @>??@	@ 43^^s   +D5D$=D6B-B+B-D$"	D5+B--
D8/C,'D,D	DDD	DDD
D!	D$$
D2.D5c              #   l  #    [        USS5      n[        XR                  X5      5      nU GH  nUR                  (       d  M  [        R
                  " SUR                  5      n[        US   5      S:X  ak  X&R                  -   S:  aY  XR                  S-
     n[        R
                  " SX-   5      n	[        USS 5      S:X  a  [        XR                  U-
  S-
  S9v   M  UR                  n
[        UR                  X5      nUR                  S:X  aW  [        XR                  U-
  [        U
S-   XR                  UR                   5      UR                  UR                  -   S	9v   GM>  [        XR                  U-
  [        XUR                  UR                   5      UR                  S	9v   GM     g
7f)zD
Private equivalent of get_completions() use only for unit_testing.
debugFNFCr   r   )start_positionfunctionz())r\   displaydisplay_metaN)getattrr   completionsr0   unicodedata	normalizer   startr   r3   typer,   end	signature)r1   r2   rF   ipycrZ   ra   cr0   char_before
fixed_textdisplay_textadjusted_texts               r"   rG   #IPythonPTCompleter._get_completions   s    
 gu-.""402A66((7D
 tAw1$"WW,q0"&ww{"3K!,!6!6{1"3J tAay)Q.(GGfDTWXDXYY  66LDQVVTZMvv# ww?OY_`lmq`qswxx  AB  AF  AF  tG  ZH  WX  W]  W]  ^_  ^i  ^i  Wi  j  j ww?OY_`ltut{t{|}  }B  }B  pC  ZD  ST  SY  SY  Z  Z? s   F2F4)r9   r:   )NN)__name__
__module____qualname____firstlineno____doc__r=   propertyr<   rW   staticmethodrG   __static_attributes__ r$   r"   r5   r5   ]   s:    B ( (@, &Z &Zr$   r5   c                   $    \ rS rSrSrS rS rSrg)IPythonPTLexer   z+
Wrapper around PythonLexer and BashLexer.
c           	         [         n[        UR                  5      U l        [        UR                  5      U l        [        UR                  5      [        UR                  5      [        UR                  5      [        UR                  5      [        UR                  5      [        UR                  5      [        UR                  5      S.U l        g )N)HTMLhtml
javascriptjsperlrubylatex)pygments_lexersr
   Python3Lexerpython_lexer	BashLexershell_lexer	HtmlLexerJavascriptLexer	PerlLexer	RubyLexerTexLexermagic_lexers)r;   ls     r"   r=   IPythonPTLexer.__init__   s    )!..9(5 "!++.!!++.'(9(9: 1 12!!++.!!++."1::.
r$   c                    UR                   R                  5       nU R                  nUR                  S5      (       d  UR                  S5      (       a  U R                  nOVUR                  S5      (       a@  U R
                  R                  5        H"  u  pEUR                  SU-   5      (       d  M   Un  O   UR                  U5      $ )N!z%%bashz%%)r0   lstripr   r(   r   r   itemslex_document)r;   rO   r0   lexermagicr   s         r"   r   IPythonPTLexer.lex_document   s    }}##%!!??34??8#<#<$$E__T"" --335??4%<00E 6
 !!(++r$   )r   r   r   N)ro   rp   rq   rr   rs   r=   r   rv   rw   r$   r"   ry   ry      s    
,r$   ry   )r   )rs   rb   r   IPython.core.completerr   r   r   prompt_toolkit.completionr   r   prompt_toolkit.lexersr	   r
   prompt_toolkit.patch_stdoutr   pygments.lexerslexersr   r   rI   rK   object_completion_sentinelstrr#   intr*   r,   r3   r5   ry   rw   r$   r"   <module>r      s       < ' / 4 ) 	 
 x *, # #s #J :<  3 S c $# $S $ $LZ LZ\!,U !,r$   