quest zh: translate chunks 25-30 (old pirate, questscroll, quiz, skill groups); keep [TAG] whole when wrapping
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
69d214ba20
commit
85cd541560
@@ -57,11 +57,12 @@ def columns(char: str) -> int:
|
||||
|
||||
|
||||
def wrap(line: str, width: int = WIDTH):
|
||||
"""Break a line at the width; CJK text breaks anywhere, ASCII words and %s stay whole."""
|
||||
tokens = re.findall(r"%[-+ #0-9.]*[a-zA-Z]|[A-Za-z0-9_'.,!?:;()/-]+|\s+|.", line)
|
||||
"""Break a line at the width; CJK text breaks anywhere, ASCII words, %s and [TAG ...] stay whole."""
|
||||
tokens = re.findall(r"\[/?[A-Z]+[^\]\[]*\]|%[-+ #0-9.]*[a-zA-Z]|[A-Za-z0-9_'.,!?:;()/-]+|\s+|.", line)
|
||||
lines, current, used = [], "", 0
|
||||
for token in tokens:
|
||||
size = sum(columns(c) for c in token)
|
||||
# A tag such as [COLOR r;1|g;0|b;0] or [DELAY value;150] takes no room on screen.
|
||||
size = 0 if re.fullmatch(r"\[/?[A-Z]+[^\]\[]*\]", token) else sum(columns(c) for c in token)
|
||||
if used + size > width and current.strip():
|
||||
lines.append(current.rstrip())
|
||||
current, used = "", 0
|
||||
|
||||
Reference in New Issue
Block a user