Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations MikeeOK on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ANSI color codes 2 html color code script

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
I am trying to write a script that replaces all the occurences of ansi color codes
in a variable with their html equivalent hex color codes ( <font colour=#000000> ).

All was working fine, until i realised that not only are the standard colours used, but
from time to time, to make a word or number stand out, the &quot;bold&quot; ansi code is sent.

Example:

You are currently level 82 and are about 95% to level 83.

This line appears as the following:

<font color=#008080>You are currently level <font color=#00FFFF>82<font color=#008080>
and are about <font color=#00FFFF>95<font color=#008080>% to level <font color=#00FFFF>83<font

color=#008080>.

This is the same with all colors available... so in the case of yellow:

You are carrying 323 gold 7 silver coins

<font color=#808000>You are carrying <font color=#FFFF00>323 gold <font color=#FFFFFF> 7 silver
<font color=#808000>coins.

 = dark cyan (#008080)

adding the &quot;bold&quot; ansi code changes the color to bright cyan (#00FFFF)

 = dark yellow (#808000)

adding the &quot;bold&quot; ansi code changes the color to bright yellow (#FFFF00)

the  (or [0;37m) is the &quot;dark white (or gray)&quot; (#C0C0C0) code, but since the &quot;bold&quot; code

was present before hand, it is bold, and therefore comes out as bright white (#FFFFFF).

In this case, the  bold code is used each time, but there are occurences where the bold
code is only used once, and there are multiple color changes until it is disabled (by &quot;[0m&quot;).

SO it may happen that the line will apear like this:

You are carrying 323 gold 7 silver coins

Without the BOLD code after the dark white colour change, and therefore it needs to remember

that the bold code was present, and hasnt been disabled, even though the color has changed.


Since I'm no expert, I'm having great difficulty in even contemplating how this could be done

(or if it is even possible), and any help would be greatly appreciated.

I can be contacted on any of the following, or via this board.

MSN Messenger: shaunchurch@hotmail.com
ICQ#: 24868483


Thanks,

-Shaun
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top