Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit a46e14d

Browse files
committed
Add Ctrl-Z shortcut (suspend) in terminal debugger
Closes gh-10254
1 parent b8cfbfe commit a46e14d

1 file changed

Lines changed: 13 additions & 1 deletion

File tree

IPython/terminal/debugger.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,19 @@
1+
import signal
2+
import sys
3+
14
from IPython.core.debugger import Pdb
25

36
from IPython.core.completer import IPCompleter
47
from .ptutils import IPythonPTCompleter
8+
from .shortcuts import suspend_to_bg
59

10+
from prompt_toolkit.filters import Condition
11+
from prompt_toolkit.keys import Keys
12+
from prompt_toolkit.key_binding.manager import KeyBindingManager
613
from prompt_toolkit.token import Token
714
from prompt_toolkit.shortcuts import create_prompt_application
815
from prompt_toolkit.interface import CommandLineInterface
916
from prompt_toolkit.enums import EditingMode
10-
import sys
1117

1218

1319
class TerminalPdb(Pdb):
@@ -31,8 +37,14 @@ def patch_stdout(**kwargs):
3137
)
3238
self._ptcomp = IPythonPTCompleter(compl, patch_stdout=patch_stdout)
3339

40+
kbmanager = KeyBindingManager.for_prompt()
41+
supports_suspend = Condition(lambda cli: hasattr(signal, 'SIGTSTP'))
42+
kbmanager.registry.add_binding(Keys.ControlZ, filter=supports_suspend
43+
)(suspend_to_bg)
44+
3445
self._pt_app = create_prompt_application(
3546
editing_mode=getattr(EditingMode, self.shell.editing_mode.upper()),
47+
key_bindings_registry=kbmanager.registry,
3648
history=self.shell.debugger_history,
3749
completer= self._ptcomp,
3850
enable_history_search=True,

0 commit comments

Comments
 (0)