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 ➜ reading color from an MSDP variable and printing to a miniwindow

reading color from an MSDP variable and printing to a miniwindow

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


Posted by Ewave   (3 posts)  Bio
Date Sun 01 Feb 2015 03:06 AM (UTC)
Message
Hey all, have a problem. I have a nice miniwindow made, just a basic 200x200 window, I can print a minimap to it via an MSDP variable sent by the mud. However I cannot get the ansi colors to show. I can handle the newlines just fine, but not the colors. Right now I break the map into lines using new lines as a delimiter, which gives me a nice table for the map. Anyone know how I can parse this table and display the colors without using a trigger or OnPluginPacketReceived()? not sure how I can use those with MSDP.
Top

Posted by Nick Gammon   Australia  (23,158 posts)  Bio   Forum Administrator
Date Reply #1 on Sun 01 Feb 2015 09:57 PM (UTC)
Message
Quote:

Right now I break the map into lines using new lines as a delimiter, which gives me a nice table for the map. Anyone know how I can parse this table and display the colors without using a trigger or OnPluginPacketReceived()? not sure how I can use those with MSDP.


Perhaps if you disclose what this table contains we can help you more.

- Nick Gammon

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

Posted by Meerclar   USA  (733 posts)  Bio
Date Reply #2 on Mon 02 Feb 2015 06:54 AM (UTC)
Message
You should be able to simply trigger in the color codes themselves, though that will probably need some OnPacket functionality to be involved for best results. MSDP doesn't directly supply color according to the specs I'm familiar with so there's not going to be a simple check on the msdp info but the color codes should be easy enough to grab and manipulate the map with.


As for doing it without using a trigger or OnPluginPacket, not so sure that's going to be possible (it certainly isn't with my skills) but maybe Nick can work a miracle for you.

Meerclar - Lord of Cats
Coder, Builder, and Tormenter of Mortals
Stormbringer: Rebirth
storm-bringer.org:4500
www.storm-bringer.org
Top

Posted by Ewave   (3 posts)  Bio
Date Reply #3 on Mon 02 Feb 2015 11:56 PM (UTC)

Amended on Tue 03 Feb 2015 05:17 AM (UTC) by Nick Gammon

Message
Thanks for the replies :) Here is the table:


1="`2  `7*`7-`7+`7-`7*  "
2="    `8|    "
3="  `3S`8-`8+`7-`3S  "
4="    `8|    "
5="  `3S`8-`!@`7-`7*`2  "
6="    `8|    "
7="`3S `3S`8-`8+`7-`3S  "
8="`8|   `7|    "
9="`8+`8-`8+`7-`&+`8-`8+`8-`8+`7``"
10=""



As you can see it's just strings with ansi colors in them. Right now I'm printing them to the mini window line by line, which works pretty well. If I could get the style runs from them, I'd be able to do it, but that seems to be an impossible task so far? (EDIT: also the map is spaced properly, but not in this forum post)

[EDIT] Code tags added.
Top

Posted by Meerclar   USA  (733 posts)  Bio
Date Reply #4 on Tue 03 Feb 2015 03:49 AM (UTC)
Message
Put it in a code block to preserve formatting in your post.

Which is the color code in those runs?

Meerclar - Lord of Cats
Coder, Builder, and Tormenter of Mortals
Stormbringer: Rebirth
storm-bringer.org:4500
www.storm-bringer.org
Top

Posted by Ewave   (3 posts)  Bio
Date Reply #5 on Tue 03 Feb 2015 04:09 AM (UTC)
Message
the '1-9 + other symbols. E.G. `! is bold red.
Top

Posted by Nick Gammon   Australia  (23,158 posts)  Bio   Forum Administrator
Date Reply #6 on Tue 03 Feb 2015 05:30 AM (UTC)
Message
Simple enough. Add a default colour to the start of lines (in case they don't start with a colour) and then do a string.gmatch to pull out colour sequences and text. For example:


t = {
[1]="`2  `7*`7-`7+`7-`7*  ",
[2]="    `8|    ",
[3]="  `3S`8-`8+`7-`3S  ",
[4]="    `8|    ",
[5]="  `3S`8-`!@`7-`7*`2  ",
[6]="    `8|    ",
[7]="`3S `3S`8-`8+`7-`3S  ",
[8]="`8|   `7|    ",
[9]="`8+`8-`8+`7-`&+`8-`8+`8-`8+`7``",
[10]="",
}


for _, line in ipairs (t) do
  -- ensure line starts with default colour
  line = '`0' .. line

  for colour, text in string.gmatch (line, "`(%d)([^`]+)") do
    print ("Colour =", colour)
    print ("Text = <" .. text .. ">")
  end -- for each style run

  print ""

end -- for



Results:


Colour = 2
Text = <  >
Colour = 7
Text = <*>
Colour = 7
Text = <->
Colour = 7
Text = <+>
Colour = 7
Text = <->
Colour = 7
Text = <*  >

Colour = 0
Text = <    >
Colour = 8
Text = <|    >

Colour = 0
Text = <  >
Colour = 3
Text = <S>
Colour = 8
Text = <->
Colour = 8
Text = <+>
Colour = 7
Text = <->
Colour = 3
Text = <S  >

Colour = 0
Text = <    >
Colour = 8
Text = <|    >

Colour = 0
Text = <  >
Colour = 3
Text = <S>
Colour = 8
Text = <->
Colour = 7
Text = <->
Colour = 7
Text = <*>
Colour = 2
Text = <  >

Colour = 0
Text = <    >
Colour = 8
Text = <|    >

Colour = 3
Text = <S >
Colour = 3
Text = <S>
Colour = 8
Text = <->
Colour = 8
Text = <+>
Colour = 7
Text = <->
Colour = 3
Text = <S  >

Colour = 8
Text = <|   >
Colour = 7
Text = <|    >

Colour = 8
Text = <+>
Colour = 8
Text = <->
Colour = 8
Text = <+>
Colour = 7
Text = <->
Colour = 8
Text = <->
Colour = 8
Text = <+>
Colour = 8
Text = <->
Colour = 8
Text = <+>


Colour = 2
Text = <  >
Colour = 7
Text = <*>
Colour = 7
Text = <->
Colour = 7
Text = <+>
Colour = 7
Text = <->
Colour = 7
Text = <*  >

Colour = 0
Text = <    >
Colour = 8
Text = <|    >

Colour = 0
Text = <  >
Colour = 3
Text = <S>
Colour = 8
Text = <->
Colour = 8
Text = <+>
Colour = 7
Text = <->
Colour = 3
Text = <S  >

Colour = 0
Text = <    >
Colour = 8
Text = <|    >

Colour = 0
Text = <  >
Colour = 3
Text = <S>
Colour = 8
Text = <->
Colour = 7
Text = <->
Colour = 7
Text = <*>
Colour = 2
Text = <  >

Colour = 0
Text = <    >
Colour = 8
Text = <|    >

Colour = 3
Text = <S >
Colour = 3
Text = <S>
Colour = 8
Text = <->
Colour = 8
Text = <+>
Colour = 7
Text = <->
Colour = 3
Text = <S  >

Colour = 8
Text = <|   >
Colour = 7
Text = <|    >

Colour = 8
Text = <+>
Colour = 8
Text = <->
Colour = 8
Text = <+>
Colour = 7
Text = <->
Colour = 8
Text = <->
Colour = 8
Text = <+>
Colour = 8
Text = <->
Colour = 8
Text = <+>


Now of course you don't "print" the stuff, you do a WindowText with the text and the colour code (some sort of lookup table).

To prove we are extracting the map OK, I'll just print the text and ignore the colour:


for _, line in ipairs (t) do
  -- ensure line starts with default colour
  line = '`0' .. line

  for colour, text in string.gmatch (line, "`(%d)([^`]+)") do
    Tell (text)
  end -- for each style run

  print ""

end -- for


Result:


  *-+-*  
    |    
  S-+-S  
    |    
  S--*  
    |    
S S-+-S  
|   |    
+-+--+-+


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


19,672 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.