We can navigate in order to edit our message

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

View File

@ -74,19 +74,37 @@ class Squinnondation:
while True:
squirrel.refresh_history()
squirrel.refresh_input()
key = screen.getkey(curses.LINES - 1, 3 + len(squirrel.nickname) + len(squirrel.input_buffer))
key = screen.getkey(curses.LINES - 1, 3 + len(squirrel.nickname) + squirrel.input_index)
if key == "\x7f": # backspace
squirrel.input_buffer = squirrel.input_buffer[:-1]
if squirrel.input_index:
squirrel.input_index -= 1
squirrel.input_buffer = squirrel.input_buffer[:squirrel.input_index] \
+ squirrel.input_buffer[squirrel.input_index + 1:]
continue
elif key == "KEY_LEFT":
squirrel.input_index = max(0, squirrel.input_index - 1)
continue
elif key == "KEY_RIGHT":
squirrel.input_index = min(len(squirrel.input_buffer), squirrel.input_index + 1)
continue
elif key == "KEY_HOME":
squirrel.input_index = 0
continue
elif key == "KEY_END":
squirrel.input_index = len(squirrel.input_buffer)
continue
elif len(key) > 1:
squirrel.history.append(f"<system> *unmanaged key press: {key}*")
continue
elif key != "\n":
squirrel.input_buffer += key
squirrel.input_buffer = squirrel.input_buffer[:squirrel.input_index] + key \
+ squirrel.input_buffer[squirrel.input_index:]
squirrel.input_index += 1
continue
msg = squirrel.input_buffer
squirrel.input_buffer = ""
squirrel.input_index = 0
if not msg:
continue
@ -408,6 +426,7 @@ class Squirrel(Hazelnut):
self.squinnondation = instance
self.input_buffer = ""
self.input_index = 0
self.history = []
self.history_pad = curses.newpad(curses.LINES - 2, curses.COLS)