From 32d8a5281db726abd80df4e87a013eafc985c502 Mon Sep 17 00:00:00 2001 From: Florent Le Coz Date: Tue, 15 Feb 2011 21:03:24 +0100 Subject: [PATCH] Line ^M are now converted to ^J if we are pasting from the clipboard, making it possible to paste huge multi-lines texts in only one message --- src/keyboard.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/keyboard.py b/src/keyboard.py index 188e65eb..ba845b83 100644 --- a/src/keyboard.py +++ b/src/keyboard.py @@ -21,6 +21,10 @@ of the time ONE char, but may be longer if it's a keyboard shortcut, like ^A, M-a or KEY_RESIZE) """ +import time + +last_char_time = None + def get_next_byte(s): """ Read the next byte of the utf-8 char @@ -41,6 +45,10 @@ def read_char(s): Read one utf-8 char see http://en.wikipedia.org/wiki/UTF-8#Description """ + # We use a timer to know if we are pasting from the + # clipboard or not + global last_char_time + last_char_time = time.time() (first, char) = get_next_byte(s) if not isinstance(first, int): # Keyboard special, like KEY_HOME etc return char @@ -48,7 +56,10 @@ def read_char(s): return "KEY_BACKSPACE" if first < 127: # ASCII char on one byte if first <= 26: # transform Ctrl+* keys - return "^"+chr(first + 64) + char = chr(first + 64) + if char == 'M' and time.time() - last_char_time < 0.0001: + char = 'J' + return "^"+char if first == 27: second = read_char(s) res = 'M-%s' % (second,)