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:
jstenar
2007-04-17 19:43:55 +00:00
parent d4f2cbeab8
commit ea4ef6e3d9
6 changed files with 29 additions and 2 deletions
+5
View File
@@ -1,3 +1,8 @@
2007-04-17 Jörgen Stenarson <jorgen.stenarson -at- bostream.nu>
* 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.
2007-04-16 Jörgen Stenarson <jorgen.stenarson -at- bostream.nu>
* doctest imports pdb which imports readline, this means readline
can be imported when a dummy object has replaced stdout. The dummy
@@ -82,3 +82,4 @@ history_filename("~/.pythonhistory")
history_length(200) #value of -1 means no limit
#set_mode("vi") #will cause following bind_keys to bind to vi mode as well as activate vi mode
#ctrl_c_tap_time_interval(0.3)
+2 -1
View File
@@ -535,7 +535,8 @@ class Console(object):
'''Check event queue.'''
Cevent = INPUT_RECORD()
count = c_int(0)
status = PeekConsoleInput(self.hin, byref(Cevent), 1, byref(count))
status = self.PeekConsoleInputA(self.hin, byref(Cevent), 1, byref(count))
log_sock("%s %s %s"%(status,count,Cevent))
if status and count == 1:
return event(self, Cevent)
+1
View File
@@ -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"))
+7 -1
View File
@@ -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
+13
View File
@@ -55,6 +55,7 @@ class Readline(object):
self.next_meta = False # True to force meta on next character
self.tabstop = 4
self.allow_ctrl_c=False
self.ctrl_c_tap_time_interval=0.3
self.begidx = 0
self.endidx = 0
@@ -327,6 +328,15 @@ class Readline(object):
def readline(self, prompt=''):
return self.mode.readline(prompt)
def event_available(self):
return self.mode.readline_event_available()
def setup(self,prompt=""):
return self.mode.readline_setup(prompt)
def keyboard_poll(self):
return self.mode._readline_from_keyboard_poll()
def read_inputrc(self,inputrcpath=os.path.expanduser("~/pyreadlineconfig.ini")):
modes=dict([(x.mode,x) for x in self.editingmodes])
@@ -364,6 +374,8 @@ class Readline(object):
self.bell_style=mode
def show_all_if_ambiguous(mode):
self.show_all_if_ambiguous=mode
def ctrl_c_tap_time_interval(mode):
self.ctrl_c_tap_time_interval=mode
def mark_directories(mode):
self.mark_directories=mode
def completer_delims(mode):
@@ -400,6 +412,7 @@ class Readline(object):
"set_prompt_color":set_prompt_color,
"set_input_color":set_input_color,
"allow_ctrl_c":allow_ctrl_c,
"ctrl_c_tap_time_interval":ctrl_c_tap_time_interval,
}
if os.path.isfile(inputrcpath):
try: