[Home] [Downloads] [Search] [Help/forum]

Gammon Forum

See www.mushclient.com/spam for dealing with forum spam. Please read the MUSHclient FAQ!

[Folder]  Entire forum
-> [Folder]  MUSHclient
. -> [Folder]  General
. . -> [Subject]  reading color from an MSDP variable and printing to a miniwindow
Home  |  Users  |  Search  |  FAQ
Username:
Register forum user name
Password:
Forgotten password?

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] Refresh page


Posted by Ewave   (3 posts)  [Biography] 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.
[Go to top] top

Posted by Nick Gammon   Australia  (21,322 posts)  [Biography] 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
[Go to top] top

Posted by Meerclar   USA  (733 posts)  [Biography] 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
[Go to top] top

Posted by Ewave   (3 posts)  [Biography] 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.
[Go to top] top

Posted by Meerclar   USA  (733 posts)  [Biography] 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
[Go to top] top

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

Posted by Nick Gammon   Australia  (21,322 posts)  [Biography] 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
[Go to top] 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.


3,984 views.

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

Go to topic:           Search the forum


[Go to top] top

Quick links: MUSHclient. MUSHclient help. Forum shortcuts. Posting templates. Lua modules. Lua documentation.

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

[Home]


Written by Nick Gammon - 5K   profile for Nick Gammon on Stack Exchange, a network of free, community-driven Q&A sites   Marriage equality

Comments to: Gammon Software support
[RH click to get RSS URL] Forum RSS feed ( https://gammon.com.au/rss/forum.xml )

[Best viewed with any browser - 2K]    [Hosted at FutureQuest]