Format: application/x-python-code
⬇ Download File (33.0 KB)
   1  o
   2  
   3  ��h��	@sddZddlZddlZddlZddlmZddlmZm	Z	ddl
   4  mZddlm
   5  Z
   6  mZddlmZddlmZmZmZdd	lmZdd
   7  lmZmZmZmZmZmZmZmZm Z m!Z!mZm"Z"m#Z#m$Z$m%Z%ddl&m'Z'ddl(m)Z)dd
   8  l*m+Z+m,Z,ddl-m.Z.m/Z/m0Z0ddl1m2Z2ddl3m4Z4ddl5m6Z6m7Z7ddl8m9Z9ddl:m;Z;ddl<m=Z=m>Z>m?Z?ddl@mAZAmBZBddlCmDZDmEZEddlFmGZHddlImJZJddlKmLZLddlMmNZNddlOmPZPmQZQddlRmSZSddlTmUZUddlVmWZWmXZXmYZYdd lZm[Z[m\Z\dd!l]m^Z^m_Z_m`Z`maZambZbmcZcdd"ldmeZemfZfdd#lgmhZhmiZieH�jd$�ZkGd%d&�d&eL�ZleNjmd'eNjnd(eNjod)eNjpd*iZqeNjmd+eNjnd,eNjod)eNjpd*iZrd-esd.esfd/d0�Ztd1d2�Zud3D]*Zveweev�Zxzex�rfeyexd4��rfex�z��skd5Z{WnW�qPe|�yzd5Z{Ynwd6Z{d7ej}v�p�e{Z~d8d9�Zd:d;�Z�Gd<d=�d=e4�Z�Gd>d?�d?e
   9  �Z�e��e��e�d@k�r�e�������dSdS)Az/IPython terminal interface using prompt_toolkit�N)�warn)�Union�Optional)�get_asyncio_loop)�InteractiveShell�InteractiveShellABC)�input)�toggle_set_term_title�set_term_title�restore_term_title)�
  10  abbrev_cwd)�Bool�Unicode�Dict�Integer�List�observe�Instance�Type�default�Enumr�Any�validate�Float�DottedObjectName)�import_item)�AutoSuggestFromHistory)�DEFAULT_BUFFER�EditingMode)�HasFocus�	Condition�IsDone)�PygmentsTokens)�History)�ConditionalProcessor�!HighlightMatchingBracketProcessor)�
  11  ColorDepth)�patch_stdout)�
  12  PromptSession�
  13  CompleteStyle�print_formatted_text)�DynamicStyle�merge_styles)�style_from_pygments_cls�style_from_pygments_dict)�__version__)�get_style_by_name)�Style)�Token�)�TerminalPdb�Pdb)�TerminalMagics)�get_inputhook_name_and_func)�Prompts�ClassicPrompts�RichPromptDisplayHook)�IPythonPTCompleter�IPythonPTLexer)�KEY_BINDINGS�UNASSIGNED_ALLOWED_COMMANDS�create_ipython_shortcuts�create_identifier�RuntimeBinding�add_binding)�KEYBINDING_FILTERS�filter_from_string)�NavigableAutoSuggestFromHistory�AppendAutoSuggestionInAnyLinez3.c@seZdZdS)�_NoStyleN)�__name__�
  14  __module__�__qualname__�rKrK�Wc:\Users\shubh\Videos\agent\nova\Lib\site-packages\IPython/terminal/interactiveshell.pyrGIsrGz#ansibrightbluez#ansiblue boldz#ansibrightred�
  15  #ansired boldz#ansibrightgreen�#ansigreen bold�width�linenocCsFt�|�}dt�|�jvstdd�|j��D��r|||d�S||�S)z?
  16      Sagemath use custom prompt and we broke them in 8.19.
  17      rPcSsg|]}|j|jk�qSrK)�kind�VAR_KEYWORD)�.0�prKrKrL�
  18  <listcomp>b�z?_backward_compat_continuation_prompt_tokens.<locals>.<listcomp>�rP)�inspect�	signature�
  19  parameters�any�values)�methodrOrP�sigrKrKrL�+_backward_compat_continuation_prompt_tokens\s
  20  �r_cCsJztjdWStyYn
  21  tytd�Ynwtjdkr#dSdS)NZEDITORzN$EDITOR environment variable is not pure ASCII. Using platform default editor.�posix�viZnotepad)�os�environ�KeyError�UnicodeErrorr�namerKrKrKrL�get_default_editoris�
  22  rg)�stdin�stdout�stderr�isattyFTZIPY_TEST_SIMPLE_PROMPTcCs>ddl}|j||��d�}|�d�s|�d�r|dd�}|S)z�
  23      We do not need to protect against error,
  24      this is taken care at a higher level where any reformat error is ignored.
  25      Indeed we may call reformatting on incomplete code.
  26      rN)�mode�
  27  �����)�black�
  28  format_strZFileMode�endswith)�text_before_cursorro�formatted_textrKrKrL�black_reformat_handler�s
  29  rtcCsdddlm}ddlm}|�t���}|j||d�\}}|r0|�d�s.|�d�r.|dd�}|S|S)Nr)�file_resources)�yapf_api)�style_configrmrn)Zyapf.yapflibrurvZGetDefaultStyleForDirrb�getcwdZ
  30  FormatCoderq)rrrurvrwrsZ
  31  was_formattedrKrKrL�yapf_reformat_handler�s
  32  �rycsJeZdZdZ�fdd�Zdd�Zdd�Zdd	�Zd
  33  eddfd
  34  d�Z	�Z
  35  S)�PtkHistoryAdapterzs
  36      Prompt toolkit has it's own way of handling history, Where it assumes it can
  37      Push/pull from history.
  38  
  39      cst���||_|��dS�N)�super�__init__�shell�_refresh)�selfr~��	__class__rKrLr}�s
  40  zPtkHistoryAdapter.__init__cCsd|_|��dS�NF)�_loadedr�r��stringrKrKrL�
  41  append_string�szPtkHistoryAdapter.append_stringcCs|jst|���|_dSdSr{)r��list�load_history_stringsZ_loaded_strings�r�rKrKrLr�s�zPtkHistoryAdapter._refreshccsf�d}g}|jjj|jjdd�D]\}}}|��}|r&||kr&|�|�|}q|ddd�EdHdS)N�T)Zinclude_latestrn)r~�history_managerZget_tailZhistory_load_length�rstrip�append)r��	last_cell�res�__Z___�cellrKrKrLr��s��
  42  �z&PtkHistoryAdapter.load_history_stringsr��returnNcCsdSr{rKr�rKrKrL�store_string��zPtkHistoryAdapter.store_string)rHrIrJ�__doc__r}r�rr��strr��
  43  __classcell__rKrKr�rLrz�s
  44  rzc
  45  seZdZUe�jdd�Zeddd�jdd�ZdZe	e
  46  dfed<dZe	e
  47  edfed<dZed	d
  48  d�jdd�Zeedd�jdd�Zedd
  49  ��Zeddd�jdd�Zeddd�jdd�Zeddd�jdd�Zeddd�jdd�Zeddd�jdd�Zeddd�jdd�Zedddd�jdd�Zeddd�jdd�Zeddd�jdd�Z e!ed�e"e#d�gdd�jdd�Z$e%d�d d!��Z&e'd�d"d#��Z(d$d%�Z)e'd&�d'd(��Z*e'd)�e'd*�d+d,���Z+d-d.�Z,ed/d�jdd�Z-edd0d�jdd�Z.ee/�d1d�jdd�Z0e"e1d2d�jdd�Z2e3e1�Z4e5d3�d4d5��Z6e5d6�d7d8��Z7edd9d�jdd�Z8ed:d;d�jdd�Z9e:d<d=d>d?�jdd�Z;edd@d�jdd�Z<eddAd�jdd�Z=e>ddBd�jdd�Z?eddCd�jdd�Z@edDdEdd�jdd�ZAe>edF<eidGd�jdd�ZBeCdHdId�jdd�ZDe>edJ<e'dK�dLdM��ZEeCdddNdO�jdd�ZFdZGe>edP<e'dQ�dRdS��ZHd�dTdU�ZIe'dV�dWdX��ZJeKee:gdY��e�eKe��e�eKe��e�ed�dY�dZ�d[jLd\�Md]d^�eND��d_�d`�jdd�ZOe'da�dbdc��ZPddde�ZQeddfd�jdd�ZRedgdhd�jdd�ZSe'di�d�djdk��ZTdldm�ZU�fdndo�ZVdpdq�ZWdrds�ZXedtdu��ZYedvdw��ZZdxdy�Z[dzd{�Z\d|d}�Z]d~d�Z^�fd�d��Z_�fd�d��Z`d��fd�d��Zad�d��ZbdZcd�d��Zdd�d��ZedZfd�d��ZgdZheiejed�<d�d�eiejd�dfd�d��ZkeljmZnd�d��ZodZpd�d��Zq�ZrS)��TerminalInteractiveShellT)�config�z�Number of line at the bottom of the screen to reserve for the tab completion menu, search history, ...etc, the height of these menus will at most this value. Increase it is you prefer long and skinny menus, decrease for short and wide.)�helpN�pt_app�auto_suggestz
  50  ~/.pdbhistoryz'File in which to store and read historya�Use `raw_input` for the REPL, without completion and prompt colors.
  51  
  52              Useful when controlling IPython as a subprocess, and piping
  53              STDIN/OUT/ERR. Known usage are: IPython's own testing machinery,
  54              and emacs' inferior-python subprocess (assuming you have set
  55              `python-shell-interpreter` to "ipython") available through the
  56              built-in `M-x run-python` and third party packages such as elpy.
  57  
  58              This mode default to `True` if the `IPY_TEST_SIMPLE_PROMPT`
  59              environment variable is set, or the current terminal is not a tty.
  60              Thus the Default value reported in --help-all, or config will often
  61              be incorrectly reported.
  62              cCs|jrtStSr{)�
  63  simple_promptr5r4r�rKrKrL�debugger_cls�sz%TerminalInteractiveShell.debugger_clsz�
  64          Set to confirm when you try to exit IPython with an EOF (Control-D
  65          in Unix, Control-Z/Enter in Windows). By typing 'exit' or 'quit',
  66          you can force a direct exit without any confirmation.�emacsz5Shortcut style to use at the prompt. 'vi' or 'emacs'.z;Add shortcuts from 'emacs' insert mode to 'vi' insert mode.z�
  67         Cursor shape changes depending on vi mode: beam in vi insert mode,
  68         block in nav mode, underscore in replace mode.g{�G�z�?zJThe time in milliseconds that is waited for a key code
  69         to complete.g�?zUThe time in milliseconds that is waited for a mapped key
  70         sequence to complete.zMAutoformatter to reformat Terminal code. Can be `'black'`, `'yapf'` or `None`)r��
  71  allow_noneFz�
  72          Automatically add/delete closing bracket or quote when opening bracket or quote is entered/deleted.
  73          Brackets: (), [], {}
  74          Quotes: '', ""
  75          zQEnable mouse support in the prompt
  76  (Note: prevents selecting text with the mouse)�legacy)�klassz�The name or class of a Pygments style to use for syntax
  77          highlighting. To see available styles, run `pygmentize -L styles`.�editing_modecCsV|d��dkr
  78  d|d<n|d��dkrd|d<tt|d���r(|d��S|jS)N�value�vimrarr�)�lower�hasattrr�upperr�)r�ZproposalrKrKrL�_validate_editing_mode7s
  79  z/TerminalInteractiveShell._validate_editing_modecCs"|jrtt|j���|j_dSdSr{)r��getattrr�newr�r��r��changerKrKrL�
  80  _editing_modeCs�z&TerminalInteractiveShell._editing_modecCs>|durdd�|_dS|dkrt|_dS|dkrt|_dSt�)NcSs|Sr{rK)�xrKrKrL�<lambda>Jsz9TerminalInteractiveShell._set_formatter.<locals>.<lambda>roZyapf)Zreformat_handlerrtry�
  81  ValueError)r��	formatterrKrKrL�_set_formatterHs
  82  
  83  z'TerminalInteractiveShell._set_formatter�
  84  autoformattercC�|j}|�|�dSr{)r�r�)r�r�r�rKrKrL�_autoformatter_changedR�z/TerminalInteractiveShell._autoformatter_changed�highlighting_style�colorscCs|��dSr{)�
  85  refresh_styler�rKrKrL�_highlighting_style_changedWsz4TerminalInteractiveShell._highlighting_style_changedcCs|�|j�|_dSr{)�_make_style_from_name_or_clsr��_styler�rKrKrLr�\sz&TerminalInteractiveShell.refresh_stylez0Override highlighting format for specific tokensz�Use 24bit colors instead of 256 colors in prompt highlighting.
  86          If your terminal supports true color, the following command should
  87          print ``TRUECOLOR`` in orange::
  88  
  89              printf "\x1b[38;2;255;100;0mTRUECOLOR\x1b[0m\n"
  90          z?Set the editor used by IPython (default to $EDITOR/vi/notepad).z6Class used to generate Prompt token for prompt_toolkit�promptscCs
  91  |�|�Sr{)�
  92  prompts_classr�rKrKrL�_prompts_defaultts
  93  z)TerminalInteractiveShell._prompts_defaultZdisplayhook_classcCstSr{)r:r�rKrKrL�_displayhook_class_default|sz3TerminalInteractiveShell._displayhook_class_defaultz$Automatically set the terminal titlezIPython: {cwd}ziCustomize the terminal title format.  This is a python format string. Available substitutions are: {cwd}.)�column�multicolumn�readlinelikez�Options for displaying tab completions, 'column', 'multicolumn', and 'readlinelike'. These options are for `prompt_toolkit`, see `prompt_toolkit` documentation for more information.r�)r��
  94  default_valuezHighlight matching brackets.z�Enable vi (v) or Emacs (C-X C-E) shortcuts to open an external editor. This is in addition to the F2 binding, which is always enabled.z�Provide an alternative handler to be called when the user presses Return. This is an advanced option intended for debugging, which may be changed or removed in later releases.z:Allows to enable/disable the prompt toolkit history searchrEaSpecifies from which source automatic suggestions are provided. Can be set to ``'NavigableAutoSuggestFromHistory'`` (:kbd:`up` and :kbd:`down` swap suggestions), ``'AutoSuggestFromHistory'``,  or ``None`` to disable automatic suggestions. Default is `'NavigableAutoSuggestFromHistory`'.Z_autosuggestions_provideru�
  95          Extra arguments to pass to `llm_provider_class` constructor.
  96  
  97          This is used to – for example – set the `model_id`�
  98  input_historyaX    Fully Qualifed name of a function that takes an IPython history manager and
  99      return a prefix to pass the llm provider in addition to the current buffer
 100      text.
 101  
 102      You can use:
 103  
 104       - no_prefix
 105       - input_history
 106  
 107      As default value. `input_history` (default),  will use all the input history
 108      of current IPython session
 109  
 110      �_llm_prefix_from_history�llm_prefix_from_historycCs|j}||_|��dSr{)r�r��_set_autosuggestions)r�r�rfrKrKrL� _llm_prefix_from_history_changed�sz9TerminalInteractiveShell._llm_prefix_from_history_changedaw        Provisional:
 111              This is a provisinal API in IPython 8.32, before stabilisation
 112              in 9.0, it may change without warnings.
 113  
 114          class to use for the `NavigableAutoSuggestFromHistory` to request
 115          completions from a LLM, this should inherit from
 116          `jupyter_ai_magics:BaseProvider` and implement
 117          `stream_inline_completions`
 118      )r�r��_llm_provider_class�llm_provider_classcCs(|j}|durtd�||_|��dS)NzvTerminalInteractiveShell.llm_provider_class is a provisional  API as of IPython 8.32, and may change without warnings.)r�rr�r�)r�r�Zprovider_classrKrKrL�_llm_provider_class_changed�s�z4TerminalInteractiveShell._llm_provider_class_changedcCs�|dur|j}|jrt|jt�r|j��|durd|_nN|dkr&t�|_nE|dkrg|jr;t|j�}|d
 119  i|j��}nd}t�|_||j_	|j
 120  }|dkrSdd�}|}n|dkr^dd�}|}nt|�}||j_ntd	��|j
 121  ru|j|j
 122  _dSdS)NrrE�	no_prefixcSsdS)Nr�rK�r�rKrKrLr�r�z@TerminalInteractiveShell._set_autosuggestions.<locals>.no_prefixr�cSsd�dd�|��D��dS)NrmcSsg|]}|d�qS)�rK)rS�srKrKrLrU
 123  szXTerminalInteractiveShell._set_autosuggestions.<locals>.input_history.<locals>.<listcomp>)�joinZ	get_ranger�rKrKrLr�szDTerminalInteractiveShell._set_autosuggestions.<locals>.input_historyzNo valid provider.rK)�autosuggestions_providerr��
 124  isinstancerEZ
 125  disconnectrr�r�llm_constructor_kwargsZ
 126  _llm_providerr�Z
 127  _llm_prefixerr�r�)r��providerZllm_provider_constructorZllm_providerrfr�Zfunr�rKrKrLr��s<�
 128  
 129  
 130  
 131  �z-TerminalInteractiveShell._set_autosuggestionsr�cCr�r{)r�r�)r�r�r�rKrKrL�!_autosuggestions_provider_changedr�z:TerminalInteractiveShell._autosuggestions_provider_changed)�command�
 132  match_keys�match_filter�new_keys�
 133  new_filter�create)Z	key_traitZper_key_traitsa�
 134          Add, disable or modifying shortcuts.
 135  
 136          Each entry on the list should be a dictionary with ``command`` key
 137          identifying the target function executed by the shortcut and at least
 138          one of the following:
 139  
 140            - ``match_keys``: list of keys used to match an existing shortcut,
 141            - ``match_filter``: shortcut filter used to match an existing shortcut,
 142            - ``new_keys``: list of keys to set,
 143            - ``new_filter``: a new shortcut filter to set
 144  
 145          The filters have to be composed of pre-defined verbs and joined by one
 146          of the following conjunctions: ``&`` (and), ``|`` (or), ``~`` (not).
 147          The pre-defined verbs are:
 148  
 149          {filters}
 150  
 151          To disable a shortcut set ``new_keys`` to an empty list.
 152          To add a shortcut add key ``create`` with value ``True``.
 153  
 154          When modifying/disabling shortcuts, ``match_keys``/``match_filter`` can
 155          be omitted if the provided specification uniquely identifies a shortcut
 156          to be modified/disabled. When modifying a shortcut ``new_filter`` or
 157          ``new_keys`` can be omitted which will result in reuse of the existing
 158          filter/keys.
 159  
 160          Only shortcuts defined in IPython (and not default prompt-toolkit
 161          shortcuts) can be modified or disabled. The full list of shortcuts,
 162          command identifiers and filters is available under
 163          :ref:`terminal-shortcuts-list`.
 164  
 165          Here is an example:
 166  
 167          .. code::
 168  
 169              c.TerminalInteractiveShell.shortcuts = [
 170                 {{
 171                     "new_keys": ["c-q"],
 172                     "command": "prompt_toolkit:named_commands.capitalize_word",
 173                     "create": True,
 174                 }},
 175                 {{
 176                     "new_keys": ["c-j"],
 177                     "command": "prompt_toolkit:named_commands.beginning_of_line",
 178                     "create": True,
 179                 }},
 180              ]
 181  
 182  
 183          z	
 184          cCsg|]}d|�d��qS)z  - ``z``rK�rS�krKrKrLrUfrVz#TerminalInteractiveShell.<listcomp>)�filters)Ztraitr��	shortcutscCs |jr|j|jd�|j_dSdS)N��user_shortcuts)r��_merge_shortcutsr��key_bindingsr�rKrKrL�_shortcuts_changedjs�z+TerminalInteractiveShell._shortcuts_changedcs�t|�}dd�tD�}|�dd�tD��g}g}|D]���d��|vr3d�|�}t��d|������dd��d�vrCt�d�nd����fd	d
 185  �tD�}��dd�}��dd�}|�}	��d
 186  d�}
 187  |
 188  on|dupn|}|
 189  ry|gkrytd��|r��fdd�dD�}t|�dkr�td|�dt����t|�dkr�td|�d|����|d}
 190  |
 191  j	�t
 192  |
 193  j��|�t
 194  |	��d��|gkr�|�t
 195  |	|pň|dur�t|�n	�durӈntd�d��qt||d�}|D]}t||�q�|S)NcSsi|]	}t|j�|j�qSrK)r@r��rS�bindingrKrKrL�
 196  <dictcomp>us��z=TerminalInteractiveShell._merge_shortcuts.<locals>.<dictcomp>cSsi|]}t|�|�qSrK)r@)rSr�rKrKrLr�zs��r�z
 197   - z< is not a known shortcut command. Allowed commands are: 
 198   - r�r�csLg|]"}�dus
 199  |j�kr$�dusdd�|jD��kr$t|j��kr|�qS)NcSsg|]}|�qSrKrKr�rKrKrLrU�szHTerminalInteractiveShell._merge_shortcuts.<locals>.<listcomp>.<listcomp>)�filter�keysr@r�r�)�
 200  command_id�
 201  old_filter�old_keysrKrLrU�s�z=TerminalInteractiveShell._merge_shortcuts.<locals>.<listcomp>r�r�r�Fz"Cannot add a shortcut without keyscsi|]}|�vr|�|�qSrKrK)rS�key)�shortcutrKrLr��s
 202  �)r�r�rzNo shortcuts matching z
 203   found in r3zMultiple shortcuts matching z1 found, please add keys/filter to select one of: )r�r��always)�skip)r?r=�updater>r�r��getrD�lenr�r�r�r�rArB)r�r�r�Zallowed_commandsZshortcuts_to_skipZshortcuts_to_addZmatchingr�r�r�Zcreating_newZmodifying_existing�
 204  specificationZmatchedr�rK)r�r�r�r�rLr�os����
 205  �����
 206  
 207  �
 208  ����
 209  �������z)TerminalInteractiveShell._merge_shortcutsz9Display the current vi mode (when using vi editing mode).r�aThe format for line numbering, will be passed `line` (int, 1 based) the current line number and `rel_line` the relative line number. for example to display both you can use the following template string : c.TerminalInteractiveShell.prompt_line_number_format='{line: 4d}/{rel_line:+03d} | ' This will display the current line number, with leading space and a width of at least 4 character, as well as the relative line number 0 padded and always with a + or - sign. Note that when using Emacs mode the prompt of the first line may not update.�
 210  term_titlecCs6|jrtrtd�t|jjt�d��dStd�dS)NT)�cwdF)r��_is_ttyr	r
 211  �term_title_format�formatrr�rKrKrL�init_term_title�s
 212  z(TerminalInteractiveShell.init_term_titlecCs|jr
 213  trt�dSdSdSr{)r�r�rr�rKrKrLr�s
 214  
 215  �z+TerminalInteractiveShell.restore_term_titlecstt|���dg|j_dS)Nz
 216  text/plain)r|r��init_display_formatter�display_formatterZactive_typesr�r�rKrLr��sz/TerminalInteractiveShell.init_display_formattercs��jr�fdd�}|�_dS�j�jd�}t��}���j��_t�fdd���_	t
 217  t�j�
 218  ��}d�_td
 219  �j|||t�d��j�j	d�j�j�jdd	�������_t�jt�rc�j��j�dSdS)Ncs�d�dd��j��D��}t|�g}d�dd��j��D��}��d�|��ddkr>|�t|����d�|��ddks+d�|�S)Nr�cs��|]}|dVqdS�r3NrK�rSr�rKrKrL�	<genexpr>��zSTerminalInteractiveShell.init_prompt_toolkit_cli.<locals>.prompt.<locals>.<genexpr>csrrrKrrKrKrLrrrmr�
 220  incomplete)r�r��in_prompt_tokensr�continuation_prompt_tokensZcheck_completer�)Zprompt_text�lines�prompt_continuationr�rKrL�prompt�s
 221  �
 222  z@TerminalInteractiveShell.init_prompt_toolkit_cli.<locals>.promptr�c��jSr{)r�rKr�rKrLr��zBTerminalInteractiveShell.init_prompt_toolkit_cli.<locals>.<lambda>F)r~z.py)r�r�r��historyZ	completer�enable_history_search�styleZinclude_default_pygments_style�
 223  mouse_supportZenable_open_in_editor�color_depthZtempfile_suffixrK)r��prompt_for_coder�r�rzr�r�r�r+rr�rr�r��_use_asyncio_inputhookr(r�r;rr�extra_open_editor_shortcutsr�_extra_prompt_optionsr�r�rE�connect)r�rr�rr�rKr�rL�init_prompt_toolkit_cli�s:�
 224  ��z0TerminalInteractiveShell.init_prompt_toolkit_clicCsJi}|dkry|j��}|dkrtd�}t}n}|dkr!t}td�}nr|dkrktd�}|�tjdtjd	tj	d
 225  tj
 226  jdtj
 227  jdtj
 228  j
 229  dtj
 230  jjdtjdtjd
 231  tjdtjdi�tjdkrj|�tjdtjdtjdtjdi�n(|dkrtt}i}ntd|��t|t�r�t|�}n|}tjdtjd
 232  tjdtjdi}|�|j�tt|�t|�g�}|S)z�
 233          Small wrapper that make an IPython compatible style from a style name
 234  
 235          We need that to add style for prompt ... etc.
 236          r��linux�monokaiZlightbg�pastieZneutralrz
 237  #ansigreen�	noinheritz#ansiyellowz	#ansibluezbold #ansibluez#ansibrightgreen boldz#ansiredz#ansibrightred bold�ntz#ansidarkgreenrNz#ansidarkredrMZnocolorzGot unknown colors: )r�r�r0�_style_overrides_linux�_style_overrides_light_bgr�r2�Number�Operator�String�Name�Function�Class�	Namespace�Variable�Magic�Prompt�	PromptNum�	OutPrompt�OutPromptNumrbrfrGr�r�r��highlighting_style_overridesr,r-r.)r�Zname_or_clsZstyle_overridesr�Z	style_clsrrKrKrLr�'sd
 238  
 239  
 240  �
 241  ��
 242  
 243  
 244  ��z5TerminalInteractiveShell._make_style_from_name_or_clscCstjtjtjd�|jS)N)r�r�r�)r)ZMULTI_COLUMNZCOLUMNZ
 245  READLINE_LIKE�display_completionsr�rKrKrL�pt_complete_stylejs��z*TerminalInteractiveShell.pt_complete_stylecCs|jrtjSdSr{)�
 246  true_colorr&Z
 247  TRUE_COLORr�rKrKrLrrsz$TerminalInteractiveShell.color_depthcs��fdd�}�jdkr�jdkr|�}dt��j|�fdd�d�jttd	d
 248  �tt�t	�@t
 249  �fdd��@d�tt�tt�t	�@t
 250  �fd
 251  d��@d�gd�}tsV�j
 252  |d<|S)z\
 253          Return the current layout option for the current Terminal InteractiveShell
 254          cst�j���Sr{)r"r�rrKr�rKrL�get_messagezszCTerminalInteractiveShell._extra_prompt_options.<locals>.get_messager�r�Fcstt�jj||d��S)NrW)r"r_r�r)rOrPZis_soft_wrapr�rKrLr��s
 255  
 256  ��z@TerminalInteractiveShell._extra_prompt_options.<locals>.<lambda>Tz[](){})�charscrr{)�highlight_matching_bracketsrKr�rKrLr��r
 257  )�	processorr�cst�jt�Sr{)r�r�rErKr�rKrLr��s�)Zcomplete_in_thread�lexerZreserve_space_for_menu�messager
 258  �	multiline�complete_styleZinput_processors�	inputhook)r��prompt_line_number_formatr<�space_for_menur/r$r%rrr!r rF�PTK3r9)r�r1�optionsrKr�rLrvsB
 259  ����
 260  �����%
 261  z.TerminalInteractiveShell._extra_prompt_optionscCs�|jr
 262  |j}d|_nd}tdd��7|jr)t�}|�|jjdd|i|�����}n|jjd||j	d�|����}Wd�|SWd�|S1sKwY|S)Nr�T)�rawr)rr9rK)
 263  �
 264  rl_next_inputr'rr�run_until_completer�Zprompt_asyncrr�
 265  _inputhook)r�rZasyncio_loop�textrKrKrLr�s6
 266  �����
 267  ��
 268  ��z(TerminalInteractiveShell.prompt_for_codecCstdtdd�dS)Nzu`enable_win_unicode_console` is deprecated since IPython 7.10, does not do anything and will be removed in the futurer�)�
 269  stacklevel)r�DeprecationWarningr�rKrKrL�enable_win_unicode_console�s
 270  �z3TerminalInteractiveShell.enable_win_unicode_consolecCs"tjdvrdSddl}|��dS)N>�win32�clir)�sys�platform�colorama�init)r�rJrKrKrL�init_io�s
 271  z TerminalInteractiveShell.init_iocstt|���|�t�dSr{)r|r��init_magicsZregister_magicsr6r�r�rKrLrM�sz$TerminalInteractiveShell.init_magicscs8tt|���tjdkrdD]}|j�||�qdSdS)Nr`)�clear�more�less�man)r|r��
 272  init_aliasrbrfZ
 273  alias_managerZsoft_define_alias)r��cmdr�rKrLrR�s
 274  �z#TerminalInteractiveShell.init_aliasr�csHtt|�j|i|��|�|j�|��|��d|_|�|j	�dS)NT)
 275  r|r�r}r�r�rr��keep_runningr�r�)r��args�kwargsr�rKrLr}�sz!TerminalInteractiveShell.__init__cCs
 276  d|_dSr�)rTr�rKrKrL�ask_exit�s
 277  z!TerminalInteractiveShell.ask_exitcCsvd|_|jr9t|jdd�z|��}Wnty*|jr$|�ddd�r(|��Yn
 278  w|r4|j|dd�|jsdSdS)NTr�)�endz#Do you really want to exit ([y]/n)?�y�n)Z
 279  store_history)	rT�printZseparate_inr�EOFError�confirm_exitZ
 280  ask_yes_norWZrun_cell)r��coderKrKrL�interact�s����z!TerminalInteractiveShell.interactc
 281  Cs�	zAz|��WWt|d�r|j��|��n;ty2}ztdt|�j�WYd}~nd}~wwWt|d�r>|j��|��nt|d�rM|j��|��wq|�	�dS)NT�
 282  _eventloopz
 283  %s escaped interact()
 284  )
 285  r_r�r`�stopr�KeyboardInterruptr[�typerHZ_atexit_once)r��erKrKrL�mainloop
 286  s(
 287  
 288  
 289  ���
 290  
 291  
 292  
 293  �
 294  
 295  �z!TerminalInteractiveShell.mainloopcCs|jdur|�|�dSdSr{)rA)r��contextrKrKrLr9(s
 296  �z"TerminalInteractiveShell.inputhook�active_eventloop�guicCs|rddlm}||�}|jdur#|dur#td|�d��td�dS|jdur2|dur2td�dS|jdur`|dur`t|�\}}|j|krS|j�d|j�d	��dS|j�	d
 297  |j�d��dS|jduro|durod|_|_|r~|dvr~t|�\|_|_nd|_|_|d
 298  k|_
 299  dS)Nr�)�_convert_gui_from_matplotlibTz$Cannot install event loop hook for "z&" when running with `--simple-prompt`.zSNOTE: Tk is supported natively; use Tk apps and Tk backends with `--simple-prompt`.zNo event loop hook running.zShell is already running the z eventloop. Doing nothingz8Shell is already running a different gui event loop for z5. Call with no arguments to disable the current loop.>ZwebaggN�asyncio)Zcore.pylabtoolsrir�r[rAr7�log�inforg�warningr)r�rhriZnewevZ	newinhookrKrKrL�
 300  enable_gui.s>
 301  ��
 302  ��z#TerminalInteractiveShell.enable_guicCsd|jsdS|j��}|jrtt|�d|jjjd�t|�dSd�	dd�|D��}t||dd�dS)z>Overridden from the parent class to use fancy rewriting promptNr�)rXrcss�|]\}}|VqdSr{rK)rS�tr�rKrKrLrhrz>TerminalInteractiveShell.auto_rewrite_input.<locals>.<genexpr>)�sep)
 303  Zshow_rewritten_inputr�Zrewrite_prompt_tokensr�r*r"Zapprr[r�)r�rS�tokensrrKrKrL�auto_rewrite_input]s
 304  
 305  �z+TerminalInteractiveShell.auto_rewrite_inputcCs6|r
 306  |j|_t|�|_dS|jr|j|_d|_dSdS)z+Switch prompts to classic for %doctest_modeN)r��_prompts_beforer9)r�rlrKrKrL�switch_doctest_models
 307  �z,TerminalInteractiveShell.switch_doctest_moder{)r�N)srHrIrJr�tagZmime_renderersrr;r��	UnionTyper(�__annotations__r�rrEZdebugger_historyrZdebugger_history_filer
 308  �_use_simple_promptr��propertyr�r]r�Z emacs_bindings_in_vi_insert_modeZmodal_cursorrZttimeoutlenZ
 309  timeoutlenr�Z
 310  auto_matchrrrr1r�rr�rr�r�r�r�r�r-r0rgZeditorr8r�rr�rr�r�r�r�rr.r3rrZ
 311  handle_returnrr�r�rr�r�r�r�r�r�r�rr�r�rCr�r�r�Zprompt_includes_vi_moder:r�rr�rr�r/rrrrErLrMrRr}rWr?r_rerAr9rgrr�rnrZ
 312  system_raw�systemrrrsrtr�rKrKr�rLr��s�
 313  
 314  ��������
 315  ����������������	����
 316  
 317  
 318  
 319  ����	��
 320  
 321  ����������������	����
 322  �
 323  �
 324  
 325  
 326  /
 327  ���2��J�L
 328  k���	�,C
 329  
 330  ;!-r��__main__)�r�rbrHrX�warningsr�typingrrvrZIPython.core.async_helpersrZIPython.core.interactiveshellrrZIPython.utils.py3compatrZIPython.utils.terminalr	r
 331  rZIPython.utils.processrZ	traitletsr
 332  rrrrrrrrrrrrrZtraitlets.utils.importstringrZprompt_toolkit.auto_suggestrZprompt_toolkit.enumsrrZprompt_toolkit.filtersrr r!Zprompt_toolkit.formatted_textr"Zprompt_toolkit.historyr#Z prompt_toolkit.layout.processorsr$r%Zprompt_toolkit.outputr&Zprompt_toolkit.patch_stdoutr'Zprompt_toolkit.shortcutsr(r)r*Zprompt_toolkit.stylesr+r,Zprompt_toolkit.styles.pygmentsr-r.Zprompt_toolkitr/Zptk_versionZpygments.stylesr0Zpygments.styler1Zpygments.tokenr2Zdebuggerr4r5Zmagicsr6Z
 333  pt_inputhooksr7r�r8r9r:Zptutilsr;r<r�r=r>r?r@rArBZshortcuts.filtersrCrDZshortcuts.auto_suggestrErF�
 334  startswithr<rGr)r*r+r,rr�intr_rg�_namer��_streamr�rkr�r�rcrxrtryrzr��registerrH�instancer_rKrKrKrL�<module>s�D 
 335  ��
 336  
 337  ��%
 338  /
 339  �