Manage suppr key, fix backspace

This commit is contained in:
Yohann D'ANELLO 2021-01-06 15:45:52 +01:00
parent 89bb6ddc3a
commit bd024c3d31
Signed by: ynerant
GPG Key ID: 3A75C55819C8CF85
1 changed files with 6 additions and 1 deletions

View File

@ -270,12 +270,16 @@ class Squirrel(Hazelnut):
"""
Process the key press from the user.
"""
if key == "\x7f": # backspace
if key == "\x7f" or key == curses.KEY_BACKSPACE: # backspace
# delete character at the good position
if self.input_index:
self.input_index -= 1
self.input_buffer = self.input_buffer[:self.input_index] + self.input_buffer[self.input_index + 1:]
return
elif key == curses.KEY_DC: # key
if self.input_index < len(self.input_buffer):
self.input_buffer = self.input_buffer[:self.input_index] + self.input_buffer[self.input_index + 1:]
return
elif key == curses.KEY_LEFT:
# Navigate in the message to the left
self.input_index = max(0, self.input_index - 1)
@ -310,6 +314,7 @@ class Squirrel(Hazelnut):
return
elif isinstance(key, int):
# Unmanaged complex key
self.add_system_message(str(key))
return
elif key != "\n":
# Insert the pressed key in the current message