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?
Capturing prompt with colours
Posted by Indoum on Fri 26 May 2006 09:30 PM — 4 posts, 19,938 views.
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.
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!
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!
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:
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:
Hope that helps.
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)
end
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
return
end
-- 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)
end
Tell("\n") -- terminate the prompt with a newline
end
Hope that helps.