This is not a feature request. I need help understanding the architecture.
My goal is to add another TConsole::printOnDisplay function that will allow me to pass it a windowName as a second parameter in order to write to Geyser miniconsoles. To better understand the code I added a wrapper function to TLuaInterpreter to allow me to use the cTelnet::postMessage function from lua, but was surprised to find out the ANSI color codes were not processed.
First: What is the flow of data/steps in between cTelnet and the screen output in TConsole?
Making TConsole::printOnDisplay work on miniconsoles
Re: Making TConsole::printOnDisplay work on miniconsoles
You already can write to Geyser miniconsoles, what exacly are you wanting to achieve?
Re: Making TConsole::printOnDisplay work on miniconsoles
I want to take a string from lua with ANSI codes such as "\27[1;31;40mBob chats to you, \27[0m\27[32;40mHello Everyone\n" and write it to a miniconsole with the colors fully translated on screen. The function feedTriggers does what I want using printOnDisplay, but it appears to be hard coded to write only to the main console.
I'm looking to understand the architecture enough that I can write a method in Qt that will process the colors and allow me to direct them to a window (without using trigger hacks).
I'm looking to understand the architecture enough that I can write a method in Qt that will process the colors and allow me to direct them to a window (without using trigger hacks).
Re: Making TConsole::printOnDisplay work on miniconsoles
The better architecture for this is to translate the ANSI codes in Lua and then output wherever you'd like, possibly having extracted data from it, stored somewhere, and so forth. For this reason I'm already writing an ansi2rgb function.
Re: Making TConsole::printOnDisplay work on miniconsoles
I'm already doing that now to an extent. I process the color codes from the ANSI string and convert them into tags I can pass into cecho. It doesn't work well for other text effects such as bold/internsity, underline, blinking because there are no tags available to cecho to process them. Many of these strings I see bold and unbold multiple times in a single line so using setBold() is not practical.
Please be patient with me. I understand the recommendation to do this in the Lua part, however I'm using this as a motivation to get more familiar with the Qt parts, not just to solve the immediate requirment. I want to start making useful contributions to the Qt pieces.
When I look at printOnDisplay I see this call:
buffer.translateToPlainText( incomingSocketData );
In TBuffer::translateToPlainText I see this at the end of the function:
mMudLine.append( ch );
TChar c( ! mIsDefaultColor && mBold ? fgColorLightR : fgColorR,
! mIsDefaultColor && mBold ? fgColorLightG : fgColorG,
! mIsDefaultColor && mBold ? fgColorLightB : fgColorB,
bgColorR,
bgColorG,
bgColorB,
mIsDefaultColor ? mBold : false,
mItalics,
mUnderline );
...
mMudBuffer.push_back( c );
msPos++;
Can I use a structure similar to mMudBuffer and have it draw to a miniconsole instead? How should I do that? What function/methods are already doing somethign similar that I can go look at? I'm still getting familiar with the code.
Please be patient with me. I understand the recommendation to do this in the Lua part, however I'm using this as a motivation to get more familiar with the Qt parts, not just to solve the immediate requirment. I want to start making useful contributions to the Qt pieces.
When I look at printOnDisplay I see this call:
buffer.translateToPlainText( incomingSocketData );
In TBuffer::translateToPlainText I see this at the end of the function:
mMudLine.append( ch );
TChar c( ! mIsDefaultColor && mBold ? fgColorLightR : fgColorR,
! mIsDefaultColor && mBold ? fgColorLightG : fgColorG,
! mIsDefaultColor && mBold ? fgColorLightB : fgColorB,
bgColorR,
bgColorG,
bgColorB,
mIsDefaultColor ? mBold : false,
mItalics,
mUnderline );
...
mMudBuffer.push_back( c );
msPos++;
Can I use a structure similar to mMudBuffer and have it draw to a miniconsole instead? How should I do that? What function/methods are already doing somethign similar that I can go look at? I'm still getting familiar with the code.
- SlySven
- Posts: 1023
- Joined: Mon Mar 04, 2013 3:40 pm
- Location: Deepest Wiltshire, UK
- Discord: SlySven#2703
Re: Making TConsole::printOnDisplay work on miniconsoles
Um, where will that Lua script be stored - we've recently found that the XML file format that is used to store the Triggers/Aliases/Scripts... created in the Editor cannot store literal ASCII control characters such as the ESC 0x1b one (the "\27" above) that someone might be seeking to match - so I think that until we get THAT sorted anything that does need to contain such characters may have to be an external Lua script that is "required" as needed... This is assuming I have got my concepts right and not made an erroneous assumption!Vadim wrote:...The better architecture for this is to translate the ANSI codes in Lua...
cTelnet::postMessage(QString) Is probably NOT what you should be using - I revamped it for the 3.0.1stuff and it actually colours the QString according to a first line starting with a "tag" of the form "[{ OK | WARN | INFO |ALERT|ERROR}] - Some possibly multi-line\nmessage!" with successive lines being left aligned to the first non-space after that hyphen. It is intended for the display of status messages and caches messages it receives until the main TConsole instance for a profile is ready to display them, at which point it dumps out everything it has cached - it also prints out using qDebug() any messages it still has that have not been displayed if it should be destroyed before they have been shown. This is because it can received messages for display during initialisation process BEFORE the completion of instantiation of other Classes that it uses and potentially after the latter have been destroyed. Whilst it will display other messages both with a "[ <tag> ] - " prefixed first line and those without, again I say: it probably ISN'T the method to display something you ought to use.
Re: Making TConsole::printOnDisplay work on miniconsoles
- The strings containing the ASCII control codes are coming from socket connections made to a Mudmaster/Zchat server, so I don't have to worry about storing the raw escape code in the XML.
- I see what you mean about cTelnet::postMessage(QString) being a bad approach. However it did help me find another way to do it by making a public method cTelnet::postData(QString) that does the same thing as the private method cTelnet::postData(). This lets me inject lua string containing ASCII escape codes directly into the main console.
So to get back to the original question, how to I modify/duplicate a method like cTelnet::postMessage(QString) or the cTelnet::postDataQString) I wrote, to publish the output to another window? Is there a good class method I can look at to study and reference?
Re: Making TConsole::printOnDisplay work on miniconsoles
That is how I came across that issue, yes. I've found a workaround however and that works fine.SlySven wrote:Um, where will that Lua script be stored - we've recently found that the XML file format that is used to store the Triggers/Aliases/Scripts... created in the Editor cannot store literal ASCII control characters such as the ESC 0x1b one (the "\27" above) that someone might be seeking to match - so I think that until we get THAT sorted anything that does need to contain such characters may have to be an external Lua script that is "required" as needed... This is assuming I have got my concepts right and not made an erroneous assumption!Vadim wrote:...The better architecture for this is to translate the ANSI codes in Lua...
Re: Making TConsole::printOnDisplay work on miniconsoles
Okay everyone, I got this working in Qt now. Start to finish it exposes a lua function called echoAsci.
For code see https://github.com/Zahatric/Mudlet/tree ... tTelnetLua
Now that I got it working, what steps do I need to go through to get this included in a mudlet release? Do I need to write test classes, restructure the code, etc?
- echoAnsi("\27[0;1;31;40m<REDTEXT>\n\27[0m\n") => displays "<REDTEXT>" colored red on the main console
- echoAnsi("WinName","\27[0;1;31;40m<REDTEXT>\n\27[0m\n") => displays "<REDTEXT>" colored red on the window named "WinName"
For code see https://github.com/Zahatric/Mudlet/tree ... tTelnetLua
Now that I got it working, what steps do I need to go through to get this included in a mudlet release? Do I need to write test classes, restructure the code, etc?
Re: Making TConsole::printOnDisplay work on miniconsoles
Submit a pull request on Github, that'll put it under our consideration