文字列カット追加
このコミットが含まれているのは:
+20
-1
@@ -7,7 +7,26 @@ class CommonModule:
|
||||
return unicodedata.east_asian_width (c) in ['F', 'W', 'A']
|
||||
|
||||
@classmethod
|
||||
def string_width_per_pt (cls, string: str) -> float:
|
||||
def len_by_full (cls, string: str) -> float:
|
||||
return sum ([1 if cls.is_wide (c) else .5
|
||||
for c in string.decode ('utf-8')])
|
||||
|
||||
@classmethod
|
||||
def index_by_f2c (cls, string: str, index: float) -> int:
|
||||
i = 0
|
||||
work = ''
|
||||
for c in string.decode ('utf-8'):
|
||||
work += c
|
||||
if cls.len_by_full (work) > index:
|
||||
break
|
||||
else:
|
||||
i += 1
|
||||
|
||||
return i
|
||||
|
||||
@classmethod
|
||||
def mid_by_full (cls, string: str, start: float, length: float) -> str:
|
||||
trimmed_left = string[cls.index_by_f2c (string, start):]
|
||||
|
||||
return trimmed_left[:cls.index_by_f2c (trimmed_left, length)]
|
||||
|
||||
|
||||
@@ -10,6 +10,7 @@ from aques import Aques
|
||||
from playsound import playsound
|
||||
from common_module import CommonModule
|
||||
from youtube import *
|
||||
from datetime import datetime
|
||||
|
||||
|
||||
class Main:
|
||||
@@ -42,7 +43,13 @@ class Main:
|
||||
|
||||
screen.blit (balloon, (0, 0))
|
||||
screen.blit (
|
||||
user_font.render ('> ' + message, True, (0, 0, 0)),
|
||||
user_font.render (
|
||||
'> ' + (message
|
||||
if (CommonModule.len_by_full (message)
|
||||
<= 21)
|
||||
else (CommonModule.mid_by_full (
|
||||
message, 0, 19.5)
|
||||
+ '...')), True, (0, 0, 0)),
|
||||
(120, 70))
|
||||
screen.blit (
|
||||
nizika_font.render (answer, True, (192, 0, 0)),
|
||||
@@ -71,6 +78,17 @@ class Main:
|
||||
f'live_chat.is_alive () == {live_chat.is_alive ()}',
|
||||
True, (0, 0, 0)),
|
||||
(i % 2, i // 2 * 2))
|
||||
screen.blit (
|
||||
system_font.render (datetime.now (), True, (0, 0, 0)),
|
||||
(i % 2, 32 + i // 2 * 2))
|
||||
|
||||
if live_chat.is_alive ():
|
||||
screen.blit (
|
||||
system_font.render (
|
||||
f'messages == {[c.message
|
||||
for c in live_chat.get ().items]}',
|
||||
True, (0, 0, 0)),
|
||||
(i % 2, 64 + i // 2 * 2))
|
||||
|
||||
pygame.display.update ()
|
||||
|
||||
|
||||
新しい課題から参照
ユーザをブロックする