From ea4ef6e3d983cb20ae758ea17f5fd37dcc37ed61 Mon Sep 17 00:00:00 2001 From: jstenar <> Date: Tue, 17 Apr 2007 19:43:55 +0000 Subject: [PATCH] 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. --- doc/ChangeLog | 5 +++++ pyreadline/configuration/pyreadlineconfig.ini | 1 + pyreadline/console/console.py | 3 ++- pyreadline/modes/basemode.py | 1 + pyreadline/modes/emacs.py | 8 +++++++- pyreadline/rlmain.py | 13 +++++++++++++ 6 files changed, 29 insertions(+), 2 deletions(-) diff --git a/doc/ChangeLog b/doc/ChangeLog index 0903418..3c1d075 100644 --- a/doc/ChangeLog +++ b/doc/ChangeLog @@ -1,3 +1,8 @@ +2007-04-17 Jörgen Stenarson + * 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 * doctest imports pdb which imports readline, this means readline can be imported when a dummy object has replaced stdout. The dummy diff --git a/pyreadline/configuration/pyreadlineconfig.ini b/pyreadline/configuration/pyreadlineconfig.ini index ea56735..9e833d7 100644 --- a/pyreadline/configuration/pyreadlineconfig.ini +++ b/pyreadline/configuration/pyreadlineconfig.ini @@ -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) \ No newline at end of file diff --git a/pyreadline/console/console.py b/pyreadline/console/console.py index 9e88c36..bb6513c 100644 --- a/pyreadline/console/console.py +++ b/pyreadline/console/console.py @@ -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) diff --git a/pyreadline/modes/basemode.py b/pyreadline/modes/basemode.py index aaa7642..2ec43bf 100644 --- a/pyreadline/modes/basemode.py +++ b/pyreadline/modes/basemode.py @@ -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")) diff --git a/pyreadline/modes/emacs.py b/pyreadline/modes/emacs.py index 6736bc7..492cb04 100644 --- a/pyreadline/modes/emacs.py +++ b/pyreadline/modes/emacs.py @@ -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)