[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]  Capturing prompt with colours
Home  |  Users  |  Search  |  FAQ
Register forum user name
Forgotten password?

Capturing prompt with colours

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

Posted by Indoum   Sweden  (17 posts)  [Biography] bio
Date Fri 26 May 2006 09:30 PM (UTC)
Using OnPluginPartialLine(), I capture the values of my prompt and it's working just fine. Now I'm pondering the posibility to capture the full prompt, with ANSI and all, to echo it out later on. How can I do this?
[Go to top] top

Posted by Ked   Russia  (524 posts)  [Biography] bio
Date Reply #1 on Sat 27 May 2006 02:31 AM (UTC)
With Lua you can use a trigger and the script function it calls will receive a fourth argument, containing all the ANSI styles for the prompt. Or you can use OnPluginPartialLine, which you already use. How to do it really depends on what exactly you want to do with the styles and the prompt.
[Go to top] top

Posted by Indoum   Sweden  (17 posts)  [Biography] bio
Date Reply #2 on Sat 27 May 2006 11:03 AM (UTC)
As I said, I want to capture it to echo out an copy of it later on.

I'd really appreciate it if you could show me some example code on how I could capture the ANSI code from using OnPluginPartialLine() and then print out a copy. Thanks!
[Go to top] top

Posted by Ked   Russia  (524 posts)  [Biography] bio
Date Reply #3 on Sat 27 May 2006 07:46 PM (UTC)

Amended on Sat 27 May 2006 09:27 PM (UTC) by Ked

For simply echoing the prompt "as is", without any modifications, a trigger and a Lua script would probably fit you best. OnPluginPartialLine is useful mainly when you need to know the exact ANSI codes and their positions in the line. Styles, as seen from Lua, just give you a table of "style runs", which correspond to what you would see on the screen, but don't necessarily precisely coincide with what was actually in the recieved packet.

I haven't really used styles that much, so you'd need to experiment with them a bit, but it's simple enough. From what I remember, the table stores pieces of text from the captured line and corresponding styling info for each piece - colour and whether it's bold, italic, underlined. So to echo a prompt, you'd create a trigger to match on it, and make it call a Lua script like:

prompts = {}

function saveTrigger(name, output, wildcs, styles)
    table.insert(prompts, styles)

That will save your prompts, as represented by their styles information, in a global table, with the most recent prompt placed at the end of that table. Later you could display the last prompt, removing it from the table:

function echoLastPrompt()
   prompt = table.remove(prompts)
   -- if prompt is nil then we are out of prompts to
   -- display for now
   if prompt == nil then

   -- iterate over the styles in the prompt
   for chunk,style in prompt do
      local text = style.text
      local fore = RGBColourToName(style.textcolour)
      local back = RGBColourToName(style.backcolour)
      ColourTell(fore, back, text)
   Tell("\n")  -- terminate the prompt with a newline

Hope that helps.
[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.


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.


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]