mirror of
https://github.com/1j01/textual-paint.git
synced 2024-09-11 15:56:03 +03:00
Prevent digits in document from merging with mIRC color codes
If digits were present in the document, they were concatenated after the color codes, and they ran together indistinguishably. This changed the color index numbers that were read back, to potentially invalid color indices, and lost the digits as part of the document. It needs the delimiter of the ending escape code to separate the digits.
This commit is contained in:
parent
f77d2bba38
commit
967801cf17
@ -36,6 +36,7 @@
|
|||||||
"dasharray",
|
"dasharray",
|
||||||
"Deutsch",
|
"Deutsch",
|
||||||
"DIALOGEX",
|
"DIALOGEX",
|
||||||
|
"disambiguates",
|
||||||
"domtree",
|
"domtree",
|
||||||
"emacsclient",
|
"emacsclient",
|
||||||
"executablepath",
|
"executablepath",
|
||||||
|
@ -916,6 +916,9 @@ class AnsiArtDocument:
|
|||||||
irc_text += str(closest_color(Color.from_rich_color(style.color)))
|
irc_text += str(closest_color(Color.from_rich_color(style.color)))
|
||||||
irc_text += ","
|
irc_text += ","
|
||||||
irc_text += str(closest_color(Color.from_rich_color(style.bgcolor)))
|
irc_text += str(closest_color(Color.from_rich_color(style.bgcolor)))
|
||||||
|
if text[0] in "0123456789,":
|
||||||
|
# separate the color code from the text with an ending escape character
|
||||||
|
irc_text += "\x03"
|
||||||
irc_text += text
|
irc_text += text
|
||||||
else:
|
else:
|
||||||
irc_text += text
|
irc_text += text
|
||||||
@ -1007,7 +1010,8 @@ class AnsiArtDocument:
|
|||||||
fg_color = default_fg
|
fg_color = default_fg
|
||||||
|
|
||||||
color_escape = "\x03"
|
color_escape = "\x03"
|
||||||
color_escape_re = re.compile(r"\x03(\d{1,2})?(?:,(\d{1,2}))?")
|
# an optional escape code at the end disambiguates a digit from part of the color code
|
||||||
|
color_escape_re = re.compile(r"\x03(\d{1,2})?(?:,(\d{1,2}))?\x03?")
|
||||||
reset_escape = "\x0F"
|
reset_escape = "\x0F"
|
||||||
|
|
||||||
index = 0
|
index = 0
|
||||||
@ -1017,6 +1021,7 @@ class AnsiArtDocument:
|
|||||||
match = color_escape_re.match(text[index:])
|
match = color_escape_re.match(text[index:])
|
||||||
if match:
|
if match:
|
||||||
index += len(match.group(0))
|
index += len(match.group(0))
|
||||||
|
# TODO: should a one-value syntax reset the background?
|
||||||
bg_color = default_bg
|
bg_color = default_bg
|
||||||
fg_color = default_fg
|
fg_color = default_fg
|
||||||
if match.group(1):
|
if match.group(1):
|
||||||
|
Loading…
Reference in New Issue
Block a user