mirror of
https://github.com/wassname/pyreadline.git
synced 2026-08-18 12:20:32 +08:00
pyreadline: When allowing to bind ctrl-c we now issue a KeyBoardInterrupt if
control-c is pressed twice within ctrl_c_tap_time_interval which is defaulted to 0.3 s and can be set from the configfile.
This commit is contained in:
@@ -48,6 +48,7 @@ class BaseMode(object):
|
||||
return val
|
||||
argument_reset=property(_argreset)
|
||||
|
||||
ctrl_c_tap_time_interval=property(*_gs("ctrl_c_tap_time_interval"))
|
||||
allow_ctrl_c=property(*_gs("allow_ctrl_c"))
|
||||
l_buffer=property(*_gs("l_buffer"))
|
||||
next_meta=property(*_gs("next_meta"))
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
# Distributed under the terms of the BSD License. The full license is in
|
||||
# the file COPYING, distributed as part of this software.
|
||||
#*****************************************************************************
|
||||
import os,sys
|
||||
import os,sys,time
|
||||
import pyreadline.logger as logger
|
||||
from pyreadline.logger import log,log_sock
|
||||
from pyreadline.lineeditor.lineobj import Point
|
||||
@@ -54,6 +54,11 @@ class EmacsMode(basemode.BaseMode):
|
||||
event.keyinfo=KeyPress("c",shift=False,control=True,meta=False,keyname=None)
|
||||
log_sock("KBDIRQ")
|
||||
if self.allow_ctrl_c:
|
||||
now=time.time()
|
||||
if (now-self.ctrl_c_timeout)<self.ctrl_c_tap_time_interval:
|
||||
raise
|
||||
else:
|
||||
self.ctrl_c_timeout=now
|
||||
pass
|
||||
else:
|
||||
raise
|
||||
@@ -89,6 +94,7 @@ class EmacsMode(basemode.BaseMode):
|
||||
def readline(self, prompt=''):
|
||||
'''Try to act like GNU readline.'''
|
||||
# handle startup_hook
|
||||
self.ctrl_c_timeout=time.time()
|
||||
self.l_buffer.selection_mark=-1
|
||||
if self.first_prompt:
|
||||
self.first_prompt = False
|
||||
|
||||
Reference in New Issue
Block a user