diff --git a/tg/utils.py b/tg/utils.py index 4f8ec9a..5995714 100644 --- a/tg/utils.py +++ b/tg/utils.py @@ -7,7 +7,6 @@ import math import mimetypes import os import random -import re import shlex import struct import subprocess @@ -23,17 +22,6 @@ from typing import Any, Optional, Tuple, Type from tg import config log = logging.getLogger(__name__) -emoji_pattern = re.compile( - "[" - "\U0001F600-\U0001F64F" # emoticons - "\U0001F300-\U0001F5FF" # symbols & pictographs - "\U0001F680-\U0001F6FF" # transport & map symbols - "\U0001F1E0-\U0001F1FF" # flags (iOS) - # "\U00002702-\U000027B0" - # "\U000024C2-\U0001F251" - "]+", - flags=re.UNICODE, -) units = {"B": 1, "KB": 10 ** 3, "MB": 10 ** 6, "GB": 10 ** 9, "TB": 10 ** 12} diff --git a/tg/views.py b/tg/views.py index ba77589..be31a0d 100644 --- a/tg/views.py +++ b/tg/views.py @@ -4,18 +4,13 @@ from datetime import datetime from typing import Any, Dict, List, Optional, Tuple, Union, cast from _curses import window # type: ignore + from tg import config from tg.colors import bold, cyan, get_color, magenta, reverse, white, yellow from tg.models import Model, UserModel from tg.msg import MsgProxy from tg.tdlib import ChatType, get_chat_type, is_group -from tg.utils import ( - emoji_pattern, - get_color_by_str, - num, - string_len_dwc, - truncate_to_len, -) +from tg.utils import get_color_by_str, num, string_len_dwc, truncate_to_len log = logging.getLogger(__name__) @@ -405,7 +400,7 @@ class MsgView: # if not channel add space between name and flags flags = " " + flags label_elements = f" {dt} ", user_id, flags - label_len = sum(len(e) for e in label_elements) + label_len = sum(string_len_dwc(e) for e in label_elements) msg = self._format_msg( msg_proxy, user_id_item, width_limit=self.w - label_len - 1 @@ -415,10 +410,8 @@ class MsgView: for i, msg_line in enumerate(msg.split("\n")): # count wide character utf-8 symbols that take > 1 bytes to # print it causes invalid offset - emojies_count = sum( - map(len, emoji_pattern.findall(msg_line)) - ) - line_len = len(msg_line) + emojies_count + line_len = string_len_dwc(msg_line) + # first line cotains msg lable, e.g user name, date if i == 0: line_len += label_len