From 38cea234bbc922eeda1ad95c402caf0bca9fd902 Mon Sep 17 00:00:00 2001 From: Yohann D'ANELLO Date: Mon, 21 Dec 2020 16:04:11 +0100 Subject: [PATCH] Make the emoji lib optional Signed-off-by: Yohann D'ANELLO --- squinnondation/squinnondation.py | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/squinnondation/squinnondation.py b/squinnondation/squinnondation.py index dec84df..c4916bd 100644 --- a/squinnondation/squinnondation.py +++ b/squinnondation/squinnondation.py @@ -11,9 +11,6 @@ from ipaddress import IPv6Address from threading import Thread from typing import Any, List, Optional, Tuple -import emoji -from emoji import unicode_codes - from squinnondation.term_manager import TermManager @@ -64,6 +61,17 @@ class Squinnondation: curses.noecho() squirrel = Squirrel(instance, nickname) + + if not squirrel.squinnondation.no_emoji: + # Check that the emoji lib is installed + try: + import emoji + _ = emoji + except ImportError: + squirrel.squinnondation.no_emoji = True + squirrel.add_system_message("Warning: the emoji lib is not installed. The support will be disabled." + "To use them, please consider to install the emoji package.") + squirrel.refresh_history() squirrel.refresh_input() if not instance.no_emoji: @@ -640,6 +648,9 @@ class Squirrel(Hazelnut): The emoji pad contains the list of all available emojis. Clicking on a emoji auto-complete the emoji in the input pad. """ + import emoji + from emoji import unicode_codes + height, width = self.emoji_pad.getmaxyx() height -= 1 width -= 1 @@ -684,6 +695,7 @@ class Squirrel(Hazelnut): """ # Replace :emoji_name: by the good emoji if not self.squinnondation.no_emoji: + import emoji msg = emoji.emojize(msg, use_aliases=True) if self.squinnondation.no_markdown: @@ -795,6 +807,11 @@ class Squirrel(Hazelnut): """ Display the emoji pad if necessary. """ + if self.squinnondation.no_emoji: + return + + from emoji import unicode_codes + self.emoji_pad.erase() if self.emoji_panel_page > 0: