From 17ca4d105f95e412ee94d60bc12b90065cb78c29 Mon Sep 17 00:00:00 2001 From: Yohann D'ANELLO Date: Mon, 21 Dec 2020 16:04:15 +0100 Subject: [PATCH] Use screen.get_wch() rather than screen.getkey() to have better support of UTF-8 Signed-off-by: Yohann D'ANELLO --- squinnondation/hazel.py | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/squinnondation/hazel.py b/squinnondation/hazel.py index 2c830cf..f72f31a 100644 --- a/squinnondation/hazel.py +++ b/squinnondation/hazel.py @@ -110,12 +110,12 @@ class Squirrel(Hazelnut): if not self.squinnondation.no_emoji: self.refresh_emoji_pad() try: - key = self.squinnondation.screen.getkey(curses.LINES - 1, - min(3 + len(self.nickname) + self.input_index, curses.COLS - 4)) + key = self.squinnondation.screen.get_wch( + curses.LINES - 1, min(3 + len(self.nickname) + self.input_index, curses.COLS - 4)) except curses.error: continue - if key == "KEY_MOUSE": + if key == curses.KEY_MOUSE: try: _, x, y, _, attr = curses.getmouse() self.handle_mouse_click(y, x, attr) @@ -136,39 +136,39 @@ class Squirrel(Hazelnut): self.input_index -= 1 self.input_buffer = self.input_buffer[:self.input_index] + self.input_buffer[self.input_index + 1:] return - elif key == "KEY_LEFT": + elif key == curses.KEY_LEFT: # Navigate in the message to the left self.input_index = max(0, self.input_index - 1) return - elif key == "KEY_RIGHT": + elif key == curses.KEY_RIGHT: # Navigate in the message to the right self.input_index = min(len(self.input_buffer), self.input_index + 1) return - elif key == "KEY_UP": + elif key == curses.KEY_UP: # Scroll up in the history self.last_line = min(max(curses.LINES - 3, self.last_line - 1), len(self.history) - 1) return - elif key == "KEY_DOWN": + elif key == curses.KEY_DOWN: # Scroll down in the history self.last_line = min(len(self.history) - 1, self.last_line + 1) return - elif key == "KEY_PPAGE": + elif key == curses.KEY_PPAGE: # Page up in the history self.last_line = min(max(curses.LINES - 3, self.last_line - (curses.LINES - 3)), len(self.history) - 1) return - elif key == "KEY_NPAGE": + elif key == curses.KEY_NPAGE: # Page down in the history self.last_line = min(len(self.history) - 1, self.last_line + (curses.LINES - 3)) return - elif key == "KEY_HOME": + elif key == curses.KEY_HOME: # Place the cursor at the beginning of the typing word self.input_index = 0 return - elif key == "KEY_END": + elif key == curses.KEY_END: # Place the cursor at the end of the typing word self.input_index = len(self.input_buffer) return - elif len(key) > 1: + elif isinstance(key, int): # Unmanaged complex key return elif key != "\n":