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 ➜ How to get ANSI color from mud by triggers

How to get ANSI color from mud by triggers

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


Posted by Andy.Liu   (22 posts)  Bio
Date Tue 02 May 2017 06:49 AM (UTC)

Amended on Wed 03 May 2017 04:48 AM (UTC) by Nick Gammon

Message
Hi,
I searched the forum and try to find a way to capture ansi color details by triggers.

My case it,when I look at a flag ,it will show a flag with colors. The text with white text color is what I want.

In zmud,it is like:


#TRIGGER {*%e[1;4(%d)m(%s)(%s)(%s)*}


Yes,I want to get the background ANSI color code.
I find something here: http://www.gammon.com.au/scripts/doc.php?function=ANSI

But I don't know how to get the raw ANSI color code by trigger. And I get styles detail by the following code:

The questions is it represents color with RGB,not ANSI code.How can I translate it into ANSI code or what a table between them?

Also,I capture the debug packets at the end of the post.

Thanks.



function zzTestFlag()
  wait.make(function()
      Send("look qi")
    local colorTable = {}
    local start = true
    while true do
      local line,wildcards,styles = wait.regexp("(.*)")
      local validLine = string.find(line,"~") or string.find(line,"˜") 
      if start then 
        if validLine then 
           start = false 
        end 
      end 
      if not line or (#line<2 and not start) then 
        break
      end   
           
       if validLine then 
        print("AAA"..line.."BBB")
        print("styles")       
        for k, v in ipairs (styles) do      
          if RGBColourToName(v.textcolour)== "white" then 
              local backcolour = RGBColourToName(v.backcolour)
            if not colorTable[backcolour] then 
              colorTable[backcolour] = 0
            end 
            colorTable[backcolour] = tonumber(colorTable[backcolour]) + string.len(v.text)
            --print(backcolour,"XXX"..v.text.."YYY")
          end 
        end -- for each style run
      end
    end 
    
    --
    tprint(colorTable)
    local flagColor = itemWithMaxCount(colorTable)
    print(flagColor)
    end)
end 


---packets


4;1m .[42;1m.[46   34 3b 31 6d 20 1b 5b 34 32 3b 31 6d 1b 5b 34 36
;1m .[41;1m .[44   3b 31 6d 20 1b 5b 34 31 3b 31 6d 20 1b 5b 34 34
;1m .[44;1m .[45   3b 31 6d 20 1b 5b 34 34 3b 31 6d 20 1b 5b 34 35
;1m.[46;1m .[42;   3b 31 6d 1b 5b 34 36 3b 31 6d 20 1b 5b 34 32 3b
1m .[42;1m .[41;   31 6d 20 1b 5b 34 32 3b 31 6d 20 1b 5b 34 31 3b
1m .[47;1m.[46;1   31 6d 20 1b 5b 34 37 3b 31 6d 1b 5b 34 36 3b 31
m .[43;1m .[44;1   6d 20 1b 5b 34 33 3b 31 6d 20 1b 5b 34 34 3b 31
m .[45;1m .[41;1   6d 20 1b 5b 34 35 3b 31 6d 20 1b 5b 34 31 3b 31
m.[46;1m .[47;1m   6d 1b 5b 34 36 3b 31 6d 20 1b 5b 34 37 3b 31 6d
.[46;1m .[45;1m.   1b 5b 34 36 3b 31 6d 20 1b 5b 34 35 3b 31 6d 1b
[46;1m .[42;1m.[   5b 34 36 3b 31 6d 20 1b 5b 34 32 3b 31 6d 1b 5b
46;1m .[45;1m.[4   34 36 3b 31 6d 20 1b 5b 34 35 3b 31 6d 1b 5b 34
6;1m .[41;1m.[46   36 3b 31 6d 20 1b 5b 34 31 3b 31 6d 1b 5b 34 36
;1m .[2;37;0m...   3b 31 6d 20 1b 5b 32 3b 33 37 3b 30 6d a1 ab 0d
....[42;1m .[42;   0a a1 d6 1b 5b 34 32 3b 31 6d 20 1b 5b 34 32 3b
1m .[41;1m.[46;1   31 6d 20 1b 5b 34 31 3b 31 6d 1b 5b 34 36 3b 31
m .[44;1m.[46;1m   6d 20 1b 5b 34 34 3b 31 6d 1b 5b 34 36 3b 31 6d
 .[43;1m.[46;1m    20 1b 5b 34 33 3b 31 6d 1b 5b 34 36 3b 31 6d 20
.[45;1m.[46;1m .   1b 5b 34 35 3b 31 6d 1b 5b 34 36 3b 31 6d 20 1b
[45;1m.[46;1m .[   5b 34 35 3b 31 6d 1b 5b 34 36 3b 31 6d 20 1b 5b
42;1m.[46;1m .[4   34 32 3b 31 6d 1b 5b 34 36 3b 31 6d 20 1b 5b 34
3;1m.[46;1m .[41   33 3b 31 6d 1b 5b 34 36 3b 31 6d 20 1b 5b 34 31
;1m.[46;1m .[44;   3b 31 6d 1b 5b 34 36 3b 31 6d 20 1b 5b 34 34 3b
1m.[46;1m .[47;1   31 6d 1b 5b 34 36 3b 31 6d 20 1b 5b 34 37 3b 31
m.[46;1m .[43;1m   6d 1b 5b 34 36 3b 31 6d 20 1b 5b 34 33 3b 31 6d
 .[45;1m.[46;1m    20 1b 5b 34 35 3b 31 6d 1b 5b 34 36 3b 31 6d 20
.[44;1m.[46;1m .   1b 5b 34 34 3b 31 6d 1b 5b 34 36 3b 31 6d 20 1b
[43;1m.[46;1m .[   5b 34 33 3b 31 6d 1b 5b 34 36 3b 31 6d 20 1b 5b
45;1m.[46;1m .[4   34 35 3b 31 6d 1b 5b 34 36 3b 31 6d 20 1b 5b 34
7;1m.[46;1m .[42   37 3b 31 6d 1b 5b 34 36 3b 31 6d 20 1b 5b 34 32
;1m.[46;1m .[44;   3b 31 6d 1b 5b 34 36 3b 31 6d 20 1b 5b 34 34 3b
1m.[46;1m .[47;1   31 6d 1b 5b 34 36 3b 31 6d 20 1b 5b 34 37 3b 31
m.[46;1m .[41;1m   6d 1b 5b 34 36 3b 31 6d 20 1b 5b 34 31 3b 31 6d
.[46;1m .[47;1m    1b 5b 34 36 3b 31 6d 20 1b 5b 34 37 3b 31 6d 20
.[44;1m .[45;1m    1b 5b 34 34 3b 31 6d 20 1b 5b 34 35 3b 31 6d 20
.[2;37;0m.......   1b 5b 32 3b 33 37 3b 30 6d a1 ab 0d 0a a1 d6 1b
[47;1m.[46;1m .[   5b 34 37 3b 31 6d 1b 5b 34 36 3b 31 6d 20 1b 5b
41;1m.[46;1m .[4   34 31 3b 31 6d 1b 5b 34 36 3b 31 6d 20 1b 5b 34
1;1m .[47;1m.[46   31 3b 31 6d 20 1b 5b 34 37 3b 31 6d 1b 5b 34 36
;1m .[42;1m.[46;   3b 31 6d 20 1b 5b 34 32 3b 31 6d 1b 5b 34 36 3b


[EDIT]Added code tags.
Top

Posted by Andy.Liu   (22 posts)  Bio
Date Reply #1 on Tue 02 May 2017 07:04 AM (UTC)

Amended on Wed 03 May 2017 04:49 AM (UTC) by Nick Gammon

Message
I find ANSI Colour in Appearance Setting page and make a translation.

If I changed the settings,the code will fail.

Is there a safe way to do this job?

RGB color name vs ANSI color.

Thanks.


function zzHorseNameByColor(colorName)
   if colorName=="maroon" then --41m
    return "chixie ma"  --red horse
   end 
   if colorName=="green" then --42m
    return "lusang ma"  --green horse
   end 
   if colorName=="olive" then --43m
    return "huangbiao ma" --yellow horse
   end 
   if colorName=="navy" then --44m
    return "lanji ma"  --blue horse
   end 
   if colorName=="purple" then --45m
    return "zisui ma"  --purplse horse
   end 
   if colorName=="teal" then --46m
    return "qingzong ma"  --cyan horse
   end 
   if colorName=="silver" then --47m
    return "bai ma"    ---white horse
   end 
   return nil
end
Top

Posted by Fiendish   USA  (2,555 posts)  Bio   Global Moderator
Date Reply #2 on Tue 02 May 2017 09:07 AM (UTC)

Amended on Tue 02 May 2017 09:08 AM (UTC) by Fiendish

Message
Template:codetag To make your code more readable please use [code] tags as described here.

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

Posted by Fiendish   USA  (2,555 posts)  Bio   Global Moderator
Date Reply #3 on Tue 02 May 2017 09:20 AM (UTC)

Amended on Tue 02 May 2017 09:23 AM (UTC) by Fiendish

Message
First, not all colors have names, so you shouldn't ever try to use color names.

Second, you can get the current ANSI color settings using the GetNormalColour and GetBoldColour functions. Like this...

BLACK = 1
RED = 2
GREEN = 3
YELLOW = 4
BLUE = 5
MAGENTA = 6
CYAN = 7
WHITE = 8

red_normal = GetNormalColour(RED)
red_bold = GetBoldColour(RED)

-- etc.

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

Posted by Andy.Liu   (22 posts)  Bio
Date Reply #4 on Wed 03 May 2017 01:30 AM (UTC)
Message
That's what I want.

Thanks a lot.
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.


21,284 views.

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.