Make the emoji lib optional

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

View File

@ -11,9 +11,6 @@ from ipaddress import IPv6Address
from threading import Thread from threading import Thread
from typing import Any, List, Optional, Tuple from typing import Any, List, Optional, Tuple
import emoji
from emoji import unicode_codes
from squinnondation.term_manager import TermManager from squinnondation.term_manager import TermManager
@ -64,6 +61,17 @@ class Squinnondation:
curses.noecho() curses.noecho()
squirrel = Squirrel(instance, nickname) 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_history()
squirrel.refresh_input() squirrel.refresh_input()
if not instance.no_emoji: if not instance.no_emoji:
@ -640,6 +648,9 @@ class Squirrel(Hazelnut):
The emoji pad contains the list of all available emojis. The emoji pad contains the list of all available emojis.
Clicking on a emoji auto-complete the emoji in the input pad. 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, width = self.emoji_pad.getmaxyx()
height -= 1 height -= 1
width -= 1 width -= 1
@ -684,6 +695,7 @@ class Squirrel(Hazelnut):
""" """
# Replace :emoji_name: by the good emoji # Replace :emoji_name: by the good emoji
if not self.squinnondation.no_emoji: if not self.squinnondation.no_emoji:
import emoji
msg = emoji.emojize(msg, use_aliases=True) msg = emoji.emojize(msg, use_aliases=True)
if self.squinnondation.no_markdown: if self.squinnondation.no_markdown:
@ -795,6 +807,11 @@ class Squirrel(Hazelnut):
""" """
Display the emoji pad if necessary. Display the emoji pad if necessary.
""" """
if self.squinnondation.no_emoji:
return
from emoji import unicode_codes
self.emoji_pad.erase() self.emoji_pad.erase()
if self.emoji_panel_page > 0: if self.emoji_panel_page > 0: