X Tutup
Skip to content

Commit 996cf4a

Browse files
committed
Make suspend work with bpython.cli.
Based on a patch by Till Maas. This closes issue #106.
1 parent 27f0f84 commit 996cf4a

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

bpython/cli.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -834,6 +834,10 @@ def p_key(self, key):
834834
elif key == 'KEY_BTAB':
835835
return self.tab(back=True)
836836

837+
elif key in key_dispatch[config.suspend_key]:
838+
self.suspend()
839+
return ''
840+
837841
elif len(key) == 1 and not unicodedata.category(key) == 'Cc':
838842
self.addstr(key)
839843
self.print_line(self.s)
@@ -1142,6 +1146,11 @@ def size(self):
11421146
self.h = h - 1
11431147
self.x = 0
11441148

1149+
def suspend(self):
1150+
"""Suspend the current process for shell job control."""
1151+
curses.endwin()
1152+
os.kill(os.getpid(), signal.SIGSTOP)
1153+
11451154
def tab(self, back=False):
11461155
"""Process the tab key being hit. If there's only whitespace
11471156
in the line or the line is blank then process a normal tab,
@@ -1403,6 +1412,10 @@ def sigwinch(unused_scr):
14031412
global DO_RESIZE
14041413
DO_RESIZE = True
14051414

1415+
def sigcont(unused_scr):
1416+
sigwinch(unused_scr)
1417+
# Forces the redraw
1418+
curses.ungetch('')
14061419

14071420
def gethw():
14081421
"""I found this code on a usenet post, and snipped out the bit I needed,
@@ -1524,6 +1537,8 @@ def main_curses(scr, args, config, interactive=True, locals_=None,
15241537

15251538
old_sigwinch_handler = signal.signal(signal.SIGWINCH,
15261539
lambda *_: sigwinch(scr))
1540+
# redraw window after being suspended
1541+
old_sigcont_handler = signal.signal(signal.SIGCONT, lambda *_: sigcont(scr))
15271542

15281543
stdscr = scr
15291544
try:
@@ -1576,8 +1591,9 @@ def main_curses(scr, args, config, interactive=True, locals_=None,
15761591
statusbar.win.refresh()
15771592
curses.raw(False)
15781593

1579-
# Restore SIGWINCH handler
1594+
# Restore signal handlers
15801595
signal.signal(signal.SIGWINCH, old_sigwinch_handler)
1596+
signal.signal(signal.SIGCONT, old_sigcont_handler)
15811597

15821598
return repl.getstdout()
15831599

bpython/config.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ def loadini(struct, configfile):
6262
'pastebin': 'F8',
6363
'save': 'C-s',
6464
'show_source': 'F2',
65+
'suspend': 'C-z',
6566
'undo': 'C-r',
6667
'up_one_line': 'C-p',
6768
'yank_from_buffer': 'C-y'},
@@ -84,6 +85,7 @@ def loadini(struct, configfile):
8485
struct.pastebin_key = config.get('keyboard', 'pastebin')
8586
struct.save_key = config.get('keyboard', 'save')
8687
struct.show_source_key = config.get('keyboard', 'show_source')
88+
struct.suspend_key = config.get('keyboard', 'suspend')
8789
struct.undo_key = config.get('keyboard', 'undo')
8890
struct.up_one_line_key = config.get('keyboard', 'up_one_line')
8991
struct.down_one_line_key = config.get('keyboard', 'down_one_line')

0 commit comments

Comments
 (0)
X Tutup