Display two colors in a single chinese character

Posted by LZN on Tue 20 Sep 2016 07:25 AM — 32 posts, 108,208 views.

#0
Hi all,
I meet a text-color issue while playing Chinese MUD.
There are few Chinese MUDs that would show a single chinese character with two colors , let me explain it by using images:

http://i.imgur.com/USYuxws.png
http://i.imgur.com/O37kYxB.png

First pic shows that characters are incorrectly from MUSHClient,
(white and grey colors are fine, but characters are garbled)
the second pic shows correctly from other.

Is this could be supported by current or future version?

NOTE: while copy and paste, that Chinese characters are displayed normally(without color, just plain text)
USA Global Moderator #1
Interesting!

Quote:
Is this could be supported by current or future version?

I think it is not supported by the current version. I don't know how hard it would be to add support for something like this to the MUSHclient code (https://github.com/nickgammon/mushclient).

Which software shows these two color characters correctly? http://i.imgur.com/O37kYxB.png

(Anyone watching this thread: I'm launching MUSHclient in WINE with "LANG=zh_CN.UTF-8 wine MUSHclient.exe" and I'm tossing this into the input bar for testing:)

\\local ch_string1 = "你往\n"; ch_string2 = string.sub(ch_string1, 1, 1)..ANSI(1,35)..string.sub(ch_string1, 2); Simulate(ANSI(0)..ch_string1..ch_string2)
Amended on Sat 21 Jan 2017 09:23 PM by Fiendish
#2
Fiendish said:

Interesting!

Which software shows these two color characters correctly? http://i.imgur.com/O37kYxB.png


I was using a telnet plugin called PttChrome on Chrome to get this picture
https://iamchucky.github.io/PttChrome/

There are some telnet client can also show two-color characters, for example:
http://pcman.ptt.cc/
http://zhouer.org/ZTerm/
USA Global Moderator #3
Code note: I'm looking at the ZTerm code now. According to the comments, it looks like it draws each Chinese character twice, masking the first and then second half.
Quote:

// 利用 clip 的功能,只畫出部份(半個)中文字。
// XXX: 每個中文都會畫兩次,又有 clip 的 overhead, 效率應該會受到蠻大的影響!


https://github.com/zhouer/ZTerm/blob/master/org/zhouer/vt/VT100.java#L2143
USA Global Moderator #4
Code note: Looks like pcman does the same for two byte characters.

(javascript version)
https://github.com/pcman-bbs/pcman.js/blob/master/lib/termview.js#L270

(windows version)
https://github.com/pcman-bbs/pcman-windows/blob/d60faad1a6db7f77ebedc1ba406a7c0061c1b6ba/Lite/TermView.cpp#L2217
Amended on Tue 20 Sep 2016 10:23 AM by Fiendish
#5
Fiendish said:

Code note: I'm looking at the ZTerm code now. According to the comments, it looks like it draws each Chinese character twice, masking the first and then second half.
Quote:

// 利用 clip 的功能,只畫出部份(半個)中文字。
// XXX: 每個中文都會畫兩次,又有 clip 的 overhead, 效率應該會受到蠻大的影響!


https://github.com/zhouer/ZTerm/blob/master/org/zhouer/vt/VT100.java#L2143


Yes, that is what comment says.
Looks like you are familiar with Chinese, that's great! :)
Australia Forum Administrator #6
Fiendish said:

(Anyone watching this thread: I'm tossing this into the input bar for testing:)

\\\local ch_string1 = "你往\n"; ch_string2 = string.sub(ch_string1, 1, 1)..ANSI(1,35)..string.sub(ch_string1, 2); Simulate(ANSI(0)..ch_string1..ch_string2)



I can't reproduce the Chinese characters at all. I just get question marks. Are you using UTF-8 in the output window? How are you getting it to display correctly?
Amended on Tue 20 Sep 2016 11:03 PM by Nick Gammon
USA Global Moderator #7
With the given launch line I have MUSHclient's UTF8 option disabled.
Australia Forum Administrator #8
@LZN: please give me the address of a Chinese MUD for me to test my enhancements on. Preferably one that display Chinese characters without me having to log on (because I don't read Chinese, nor do I speak it).
#9
Nick Gammon said:

@LZN: please give me the address of a Chinese MUD for me to test my enhancements on. Preferably one that display Chinese characters without me having to log on (because I don't read Chinese, nor do I speak it).


Hi Nick,

ip: void7777.no-ip.org
port: 7777

I will create a test character for u to log in,
name : doubleword
passwd: testdoubleword

請輸入你在本遊戲中所使用的名字 ID NAME? <!-- type 'doubleword' here !>
請輸入密碼: <!-- type 'testdoubleword' here !>
and then press enter to skip some information.

after login, type 'look' (or 'l') to look room description,
the room title contains 3 Chinese characters followed by '(A)',that is '聊天室(A)',
each Chinese character using two color to display it.
Australia Forum Administrator #10
I've been trying to convert GB2312 code page to UTF-8. I'm not at all sure it is working. Check out these images:

Typing "help":



Typing "look":




Is this better or worse than what you are seeing?

Does it make any sense at all? Is it partly right or completely wrong?
Amended on Thu 22 Sep 2016 05:46 AM by Nick Gammon
Australia Forum Administrator #11
I've been trying with telnet (on Ubuntu) and am experimenting with different encodings.

This is Chinese Traditional (Big5):

Quote:

<312hp 69m 175mv 413pw> l
�(A)
這是聊天室A棟,傳統的中國建築,檀香味瀰漫著整個空氣中,傳統的茶具
更是讓人想坐下來好好的品茗一番,來到這你可以暢所欲言,人家說:『
人若得一知己,可真死而無憾』,搞不好在這可以交到知心好友也不一定
呢!
[出口: 西]
過期的雜誌/magazine
美工刀/knife
(嗡嗡作響) 一把能夠自由進出格鬥天堂的i怳鑰。/Key



Do you happen to know what encoding (code set) you are using?
#12
Hi Nick,

These characters on screenshot is completely wrong/garbled.

I think this MUD is using Big5(Traditional Chinese) charset, not GB2312(Simplified Chinese).

It should look like:
http://i.imgur.com/C2vAxfH.png
http://i.imgur.com/cTj2edn.png
Australia Forum Administrator #13
I suspect that what is happening with the "two colour" characters is that the colour codes are getting inbetween the two bytes of the Big5 codes, thus confusing the output routine to think that they are two different characters in two colours. This seems to support what you are describing.

It won't be easy to fix as it would require detecting this situation in the first place, and drawing each character twice, carefully masking out the left half and then the right half.

Can't you turn off this dual-character colouring at the MUD end?
USA Global Moderator #14
Quote:
it would require detecting this situation in the first place, and drawing each character twice, carefully masking out the left half and then the right half.

This appears to be exactly what the Chinese-specific clients are doing. I'm guessing it must be pretty common on the Chinese servers.
Australia Forum Administrator #15
Sounds like over-egging the pudding to me.
USA Global Moderator #16
Nick Gammon said:

Sounds like over-egging the pudding to me.

Does pudding have eggs? I'm not familiar with that one! :D
But it does definitely seem like the sort of thing that someone does just because they can.
#17
Nick Gammon said:

Can't you turn off this dual-character colouring at the MUD end?


It can not just turn off color to dual-character.
It can turned off all color in MUD by using 'config -color' command, makes that colored-dual-characters are not garbled.
Australia Forum Administrator #18
I might be able to suppress colour changes between the two bytes of a two-byte BIG5 character. Please provide a "packet debug" of an example of the dual-colour character.

To do this, activate Edit menu -> Debug packets.

Then display the text in question. Then turn debugging off.

Copy and paste the results into a reply here.
#19
i
你身上攜帶著有:
(閃爍) (嗡嗡作響) 聖十字/Holy Cross

<2903/2903生命 1352/1352精神 2238/2238體力 450/418內力 96989>


Sent  packet: 22 (3 bytes) at 星期五, 九月 23, 2016, 6:20:17 下午

i..                69 0d 0a

Incoming packet: 36 (213 bytes) at 星期五, 九月 23, 2016, 6:20:18 下午

.A...W...a....:.   a7 41 a8 ad a4 57 c4 e2 b1 61 b5 db a6 b3 3a 0a
.     .[36m(.{.{   0d 20 20 20 20 20 1b 5b 33 36 6d 28 b0 7b c3 7b
).[37m .[36m(...   29 1b 5b 33 37 6d 20 1b 5b 33 36 6d 28 b6 e4 b6
..@.T).[37m .[1m   e4 a7 40 c5 54 29 1b 5b 33 37 6d 20 1b 5b 31 6d
..[0mt.[1m..[0mQ   b8 1b 5b 30 6d 74 1b 5b 31 6d a4 1b 5b 30 6d 51
.[1m..[0mr.[37;0   1b 5b 31 6d a6 1b 5b 30 6d 72 1b 5b 33 37 3b 30
m/Holy Cross....   6d 2f 48 6f 6c 79 20 43 72 6f 73 73 0a 0d 0a 0d
<.[32m2903.[37m/   3c 1b 5b 33 32 6d 32 39 30 33 1b 5b 33 37 6d 2f
2903...R .[35m13   32 39 30 33 a5 cd a9 52 20 1b 5b 33 35 6d 31 33
52.[37m/1352....   35 32 1b 5b 33 37 6d 2f 31 33 35 32 ba eb af ab
 .[36m2238.[37m/   20 1b 5b 33 36 6d 32 32 33 38 1b 5b 33 37 6d 2f
2238...O .[33m45   32 32 33 38 c5 e9 a4 4f 20 1b 5b 33 33 6d 34 35
0.[37m/418...O 9   30 1b 5b 33 37 6d 2f 34 31 38 a4 ba a4 4f 20 39
6989>              36 39 38 39 3e

Australia Forum Administrator #20
This should get rid of the colour codes in the middle of a two-byte character.

Template:saveplugin=Remove_colour_code
To save and install the Remove_colour_code plugin do this:
  1. Copy the code below (in the code box) to the Clipboard
  2. Open a text editor (such as Notepad) and paste the plugin code into it
  3. Save to disk on your PC, preferably in your plugins directory, as Remove_colour_code.xml
    • The "plugins" directory is usually under the "worlds" directory inside where you installed MUSHclient.
  4. Go to the MUSHclient File menu -> Plugins
  5. Click "Add"
  6. Choose the file Remove_colour_code.xml (which you just saved in step 3) as a plugin
  7. Click "Close"
  8. Save your world file, so that the plugin loads next time you open it.



<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE muclient>

<muclient>
<plugin
   name="Remove_colour_code"
   author="Nick Gammon"
   id="cc152a5618bce5870c579574"
   language="Lua"
   purpose="Removes embedded colour from Big5 codes"
   date_written="2016-09-24 08:25:50"
   date_modified="2016-09-25 08:01:42"
   requires="4.90"
   version="2.0"
   >
</plugin>

<!--  Script  -->
<script>
<![CDATA[

function OnPluginPacketReceived (sText)
  -- BIG5:   -- 0x81 to 0xFE, 0x40 to 0x7E or 0xA1 to 0xFE

  -- look for sequence x ESC [ m ESC [ 31 m y
  sText = string.gsub (sText, "([\129-\254])(\027%[m\027%[[0-9;]*m)([\064-\126\161-\254])", "%1%3%2")

  -- look for sequence x ESC [ 31 m y
  sText = string.gsub (sText, "([\129-\254])(\027%[[0-9;]*m)([\064-\126\161-\254])", "%1%3%2")

  return sText
end -- function

]]>
</script>
</muclient>



What it does is look for ANSI colour codes (ie. ESC [ digits m) between two bytes in the range 0x81-0xFE and 0x40 to 0x7E or 0xA1 to 0xFE and move the colour code to after the two bytes.

[EDIT] Note a much more reliable version below in reply #27.
Amended on Sun 25 Sep 2016 08:05 PM by Nick Gammon
USA Global Moderator #21
I hope the server doesn't use them to indicate anything important. ^_^;
Australia Forum Administrator #22
You could move the second colour to after the character, that is transpose: xcy (where c is the colour) to xyc.

That is fairly trivial to do, if you have problems with colours. The supplied packet seems to change colours *a lot* so I doubt the wrong colour will persist for long.
Australia Forum Administrator #23
Fiendish said:

I hope the server doesn't use them to indicate anything important. ^_^;


Oh, you mean a symbol shown in two colours has a different meaning to that in one colour? Well, let's hope colour-blind people don't play the game then. :)
Australia Forum Administrator #24
I am kind-of hoping that a Sword is the same as a Sword and also the same as a Sword.
#25
Hi Nick,

This plugs helps a lot, but still have few garbled characters from other item descriptions.

Below are some items(that I have it in MUD now) are still garbled(belt, fierce blade, ancient weapon, blackhole wall and micro processor)


i
你身上攜帶著有:
     (閃爍) (嗡嗡作響) 桃花束腰/belt
     (閃爍) (嗡嗡作響) 蠻荒之刃/fierce blade
     (閃爍) (嗡嗡作響) 上古神兵/ancient weapon
     (閃爍) (嗡嗡作響) 黑洞牆/blackhole wall
     (閃爍) (嗡嗡作響) 微電腦裝置/micro processor
     生命水晶/life crystal
     魔法方塊/Magic Box

<2903/2903生命 1352/1352精神 2238/2238體力 450/418內力 96989>


garbled img:

http://i.imgur.com/DHTvokg.png




Sent  packet: 90 (3 bytes) at 星期六, 九月 24, 2016, 3:11:46 下午

i..                69 0d 0a

Incoming packet: 129 (753 bytes) at 星期六, 九月 24, 2016, 3:11:46 下午

.A...W...a....:.   a7 41 a8 ad a4 57 c4 e2 b1 61 b5 db a6 b3 3a 0a
.     .[36m(.{.{   0d 20 20 20 20 20 1b 5b 33 36 6d 28 b0 7b c3 7b
).[37m .[36m(...   29 1b 5b 33 37 6d 20 1b 5b 33 36 6d 28 b6 e4 b6
..@.T).[37m .[1;   e4 a7 40 c5 54 29 1b 5b 33 37 6d 20 1b 5b 31 3b
31m..[m.[1m..[1;   33 31 6d ae 1b 5b 6d 1b 5b 31 6d e7 1b 5b 31 3b
31m..[m.[1m..[1;   33 31 6d aa 1b 5b 6d 1b 5b 31 6d e1 1b 5b 31 3b
31m..[m.[1m..[1;   33 31 6d a7 1b 5b 6d 1b 5b 31 6d f4 1b 5b 31 3b
31m..[m.[1my.[m/   33 31 6d b8 1b 5b 6d 1b 5b 31 6d 79 1b 5b 6d 2f
belt..     .[36m   62 65 6c 74 0a 0d 20 20 20 20 20 1b 5b 33 36 6d
(.{.{).[37m .[36   28 b0 7b c3 7b 29 1b 5b 33 37 6d 20 1b 5b 33 36
m(.....@.T).[37m   6d 28 b6 e4 b6 e4 a7 40 c5 54 29 1b 5b 33 37 6d
 .[31m..[mZ.[31m   20 1b 5b 33 31 6d c6 1b 5b 6d 5a 1b 5b 33 31 6d
..[m..[1m..[m..[   af 1b 5b 6d ee 1b 5b 31 6d a4 1b 5b 6d a7 1b 5b
1m.[36m..[m.[36m   31 6d 1b 5b 33 36 6d a4 1b 5b 6d 1b 5b 33 36 6d
b.[m/fierce blad   62 1b 5b 6d 2f 66 69 65 72 63 65 20 62 6c 61 64
e..     .[36m(.{   65 0a 0d 20 20 20 20 20 1b 5b 33 36 6d 28 b0 7b
.{).[37m .[36m(.   c3 7b 29 1b 5b 33 37 6d 20 1b 5b 33 36 6d 28 b6
....@.T).[37m .[   e4 b6 e4 a7 40 c5 54 29 1b 5b 33 37 6d 20 1b 5b
1m.[34m..[36mW.[   31 6d 1b 5b 33 34 6d a4 1b 5b 33 36 6d 57 1b 5b
34m..[36mj.[37m.   33 34 6d a5 1b 5b 33 36 6d 6a 1b 5b 33 37 6d af
.[m..[1m..[mL/an   1b 5b 6d ab 1b 5b 31 6d a7 1b 5b 6d 4c 2f 61 6e
cient weapon..     63 69 65 6e 74 20 77 65 61 70 6f 6e 0a 0d 20 20
   .[36m(.{.{).[   20 20 20 1b 5b 33 36 6d 28 b0 7b c3 7b 29 1b 5b
37m .[36m(.....@   33 37 6d 20 1b 5b 33 36 6d 28 b6 e4 b6 e4 a7 40
.T).[37m .[m.[1;   c5 54 29 1b 5b 33 37 6d 20 1b 5b 6d 1b 5b 31 3b
30m...}.[m.[1m.U   33 30 6d b6 c2 ac 7d 1b 5b 6d 1b 5b 31 6d c7 55
.[m.[1;31m..[m.[   1b 5b 6d 1b 5b 31 3b 33 31 6d c0 1b 5b 6d 1b 5b
31m..[m.[0m/blac   33 31 6d f0 1b 5b 6d 1b 5b 30 6d 2f 62 6c 61 63
khole wall..       6b 68 6f 6c 65 20 77 61 6c 6c 0a 0d 20 20 20 20
 .[36m(.{.{).[37   20 1b 5b 33 36 6d 28 b0 7b c3 7b 29 1b 5b 33 37
m .[36m(.....@.T   6d 20 1b 5b 33 36 6d 28 b6 e4 b6 e4 a7 40 c5 54
).[37m ..[m.[1mL   29 1b 5b 33 37 6d 20 b7 1b 5b 6d 1b 5b 31 6d 4c
..[m.[0mq..[m.[1   b9 1b 5b 6d 1b 5b 30 6d 71 b8 1b 5b 6d 1b 5b 31
m...[m.[0m...[m.   6d a3 b8 1b 5b 6d 1b 5b 30 6d cb b8 1b 5b 6d 1b
[1mm.[m.[0m/micr   5b 31 6d 6d 1b 5b 6d 1b 5b 30 6d 2f 6d 69 63 72
o processor..      6f 20 70 72 6f 63 65 73 73 6f 72 0a 0d 20 20 20
  ...R..../life    20 20 a5 cd a9 52 a4 f4 b4 b9 2f 6c 69 66 65 20
crystal..     .[   63 72 79 73 74 61 6c 0a 0d 20 20 20 20 20 1b 5b
33m.].[34m.k.[35   33 33 6d c5 5d 1b 5b 33 34 6d aa 6b 1b 5b 33 35
m...[36m...[0m/M   6d a4 e8 1b 5b 33 36 6d b6 f4 1b 5b 30 6d 2f 4d
agic Box....<.[3   61 67 69 63 20 42 6f 78 0a 0d 0a 0d 3c 1b 5b 33
2m2903.[37m/2903   32 6d 32 39 30 33 1b 5b 33 37 6d 2f 32 39 30 33
...R .[35m1352.[   a5 cd a9 52 20 1b 5b 33 35 6d 31 33 35 32 1b 5b
37m/1352.... .[3   33 37 6d 2f 31 33 35 32 ba eb af ab 20 1b 5b 33
6m2238.[37m/2238   36 6d 32 32 33 38 1b 5b 33 37 6d 2f 32 32 33 38
...O .[33m450.[3   c5 e9 a4 4f 20 1b 5b 33 33 6d 34 35 30 1b 5b 33
7m/418...O 96989   37 6d 2f 34 31 38 a4 ba a4 4f 20 39 36 39 38 39
>                  3e

Australia Forum Administrator #26
I have amended the plugin in reply #20 - try that. I got these results in testing:


你身上攜帶著有:
     (閃爍) (嗡嗡作響) 桃花束腰/belt
     (閃爍) (嗡嗡作響) 蠻荒之刃/fierce blade
     (閃爍) (嗡嗡作響) 上古神兵/ancient weapon
     (閃爍) (嗡嗡作響) 黑洞ソ牆/blackhole wall
     (閃爍) (嗡嗡作響) 微電腦裝置/micro processor
     生命水晶/life crystal
     魔法方/Magic Box

<2903/2903生命 1352/1352精神 2238/2238體力 450/418內力 96989


Screenshot:

Amended on Sat 24 Sep 2016 10:04 PM by Nick Gammon
Australia Forum Administrator #27
This newer version should work more reliably for multiple embedded colour codes:

Template:saveplugin=Remove_colour_code
To save and install the Remove_colour_code plugin do this:
  1. Copy the code below (in the code box) to the Clipboard
  2. Open a text editor (such as Notepad) and paste the plugin code into it
  3. Save to disk on your PC, preferably in your plugins directory, as Remove_colour_code.xml
    • The "plugins" directory is usually under the "worlds" directory inside where you installed MUSHclient.
  4. Go to the MUSHclient File menu -> Plugins
  5. Click "Add"
  6. Choose the file Remove_colour_code.xml (which you just saved in step 3) as a plugin
  7. Click "Close"
  8. Save your world file, so that the plugin loads next time you open it.



<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE muclient>

<muclient>
<plugin
   name="Remove_colour_code"
   author="Nick Gammon"
   id="cc152a5618bce5870c579574"
   language="Lua"
   purpose="Removes embedded colour from Big5 codes"
   date_written="2016-09-24 08:25:50"
   date_modified="2016-09-25 16:36:42"
   requires="4.90"
   version="3.1"
   >
</plugin>

<!--  Script  -->
<script>
<![CDATA[

-- save typing function names with "lpeg" in front of them:
local P, V, R, C, S, Cs = lpeg.P, lpeg.V, lpeg.R, lpeg.C, lpeg.S, lpeg.Cs

local Big5_first  = R"\129\254"   -- start of Big5 code (0x81 to 0xFE)
local Big5_second = R"\064\126" + R"\161\254"  -- end of Big5 code (0x40 to 0x7E or 0xA1 to 0xFE)

-- grammar for parsing the packet
grammar = P {
           "big5",      --> this tells LPEG which rule to process first

           -- An ANSI colour sequence is: ESC [ digits or ";" then "m"
           ColourCode   = P"\027" * P"[" * S"0123456789;"^0 * P"m",

           -- We look for the first BIG5 code (0x81 to 0xFE) followed by one or more ANSI sequences
           --  followed by the second BIG5 code (0x40 to 0x7E or 0xA1 to 0xFE)
           big5         = C (Big5_first) * C (V"ColourCode"^1) * C (Big5_second),
           }

-- swap the order so that the first and second BIG5 byte are together
-- followed by the colour code that was between them
local function substituteFunction (first, colour, second)
  return first .. second .. colour
end -- substituteFunction

-- call the substitution function on a match

-- test for: Ordinary Big5 (Big5_first followed by Big5_second)
--       or: Big5 with colour in the middle
--       or: skip one character

pattern = Cs(((Big5_first * Big5_second) + (grammar / substituteFunction) + 1)^0)

-- handle incoming packet
function OnPluginPacketReceived (sText)
  return lpeg.match(pattern, sText)
end -- function

]]>
</script>
</muclient>



Instead of using string.gsub it uses LPEG (Lua Parsing Expression Grammar). This lets me check for multiple colour sequences inside a single BIG5 code rather than just one or two. This would handle the situation where the MUD sends (say) 3 colour changes between the two BIG5 bytes.
Amended on Sun 25 Sep 2016 05:57 AM by Nick Gammon
#28
Hi Nick,

New plugin works to display two-color-character not garbled, but I also meet a side effect that some colored-text become garbled.


i
你身上攜帶著有:
     (嗡嗡作響) 小少爺之神力長靴/Childe boots
     (嗡嗡作響) 阿拉蕾之神力手套/Arale gauntlets
     生命水晶/life crystal
     魔法方塊/Magic Box


神力(in Childe boots/Arale gauntlets) and 塊(in Magic box) are garbled.

img
http://i.imgur.com/YksqW5X.png


Sent  packet: 99 (3 bytes) at 星期日, 九月 25, 2016, 10:48:59 上午

i..                69 0d 0a

Incoming packet: 142 (332 bytes) at 星期日, 九月 25, 2016, 10:48:59 上午

.A...W...a....:.   a7 41 a8 ad a4 57 c4 e2 b1 61 b5 db a6 b3 3a 0a
.     .[36m(....   0d 20 20 20 20 20 1b 5b 33 36 6d 28 b6 e4 b6 e4
.@.T).[37m .p...   a7 40 c5 54 29 1b 5b 33 37 6d 20 a4 70 a4 d6 b7
....[36m...O...u   dd a4 a7 1b 5b 33 36 6d af ab a4 4f aa f8 b9 75
.[0m/Childe boot   1b 5b 30 6d 2f 43 68 69 6c 64 65 20 62 6f 6f 74
s..     .[36m(..   73 0a 0d 20 20 20 20 20 1b 5b 33 36 6d 28 b6 e4
...@.T).[37m ...   b6 e4 a7 40 c5 54 29 1b 5b 33 37 6d 20 aa fc a9
......[35m...O..   d4 c1 a2 a4 a7 1b 5b 33 35 6d af ab a4 4f a4 e2
.M.[0m/Arale gau   ae 4d 1b 5b 30 6d 2f 41 72 61 6c 65 20 67 61 75
ntlets..     ...   6e 74 6c 65 74 73 0a 0d 20 20 20 20 20 a5 cd a9
R..../life cryst   52 a4 f4 b4 b9 2f 6c 69 66 65 20 63 72 79 73 74
al..     .[33m.]   61 6c 0a 0d 20 20 20 20 20 1b 5b 33 33 6d c5 5d
.[34m.k.[35m...[   1b 5b 33 34 6d aa 6b 1b 5b 33 35 6d a4 e8 1b 5b
36m...[0m/Magic    33 36 6d b6 f4 1b 5b 30 6d 2f 4d 61 67 69 63 20
Box....<.[32m290   42 6f 78 0a 0d 0a 0d 3c 1b 5b 33 32 6d 32 39 30
3.[37m/2903...R    33 1b 5b 33 37 6d 2f 32 39 30 33 a5 cd a9 52 20
.[35m1352.[37m/1   1b 5b 33 35 6d 31 33 35 32 1b 5b 33 37 6d 2f 31
352.... .[36m223   33 35 32 ba eb af ab 20 1b 5b 33 36 6d 32 32 33
8.[37m/2238...O    38 1b 5b 33 37 6d 2f 32 32 33 38 c5 e9 a4 4f 20
.[33m450.[37m/41   1b 5b 33 33 6d 34 35 30 1b 5b 33 37 6d 2f 34 31
8...O 96989>       38 a4 ba a4 4f 20 39 36 39 38 39 3e



I think it might be because of that:

之(a4a7) Color(1b5b33366d) 神(afab)

'a7 color af' matches grammar pattern, and results that :

之(a4a7) 神(af) Color(1b5b33366d) 神(ab)
Australia Forum Administrator #29
You are quite right!

The earlier version advanced one byte at a time, so it could interpret the sequence:


xycxy


(Where xy is the character and c the colour) as a sequence that needed to be re-arranged, and turn it into:


xyxcy


I have updated the code in reply #27 so that it also looks for "xy" as the first choice. That way it skips two bytes, and that fixes this problem.

Screenshot:

Australia Forum Administrator #30
This shows how LPEG is very powerful. You couldn't do this with a simple pattern.

For more details:

LPeg - Parsing Expression Grammars For Lua
Amended on Sun 25 Sep 2016 05:49 AM by Nick Gammon
#31
Hi Nick,

This plugin works perfect now,
I see no garbled character anymore.
Thanks!