Echo with color.

Share your scripts and packages with other Mudlet users.
hempa
Posts: 48
Joined: Sat Jan 02, 2010 1:07 pm

Re: Echo with color.

Post by hempa »

Right, just changing it to be suffix instead of echo will print everything in the opposite order, same with prefix. It would really be nice if the echoing (prefix, echo, suffix, insertText) would all support this notation.

I did find a bug, however. If I have a > or a < in the text, the function will filter it out and not print it. I tried escaping it in different ways, but that wouldn't work. Suggestions?

Denarii
Posts: 111
Joined: Thu Dec 03, 2009 10:54 pm

Re: Echo with color.

Post by Denarii »

I added escaping with \ to the lrexlib versions. It'll be available in the next release. Note that you'll need to do either cecho("\\<red>") or cecho([[\<red>]]) as \ is an escape character in Lua as well.

Iocun, I have modified versions of your native Lua functions included as fallbacks if lrexlib isn't found, if you want to modify them so they can be escaped, I'll include that.

hempa
Posts: 48
Joined: Sat Jan 02, 2010 1:07 pm

Re: Echo with color.

Post by hempa »

Thank you for your hard work, looking forward to next release! :)

As for prefixing using moveCursor and insertText, whenever I use that on a string like this:

Code: Select all

"<red>[<green>Some Text<red>]" 
it will show up like this when output to the game (using moveCursor to the start of the line first):
]SomeText[

It seems like insertText does not move the cursor but rather keeps it at the position mentioned. I suppose I could move the cursor forward as I'm adding text, unless there is another way.. Suggestions?

Denarii
Posts: 111
Joined: Thu Dec 03, 2009 10:54 pm

Re: Echo with color.

Post by Denarii »

If I understand your problem correctly, try:

Code: Select all

moveCursor("main", 0, getLineCount()-1)
cecho("<red>[<green>Text<red>]", nil, nil, true)
moveCursorEnd("main")

hempa
Posts: 48
Joined: Sat Jan 02, 2010 1:07 pm

Re: Echo with color.

Post by hempa »

Ok, going to give this a try and see if it works when I get back from work today. It should work fine to just overwrite the prefix function into something like this:

Code: Select all

function prefix(what, color)
   if color == true then
      moveCursor("main", 0, getLineCount()-1)
      cecho("<red>[<green>Text<red>]", nil, nil, true)
      moveCursorEnd("main")
   else
      moveCursor("main",0,getLineNumber());
      insertText(what)
   end
end
Thanks for all help :)

Denarii
Posts: 111
Joined: Thu Dec 03, 2009 10:54 pm

Re: Echo with color.

Post by Denarii »

Oh, nevermind.

Prefix just moves the cursor to the beginning of the current line it's on, by default the last line received, and inserts the text there. If you want to return the cursor to its normal position afterwards, use moveCursorEnd. I'll look into making it possible to use color with prefix and suffix. Until then you can emulate the behavior with: moveCursor("main",0,getLineNumber()); cecho("whatever", nil, nil, true)

Setting the fourth argument of cecho to true makes it use inserttext instead of echo.

hempa
Posts: 48
Joined: Sat Jan 02, 2010 1:07 pm

Re: Echo with color.

Post by hempa »

Found another little bug for you to look at. Look at this:
|c00FF00Target: |cFF0000Bandit
It should output Target: Bandit
but it actually outputs: Target: ndit

In your rex split about halfway through the function, you do ",?" to check if there is a comma, but in theory that only checks if the comma is there, but keeps processing if there's more text after it. It would mean one could write |cff000000ff00 to make red text on green background.

It can be fixed by adding a space after the color group, but you're not always able to do that. Can we get a terminating character for the clause or so?

Also, I'd really like to see the possibility to use <color name> in there somehow just like in the function listed earlier in this thread? It really does look better having "<yellow>Target: <red>Bandit" instead of all the hex code :P Perhaps a flag to cecho to use color names or hex?

Denarii
Posts: 111
Joined: Thu Dec 03, 2009 10:54 pm

Re: Echo with color.

Post by Denarii »

The problem in the hex function should already be fixed in my local copy. A lot has changed since the last release.

We're splitting it into three separate functions, cecho, hecho and decho. cecho uses <color>, hecho uses |cXXXXXX, and decho uses <nnn,nnn,nnn>

hempa
Posts: 48
Joined: Sat Jan 02, 2010 1:07 pm

Re: Echo with color.

Post by hempa »

Ahhhh, I see. Any plan on when your local version is going to be released?

Denarii
Posts: 111
Joined: Thu Dec 03, 2009 10:54 pm

Re: Echo with color.

Post by Denarii »

Whenever the next Mudlet release is, I'd have to ask Heiko.

Post Reply