Use screen.get_wch() rather than screen.getkey() to have better support of UTF-8

Signed-off-by: Yohann D'ANELLO <ynerant@crans.org>
This commit is contained in:
Yohann D'ANELLO 2020-12-21 16:04:15 +01:00
parent e44998028d
commit 17ca4d105f
Signed by: ynerant
GPG Key ID: 3A75C55819C8CF85
1 changed files with 12 additions and 12 deletions

View File

@ -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":