Format: application/x-python-code
⬇ Download File (5.8 KB)
   1  o
   2  
   3  ��h9�	@sdZddlZddlmZddlmZmZmZddlmZm	Z	ddl
   4  mZddl
   5  mZddl
   6  mZddlmZddlZddlZddlZe�Zd	d
   7  �dedefd
   8  d�Zd	d
   9  �dedededefdd�Zddededefdd�Zdd�ZGdd�de�ZGdd�de�ZdS)zfprompt-toolkit utilities
  10  
  11  Everything in this module is a private API,
  12  not to be used outside IPython.
  13  �N)�wcwidth)�provisionalcompleter�cursor_to_position�_deduplicate_completions)�	Completer�
  14  Completion)�Lexer)�
  15  PygmentsLexer)�patch_stdout���	min_elide�string�returncCs�|�dd�}|�dd�}t|�|kr|S|�d�}|�tj�}|ddkr)|��t|�dkrGd	�|d
  16  |ddd�|d
  17  dd�|d�St|�dkrodtjdtjd�|d
  18  |ddd�|d
  19  dd�|d�S|S)a�
  20      If a string is long enough, and has at least 3 dots,
  21      replace the middle part with ellipses.
  22  
  23      If a string naming a file is long enough, and has at least 3 slashes,
  24      replace the middle part with ellipses.
  25  
  26      If three consecutive dots, or two consecutive dots are encountered these are
  27      replaced by the equivalents HORIZONTAL ELLIPSIS or TWO DOT LEADER unicode
  28      equivalents
  29      z...�…z..u‥�.�������u
  30  {}.{}…{}.{}r�N�����z{}u{}…{})�replace�len�split�os�sep�pop�format)rr
  31  Zobject_partsZ
  32  file_parts�r�Nc:\Users\shubh\Videos\agent\nova\Lib\site-packages\IPython/terminal/ptutils.py�_elide_points(
  33  �(�r �typedr
  34  cCsdt|�|kr|St|�d}|dkr|S|�|�r0t|�t|�kr0|dd��d||d���S|S)zT
  35      Elide the middle of a long string if the beginning has already been typed.
  36      r�Nr)r�
  37  startswith)rr!r
  38  Zcut_how_muchrrr�_elide_typedAsr$cCstt||d�||d�S)Nr)r$r )rr!r
  39  rrr�_elideOs
  40  �r%cCs2|�d�rt|�|kr||dkr|dd�S|S)N�=r)�endswithr)�text�body�offsetrrr�(_adjust_completion_text_based_on_contextVs"r+c@s:eZdZdZddd�Zedd��Zdd�Zed	d
  41  ��Z	dS)�IPythonPTCompleterz8Adaptor to provide IPython completions to prompt_toolkitNcCs(|dur|durtd��||_||_dS)Nz/Please pass shell=an InteractiveShell instance.)�	TypeError�_ipy_completer�shell)�self�
  42  ipy_completerr/rrr�__init___s
  43  zIPythonPTCompleter.__init__cCs|jr|jS|jjS)N)r.r/r)r0rrrr1esz IPythonPTCompleter.ipy_completerc
  44  cs�|j��sdSt��ut��Y|j}|j}|j}|j}t|||�}z|�	||||j
  45  �EdHWn0ty`}z$zt�
  46  �\}	}
  47  }t�|	|
  48  |�Wn
  49  tyUtd�YnwWYd}~nd}~wwWd�n1skwYWd�dSWd�dS1s�wYdS)Nz"Unrecoverable Error in completions)�current_line�stripr
  50  rr(Zcursor_position_rowZcursor_position_col�cursor_positionr�_get_completionsr1�	Exception�sys�exc_info�	traceback�print_exception�AttributeError�print)r0�documentZcomplete_eventr)Z
  51  cursor_rowZ
  52  cursor_colr5r*�e�exc_type�	exc_value�exc_tbrrr�get_completionsls,�
  53  ����P�z"IPythonPTCompleter.get_completionsc	cs0�t|dd�}t||�||��}|D]�}|jsqt�d|j�}t|d�dkrT||jdkrT||jd}t�d||�}	t|dd��dkrTt|	|j|dd�Vq|j}
  54  t	|j||�}|j
  55  dkrt||j|t|
  56  d||j|j��|j
  57  |j
  58  d	�Vqt||j|t|
  59  ||j|j��|j
  60  d	�Vqd
  61  S)zT
  62          Private equivalent of get_completions() use only for unit_testing.
  63          �debugF�NFCrr)�start_position�functionz())rF�displayZdisplay_metaN)�getattrr�completionsr(�unicodedata�	normalizer�startrr+�typer%�end�	signature)r)r*r5ZipycrDrJ�cr(Zchar_beforeZ
  64  fixed_textZdisplay_textZ
  65  adjusted_textrrrr6�s0���
  66  8.�z#IPythonPTCompleter._get_completions)NN)
  67  �__name__�
  68  __module__�__qualname__�__doc__r2�propertyr1rC�staticmethodr6rrrrr,]s
  69  
  70  r,c@s eZdZdZdd�Zdd�ZdS)�IPythonPTLexerz3
  71      Wrapper around PythonLexer and BashLexer.
  72      cCs`t}t|j�|_t|j�|_t|j�t|j�t|j�t|j�t|j�t|j	�t|j
  73  �d�|_dS)N)�HTML�html�
  74  javascript�js�perl�ruby�latex)�pygments_lexersr	�Python3Lexer�python_lexer�	BashLexer�shell_lexer�	HtmlLexer�JavascriptLexer�	PerlLexer�	RubyLexer�TexLexer�magic_lexers)r0�lrrrr2�s�zIPythonPTLexer.__init__cCsj|j��}|j}|�d�s|�d�r|j}n|�d�r0|j��D]\}}|�d|�r/|}nq |�|�S)N�!z%%bashz%%)r(�lstriprbr#rdrj�items�lex_document)r0r>r(�lexer�magicrkrrrro�s
  75  
  76  �
  77  zIPythonPTLexer.lex_documentN)rRrSrTrUr2rorrrrrX�srX)r)rUrKrZIPython.core.completerrrrZprompt_toolkit.completionrrZprompt_toolkit.lexersrr	Zprompt_toolkit.patch_stdoutr
  78  Zpygments.lexers�lexersr`rr8r:�objectZ_completion_sentinel�strr �intr$r%r+r,rXrrrr�<module>s&	 %N