Page 1 of 1

formatting the text of a label

Posted: Wed Oct 23, 2013 10:20 pm
by branden7
Making a lot of progress thanks to how helpful everyone is here...
Still a few questions, though.

Can anyone suggest a way to color the text of a label.
I tried using cecho() but it doesnt seem to let me do that in a label.

I have a label box that displays the name and condition of my target. It would be nice to just directly copy over the colors from the MUD, but failing that I can color them myself.

Note that cecho doesnt throw any sort of error, it just makes the label not display anything.

here's what I am looking at:
Code: [show] | [select all] lua
GUI.Box2:echo("You are Fighting: " .. target .. "<br> Condition:<br>" .. condition);
and the box looks like this:
Code: [show] | [select all] lua
GUI.Box2 = Geyser.Label:new({
  name = "GUI.Box2",
  x = 0, y = "50%",
  width = "50%",
  height = "50%",
Should I just be using a miniConsole?
this is probably just an issue of me not really knowing lua....if anyone has a reference to formatting that would be great.

Re: formatting the text of a label

Posted: Thu Oct 24, 2013 6:15 pm
by fetaera
Miniconsoles are certainly faster, but there's no reason not to use a label. My UI uses them exclusively with no problem.

In answer to your question, though, colours are passed differently in this instance. Take the following snippet as an example:
Code: [show] | [select all] lua
local out = [[<p align="center" style="font-size: 11px; font-family: ']] .. ccc.ui_font .. [['">]] .. "<span style=\"color:OrangeRed\">" .. table.concat(todisplay, "<br \>") .. [[</span></p><br>]]

Hope that helps.

Re: formatting the text of a label

Posted: Thu Oct 24, 2013 6:29 pm
by branden7
Yeah it was that [[ ]] syntax that I was missing. I think that will help greatly.


Re: formatting the text of a label

Posted: Thu Oct 24, 2013 6:49 pm
by branden7
Yep...that thing helps and my labels now work better than the MiniConsole boxes I was trying to use.

Re: formatting the text of a label

Posted: Mon Mar 07, 2016 4:42 am
by Nyyrazzilyss
Bringing back a very old thread, however:

I've been using cecho with a miniconsole window. I couldn't find a way to set callbacks for enter/exit/etc on miniconsoles, so i'm having to change it to a label. The text I was sending out with cecho though isn't css formatted, it was more stuff like <green>some text<red>999\n<green>more text<blue>0\n etc etc. This means switching from using a miniconsole to a label for that window has also cost me all my colouring/formatting.

Was there an easy function to reformat from cecho to echo, since cecho doesn't work with labels? Or even better, an easy way to add cecho to labels?


I wrote a quick function to switch from cecho format to echo. It works for me, though it's more then likely restricted as to how well it works/what it's checking for. Is there a prexisting function to do this?

Code: [show] | [select all] lua
function parseLine(xline)
	local fontsize = 14
	local retval=""

	for k,v in pairs( string.split(xline, "<") ) do
		if v ~= "" then
			local tmp = 	string.split(v, ">")
			retval = retval .. [[<span style="color:]] .. tmp[1] .. [[">]] .. 
				 string.gsub(tmp[2], " ", "&nbsp;")
				 .. [[</span>]]

	retval = [[<p style="font-size:]] .. fontsize .. [[px;font-style:normal;font-family: 'Bitstream Vera Sans Mono'">]] .. retval .. [[</font></p>]]
	retval = string.gsub(retval, "\n", "<br>")