This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
Bandus's profile picture

[QUESTION][LUA] Colored text within a line of white text

Started by Bandus, 05 April 2013 - 06:11 PM
Bandus #1
Posted 05 April 2013 - 08:11 PM
So, at first glance I thought this was something that would be easy for me to do, however, I am either over complicating it or it is deceptively difficult.

I am attempting to have part of a string print in plain white text, and another part in color. For example:

print("Steam output levels: [OPTIMAL]")

I'd like the "Steam output levels" part to be plain white text while the "[OPTIMAL]" part to be in green.
How would one accomplish this? Thank you!
Engineer #2
Posted 05 April 2013 - 08:45 PM
Its very easy to do:

term.setTextColor(colors.green)
write("Steam output levels: ")
term.setTextColor(colors.red)
write(varName)
Mads #3
Posted 05 April 2013 - 09:42 PM
Or you could use this function http://www.computercraft.info/forums2/index.php?/topic/11771-print-coloured-text-easily/

And print stuff like "&7Hello, &aWorld!"
Kingdaro #4
Posted 06 April 2013 - 02:04 AM
Or you could use this function http://www.computercraft.info/forums2/index.php?/topic/11771-print-coloured-text-easily/

And print stuff like "&7Hello, &aWorld!"

Eh, I'd only resort to using an external library if I would actually save time and characters, also while solution isn't as easy as:

term.setTextColor(colors.green)
write("Steam output levels: ")
term.setTextColor(colors.red)
write(varName)