diff options
author | Florent Le Coz <louiz@louiz.org> | 2013-06-06 22:58:29 +0200 |
---|---|---|
committer | Florent Le Coz <louiz@louiz.org> | 2013-06-06 22:58:29 +0200 |
commit | 032d2b711bb6a97214403db36ca314154c1bd9c9 (patch) | |
tree | 66f81fac87f69f93d97037c0ecac1c0a20b0bdfc | |
parent | 834546ac7752e3e5c65d31e900489df2c85ce298 (diff) | |
download | poezio-032d2b711bb6a97214403db36ca314154c1bd9c9.tar.gz poezio-032d2b711bb6a97214403db36ca314154c1bd9c9.tar.bz2 poezio-032d2b711bb6a97214403db36ca314154c1bd9c9.tar.xz poezio-032d2b711bb6a97214403db36ca314154c1bd9c9.zip |
Add a M-k keyboard shortcut to escape the next keyboard shortcut
fix #2227
-rw-r--r-- | src/core.py | 8 | ||||
-rw-r--r-- | src/keyboard.py | 18 |
2 files changed, 25 insertions, 1 deletions
diff --git a/src/core.py b/src/core.py index a77868cb..2605aeb6 100644 --- a/src/core.py +++ b/src/core.py @@ -197,6 +197,7 @@ class Core(object): 'M-j': self.go_to_room_number, 'M-D': self.scroll_info_up, 'M-C': self.scroll_info_down, + 'M-k': self.escape_next_key, ######## actions mappings ########## '_bookmark': self.command_bookmark, '_bookmark_local': self.command_bookmark_local, @@ -1326,6 +1327,13 @@ class Core(object): res = keyboard.get_user_input(self.stdscr) return res + def escape_next_key(self): + """ + Tell the Keyboard object that the next key pressed by the user + should be escaped. See Keyboard.get_user_input + """ + keyboard.escape_next_key() + ####################### Commands and completions ############################## def register_command(self, name, func, *, desc='', shortdesc='', completion=None, usage=''): diff --git a/src/keyboard.py b/src/keyboard.py index 240cc2c8..b7480c9c 100644 --- a/src/keyboard.py +++ b/src/keyboard.py @@ -134,6 +134,16 @@ def get_char_list_new(s): class Keyboard(object): def __init__(self): self.get_char_list = get_char_list_new + self.escape = False + + def escape_next_key(self): + """ + The next key pressed by the user should be escaped. e.g. if the user + presses ^N, keyboard.get_user_input() will return ["^", "N"] instead + of ["^N"]. This will display ^N in the input, instead of + interpreting the key binding. + """ + self.escape = True def get_user_input(self, s, timeout=1000): """ @@ -160,7 +170,13 @@ class Keyboard(object): if len(ret_list) != 1: if ret_list[-1] == '^M': ret_list.pop(-1) - return [char if char != '^M' else '^J' for char in ret_list] + ret_list = [char if char != '^M' else '^J' for char in ret_list] + if self.escape: + # Modify the first char of the list into its escaped version (i.e one or more char) + key = ret_list.pop(0) + for char in key[::-1]: + ret_list.insert(0, char) + self.escape = False return ret_list keyboard = Keyboard() |