Register forum user name Search FAQ

Gammon Forum

Notice: Any messages purporting to come from this site telling you that your password has expired, or that you need to verify your details, confirm your email, resolve issues, making threats, or asking for money, are spam. We do not email users with any such messages. If you have lost your password you can obtain a new one by using the password reset link.

Due to spam on this forum, all posts now need moderator approval.

 Entire forum ➜ MUSHclient ➜ General ➜ Display two colors in a single chinese character

Display two colors in a single chinese character

It is now over 60 days since the last post. This thread is closed.     Refresh page


Pages: 1  2 3  

Posted by Nick Gammon   Australia  (23,133 posts)  Bio   Forum Administrator
Date Reply #15 on Thu 22 Sep 2016 09:57 PM (UTC)
Message
Sounds like over-egging the pudding to me.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by Fiendish   USA  (2,534 posts)  Bio   Global Moderator
Date Reply #16 on Thu 22 Sep 2016 10:23 PM (UTC)
Message
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.

https://github.com/fiendish/aardwolfclientpackage
Top

Posted by LZN   (12 posts)  Bio
Date Reply #17 on Fri 23 Sep 2016 12:26 AM (UTC)
Message
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.
Top

Posted by Nick Gammon   Australia  (23,133 posts)  Bio   Forum Administrator
Date Reply #18 on Fri 23 Sep 2016 06:46 AM (UTC)
Message
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.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by LZN   (12 posts)  Bio
Date Reply #19 on Fri 23 Sep 2016 09:23 AM (UTC)
Message
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

Top

Posted by Nick Gammon   Australia  (23,133 posts)  Bio   Forum Administrator
Date Reply #20 on Fri 23 Sep 2016 09:29 PM (UTC)

Amended on Sun 25 Sep 2016 08:05 PM (UTC) by Nick Gammon

Message
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 between the lines below (to the Clipboard)
  2. Open a text editor (such as Notepad) and paste the plugin into it
  3. Save to disk on your PC, preferably in your plugins directory, as Remove_colour_code.xml
  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"



<?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.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by Fiendish   USA  (2,534 posts)  Bio   Global Moderator
Date Reply #21 on Fri 23 Sep 2016 09:43 PM (UTC)
Message
I hope the server doesn't use them to indicate anything important. ^_^;

https://github.com/fiendish/aardwolfclientpackage
Top

Posted by Nick Gammon   Australia  (23,133 posts)  Bio   Forum Administrator
Date Reply #22 on Sat 24 Sep 2016 01:23 AM (UTC)
Message
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.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by Nick Gammon   Australia  (23,133 posts)  Bio   Forum Administrator
Date Reply #23 on Sat 24 Sep 2016 01:24 AM (UTC)
Message
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. :)

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by Nick Gammon   Australia  (23,133 posts)  Bio   Forum Administrator
Date Reply #24 on Sat 24 Sep 2016 01:29 AM (UTC)
Message
I am kind-of hoping that a Sword is the same as a Sword and also the same as a Sword.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by LZN   (12 posts)  Bio
Date Reply #25 on Sat 24 Sep 2016 06:32 AM (UTC)
Message
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

Top

Posted by Nick Gammon   Australia  (23,133 posts)  Bio   Forum Administrator
Date Reply #26 on Sat 24 Sep 2016 09:59 PM (UTC)

Amended on Sat 24 Sep 2016 10:04 PM (UTC) by Nick Gammon

Message
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:


- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by Nick Gammon   Australia  (23,133 posts)  Bio   Forum Administrator
Date Reply #27 on Sat 24 Sep 2016 11:38 PM (UTC)

Amended on Sun 25 Sep 2016 05:57 AM (UTC) by Nick Gammon

Message
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 between the lines below (to the Clipboard)
  2. Open a text editor (such as Notepad) and paste the plugin into it
  3. Save to disk on your PC, preferably in your plugins directory, as Remove_colour_code.xml
  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"



<?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.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by LZN   (12 posts)  Bio
Date Reply #28 on Sun 25 Sep 2016 02:44 AM (UTC)
Message
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)
Top

Posted by Nick Gammon   Australia  (23,133 posts)  Bio   Forum Administrator
Date Reply #29 on Sun 25 Sep 2016 05:42 AM (UTC)
Message
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:


- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).

To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.


75,902 views.

This is page 2, subject is 3 pages long:  [Previous page]  1  2 3  [Next page]

It is now over 60 days since the last post. This thread is closed.     Refresh page

Go to topic:           Search the forum


[Go to top] top

Information and images on this site are licensed under the Creative Commons Attribution 3.0 Australia License unless stated otherwise.