Page 1 of 1

Appending a line with some of the text coloured.

Posted: 14 Aug 2019 05:36
by Callimachus
I'm tryin to append a line to my screen output, with specific colour for a portion of it. Unfortunately, my simple brain can't seem to get it to work.

A silly example to show the sort of thing I'm trying to do:
If I inventory my backpack, I might get a few lines like:

32 copper coins
83 silver coins

So, say I want to add a line to the output after the silver coins lines such as:

32 copper coins
83 silver coins
need gold coins -- get some

Adding the extra line is easy enough. The problem I'm having is I would like to colour one or more words in that extra line, but not the entire line. So, output 'gold coins' in yellow, leaving the rest in the default colour. I don't want to use gwc.output.replace because I'm not replacing anything. I'm using gwc.output.append, but I can't seem to get colour inserted in there without the actual code I'm trying printing out as well.

I realize this is probably a simple thing, but I hope someone can help me out anyway.

Re: Appending a line with some of the text coloured.

Posted: 03 Feb 2021 16:15
by Kjartan
Hey,

you actually want to replace something.
To have words coloured, you surround them with a span tag.
Like:

Code: Select all

<span style="color: YOUR COLOUR">HERE GOES WHATEVER IS TO BE COLOURED</span>
Yes, you could go, and just insert something before and after to achieve this, but the easiest way to achieve the same is, to replace them with

Code: Select all

<span style="color: YOUR COLOUR">THE WORD(S) YOU REPLACE IN ORDER TO BE COLOURED</span>
So, replacing is the easiest way to go, even though you just replace them with themselves and a bit before and after.