In no-emoji mode, don't display the emoji menu

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

View File

@ -65,7 +65,8 @@ class Squinnondation:
squirrel = Squirrel(instance, nickname) squirrel = Squirrel(instance, nickname)
squirrel.refresh_history() squirrel.refresh_history()
squirrel.refresh_input() squirrel.refresh_input()
squirrel.refresh_emoji_pad() if not instance.no_emoji:
squirrel.refresh_emoji_pad()
if instance.args.client_address and instance.args.client_port: if instance.args.client_address and instance.args.client_port:
hazelnut = Hazelnut(address=instance.args.client_address, port=instance.args.client_port) hazelnut = Hazelnut(address=instance.args.client_address, port=instance.args.client_port)
@ -76,7 +77,8 @@ class Squinnondation:
while True: while True:
squirrel.refresh_history() squirrel.refresh_history()
squirrel.refresh_input() squirrel.refresh_input()
squirrel.refresh_emoji_pad() if not instance.no_emoji:
squirrel.refresh_emoji_pad()
key = screen.getkey(curses.LINES - 1, 3 + len(squirrel.nickname) + squirrel.input_index) key = screen.getkey(curses.LINES - 1, 3 + len(squirrel.nickname) + squirrel.input_index)
if key == "\x7f": # backspace if key == "\x7f": # backspace
if squirrel.input_index: if squirrel.input_index:
@ -115,39 +117,40 @@ class Squinnondation:
except curses.error: except curses.error:
# This is not a valid click # This is not a valid click
continue continue
if y == curses.LINES - 1 and x >= curses.COLS - 3: if not instance.no_emoji:
# Click on the emoji if y == curses.LINES - 1 and x >= curses.COLS - 3:
squirrel.emoji_panel_page *= -1 # Click on the emoji
elif squirrel.emoji_panel_page > 0 and y == curses.LINES - 4 and x >= curses.COLS - 5: squirrel.emoji_panel_page *= -1
squirrel.emoji_panel_page += 1 elif squirrel.emoji_panel_page > 0 and y == curses.LINES - 4 and x >= curses.COLS - 5:
elif squirrel.emoji_panel_page > 1 and y == curses.LINES - curses.LINES // 2 - 1 \ squirrel.emoji_panel_page += 1
and x >= curses.COLS - 5: elif squirrel.emoji_panel_page > 1 and y == curses.LINES - curses.LINES // 2 - 1 \
squirrel.emoji_panel_page -= 1 and x >= curses.COLS - 5:
elif squirrel.emoji_panel_page > 0 and y >= curses.LINES // 2 - 1 and x >= curses.COLS // 2 - 1: squirrel.emoji_panel_page -= 1
pad_y, pad_x = y - (curses.LINES - curses.LINES // 2) + 1,\ elif squirrel.emoji_panel_page > 0 and y >= curses.LINES // 2 - 1 and x >= curses.COLS // 2 - 1:
(x - (curses.COLS - curses.COLS // 3)) // 2 pad_y, pad_x = y - (curses.LINES - curses.LINES // 2) + 1,\
height, width = squirrel.emoji_pad.getmaxyx() (x - (curses.COLS - curses.COLS // 3)) // 2
height -= 1 height, width = squirrel.emoji_pad.getmaxyx()
width -= 1 height -= 1
width -= 1
emojis = list(unicode_codes.UNICODE_EMOJI) emojis = list(unicode_codes.UNICODE_EMOJI)
emojis = [c for c in emojis if len(c) == 1] emojis = [c for c in emojis if len(c) == 1]
size = (height - 2) * (width - 4) // 2 size = (height - 2) * (width - 4) // 2
page = emojis[(squirrel.emoji_panel_page - 1) * size:squirrel.emoji_panel_page * size] page = emojis[(squirrel.emoji_panel_page - 1) * size:squirrel.emoji_panel_page * size]
index = pad_y * (width - 4) // 2 + pad_x index = pad_y * (width - 4) // 2 + pad_x
char = page[index] char = page[index]
if char: if char:
demojized = emoji.demojize(char) demojized = emoji.demojize(char)
if char != demojized: if char != demojized:
for c in reversed(demojized): for c in reversed(demojized):
curses.ungetch(c) curses.ungetch(c)
continue continue
elif len(key) > 1: elif len(key) > 1:
squirrel.add_message(f"<system> *unmanaged key press: {key}*") squirrel.add_message(f"<system> *unmanaged key press: {key}*")
continue continue
elif key != "\n": elif key != "\n":
squirrel.input_buffer = squirrel.input_buffer[:squirrel.input_index] + key \ squirrel.input_buffer = squirrel.input_buffer[:squirrel.input_index] + key \
+ squirrel.input_buffer[squirrel.input_index:] + squirrel.input_buffer[squirrel.input_index:]
squirrel.input_index += 1 squirrel.input_index += 1
continue continue
@ -648,7 +651,8 @@ class Squirrel(Hazelnut):
self.input_pad.addstr(0, 1, self.nickname, curses.A_BOLD | curses.color_pair(color_id + 1)) self.input_pad.addstr(0, 1, self.nickname, curses.A_BOLD | curses.color_pair(color_id + 1))
self.input_pad.addstr(0, 1 + len(self.nickname), "> ") self.input_pad.addstr(0, 1 + len(self.nickname), "> ")
self.input_pad.addstr(0, 3 + len(self.nickname), self.input_buffer) self.input_pad.addstr(0, 3 + len(self.nickname), self.input_buffer)
self.input_pad.addstr(0, self.input_pad.getmaxyx()[1] - 3, "😀") if not self.squinnondation.no_emoji:
self.input_pad.addstr(0, self.input_pad.getmaxyx()[1] - 3, "😀")
self.input_pad.refresh(0, 0, curses.LINES - 1, 0, curses.LINES - 1, curses.COLS - 1) self.input_pad.refresh(0, 0, curses.LINES - 1, 0, curses.LINES - 1, curses.COLS - 1)
def refresh_emoji_pad(self) -> None: def refresh_emoji_pad(self) -> None: