mirror of
https://github.com/paul-nameless/tg
synced 2024-11-22 03:43:19 +00:00
Remove old way to count wide characters
This commit is contained in:
parent
98edcae1c4
commit
5bf3f62797
2 changed files with 5 additions and 24 deletions
12
tg/utils.py
12
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}
|
||||
|
||||
|
||||
|
|
17
tg/views.py
17
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
|
||||
|
|
Loading…
Reference in a new issue