Cecho Problem

Post Reply
Sani
Posts: 15
Joined: Thu Jan 21, 2010 6:35 pm

Cecho Problem

Post by Sani »

I'm trying to overwrite the current prompt with one i'm used to, unfortunately it involves <'s in the actual display. Like so...

H:295 M:136 E:1373 W:882 <eb> <db>

This seems to conflict with mudlets use of them for colours so the ,'s never appear and i get left with...

H:295 M:136 E:1373 W:882 eb db

I've tried the usual escape's but they don't seem to work so would anyone know if its possible?

Iocun
Posts: 174
Joined: Wed Dec 02, 2009 1:45 am

Re: Cecho Problem

Post by Iocun »

I don't think any possibility of escaping those angular brackets was built into the cecho() function. (Which I guess might be a good idea for future versions - unless it already exists and I simply missed it.)

One possibility is to include another redundant color tag -within- the set of < and >:

cecho("<green>H:295 M:136 E:1373 W:882 <<green>eb> <<green>db>")
This will print the whole line in green, as: H:295 M:136 E:1373 W:882 <eb> <db>
The two <green> within the <eb> and <db> serve no other purpose than to "break up" the special meaning of the angular brackets around eb and db.

Not exactly an elegant solution, but it works, as far as I can see.

P.S. instead of actually using a valid color like <green>, you can also put in any other thing anywhere into the original <eb> that has the same syntax as a color tag, e.g.: <eb<foo>> or <e<_>b>
Both of those look weird in the code, but will evaluate to a normal visible <eb>

Sani
Posts: 15
Joined: Thu Jan 21, 2010 6:35 pm

Re: Cecho Problem

Post by Sani »

Thanks for the quick reply, I tried your suggestion but it doesn't seem to work (still doesn't display the <>'s), this is a better explanation i guess of what i'm trying to achieve with the prompt.

Code: Select all

<grey>H:<green>295 <grey>M:<yellow>136 <grey>E:<green>1291 <grey>W:<green>882 <grey><<green>eb<grey>>
...just, no <>'s get displayed whatever I try. :(

EDIT: Got around it though, simple way...

Code: Select all

cecho(stats)
echo(" <")
cecho(extra)
echo(">")
echo(" <")
cecho(extra)
echo(">")

Iocun
Posts: 174
Joined: Wed Dec 02, 2009 1:45 am

Re: Cecho Problem

Post by Iocun »

Weird, that first code box you posted there works just fine for me and displays the <> all right. One possibility is that I still have an older version of cecho() floating around in my system that's overwriting the default one, hrm... I thought I deactivated that, but it may still be lurking somewhere.

What version of Mudlet are you using?


P.S. Uh... wait. Now it suddenly stopped working for myself too and I also get the same problem, with no <> showing up. Very weird.

P.P.S. Oh, found out why it stopped working. While looking around for this old cecho() version in my system I mentioned, I accidentally -activated- it, which caused it to overwrite the default cecho() and made it stop working like before. This means it works fine for me with the default cecho() that comes with Mudlet (v 1.2.0-pre5.1 on OS X), but not with my own old version. But that doesn't explain why it isn't working for you.

P.P.P.S. Ok, I hope that this is the last addendum... Seems it's like this:
Mudlet still actually contains my old cecho() function, but only uses it if your Lua doesn't have a certain regex library installed. Since this "rex" library is installed for me, it executes the new function which works like I described above. It seems like for you, it still executes my old function, since you don't have this library (I guess). You can check this by making an alias execute: display(rex)
If this then displays a table with various functions for you, you have this regex library installed. If it displays nil, you don't and it clearly will execute the old version of cecho().

Yetzederixx
Posts: 186
Joined: Sun Nov 14, 2010 5:57 am

Re: Cecho Problem

Post by Yetzederixx »

Code: [show] | [select all] lua
local prompt = matches[1]

-- swap out those pesky lt/gl symbols with parentheses, or whatever you want 
prompt = string.gsub(prompt, "<", "(")
prompt = string.gsub(prompt, ">", ")")
Then tear apart your prompt with string.sub and insert the color codes as you will

Here is an actual cut and paste from my MUD since my prompt has the gt/lt symbols, note I don't capture the entire prompt:

Code: Select all

(1813/1813)(1109/1109)(456/456) <Above the Altar|SD> <11:00pm|Elvish>
(1813/1813)(1109/1109)(456/456) (Above the Altar|SD) (11:00pm|

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

Re: Cecho Problem

Post by Denarii »

Cecho does in fact have escaping using \, however \ is also an escape character in Lua. So if you're using a string in single or double quotes you'll need to use two.

Ex.
Code: [show] | [select all] lua
cecho("\\<green>test")
cecho('\\<green>test')
cecho([[\<green>test]])

Yetzederixx
Posts: 186
Joined: Sun Nov 14, 2010 5:57 am

Re: Cecho Problem

Post by Yetzederixx »

Code: [show] | [select all] lua
cecho("\<CornflowerBlue>test")
cecho('\<light_gray>test')
cecho([[<DarkSlateBlue>test]])
That will actually get your colors, and will be much easier to color your prompt than starting with the entire thing as a string from matches[1], breaking it apart again, adding the color codes, and then displaying it since you'll be able to use matches[2-n] and prefix them with the codes instead. Take note that if you change the background color from the default you will have to reset it.
Code: [show] | [select all] lua
cecho("this is a <yellow:green>test pattern to <blue>demonstrate the <white:black>necessity of changing the background color back")

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

Re: Cecho Problem

Post by Denarii »

The original question wasn't about coloring the prompt, it was about cecho eating angle brackets. (I've also just committed a fix to this to LuaGlobal. In the next Mudlet release, cecho will ignore anything in angle brackets if it's not in the color table. If it is in the color table and you want it to be printed out rather than colored, you can escape with backslash.)

Yetzederixx
Posts: 186
Joined: Sun Nov 14, 2010 5:57 am

Re: Cecho Problem

Post by Yetzederixx »

Yep, you're absolutely right. This example will cecho in color and and show how to get the gl/lt data in there also:
Code: [show] | [select all] lua
cecho("\<CornflowerBlue>test \\<adf> \n")
cecho('\<light_gray>test \\<adf> \n')
cecho([[<DarkSlateBlue>test \<adf>]])

Post Reply