44import os
55import sys
66import signal
7- import unicodedata
87from warnings import warn
9- from wcwidth import wcwidth
108
119from IPython .core .error import TryNext
1210from IPython .core .interactiveshell import InteractiveShell
13- from IPython .utils .py3compat import PY3 , cast_unicode_py2 , input
11+ from IPython .utils .py3compat import cast_unicode_py2 , input
1412from IPython .utils .terminal import toggle_set_term_title , set_term_title
1513from IPython .utils .process import abbrev_cwd
1614from traitlets import Bool , Unicode , Dict , Integer , observe
1715
18- from prompt_toolkit .completion import Completer , Completion
1916from prompt_toolkit .enums import DEFAULT_BUFFER , SEARCH_BUFFER , EditingMode
2017from prompt_toolkit .filters import HasFocus , HasSelection , Condition , ViInsertMode , EmacsInsertMode , IsDone
2118from prompt_toolkit .history import InMemoryHistory
2219from prompt_toolkit .shortcuts import create_prompt_application , create_eventloop , create_prompt_layout
2320from prompt_toolkit .interface import CommandLineInterface
2421from prompt_toolkit .key_binding .manager import KeyBindingManager
2522from prompt_toolkit .keys import Keys
26- from prompt_toolkit .layout .lexers import Lexer
27- from prompt_toolkit .layout .lexers import PygmentsLexer
2823from prompt_toolkit .layout .processors import ConditionalProcessor , HighlightMatchingBracketProcessor
2924from prompt_toolkit .styles import PygmentsStyle , DynamicStyle
3025
3126from pygments .styles import get_style_by_name , get_all_styles
32- from pygments .lexers import Python3Lexer , BashLexer , PythonLexer
3327from pygments .token import Token
3428
29+ from .debugger import TerminalPdb
3530from .pt_inputhooks import get_inputhook_func
3631from .interactiveshell import get_default_editor , TerminalMagics
37-
38-
39- class IPythonPTCompleter (Completer ):
40- """Adaptor to provide IPython completions to prompt_toolkit"""
41- def __init__ (self , ipy_completer ):
42- self .ipy_completer = ipy_completer
43-
44- def get_completions (self , document , complete_event ):
45- if not document .current_line .strip ():
46- return
47-
48- used , matches = self .ipy_completer .complete (
49- line_buffer = document .current_line ,
50- cursor_pos = document .cursor_position_col
51- )
52- start_pos = - len (used )
53- for m in matches :
54- m = unicodedata .normalize ('NFC' , m )
55-
56- # When the first character of the completion has a zero length,
57- # then it's probably a decomposed unicode character. E.g. caused by
58- # the "\dot" completion. Try to compose again with the previous
59- # character.
60- if wcwidth (m [0 ]) == 0 :
61- if document .cursor_position + start_pos > 0 :
62- char_before = document .text [document .cursor_position + start_pos - 1 ]
63- m = unicodedata .normalize ('NFC' , char_before + m )
64-
65- # Yield the modified completion instead, if this worked.
66- if wcwidth (m [0 :1 ]) == 1 :
67- yield Completion (m , start_position = start_pos - 1 )
68- continue
69-
70- # TODO: Use Jedi to determine meta_text
71- # (Jedi currently has a bug that results in incorrect information.)
72- # meta_text = ''
73- # yield Completion(m, start_position=start_pos,
74- # display_meta=meta_text)
75- yield Completion (m , start_position = start_pos )
76-
77- class IPythonPTLexer (Lexer ):
78- """
79- Wrapper around PythonLexer and BashLexer.
80- """
81- def __init__ (self ):
82- self .python_lexer = PygmentsLexer (Python3Lexer if PY3 else PythonLexer )
83- self .shell_lexer = PygmentsLexer (BashLexer )
84-
85- def lex_document (self , cli , document ):
86- if document .text .startswith ('!' ):
87- return self .shell_lexer .lex_document (cli , document )
88- else :
89- return self .python_lexer .lex_document (cli , document )
32+ from .ptutils import IPythonPTCompleter , IPythonPTLexer
9033
9134
9235class TerminalInteractiveShell (InteractiveShell ):
@@ -100,6 +43,8 @@ def _space_for_menu_changed(self, old, new):
10043 self ._update_layout ()
10144
10245 pt_cli = None
46+ debugger_history = None
47+ debugger_cls = TerminalPdb
10348
10449 autoedit_syntax = Bool (False ,
10550 help = "auto editing of files with syntax errors." ,
@@ -362,6 +307,8 @@ def __init__(self, *args, **kwargs):
362307 self .init_term_title ()
363308 self .keep_running = True
364309
310+ self .debugger_history = InMemoryHistory ()
311+
365312 def ask_exit (self ):
366313 self .keep_running = False
367314
0 commit comments