eapms
Class ColorFormatter

java.lang.Object
  |
  +--eapms.ANSIFormat
        |
        +--eapms.ColorFormatter

public class ColorFormatter
extends ANSIFormat

Class to format text in pretty colors


Nested Class Summary
 
Nested classes inherited from class eapms.ANSIFormat
ANSIFormat.Attrs, ANSIFormat.BGColors, ANSIFormat.FGColors
 
Field Summary
 
Fields inherited from class eapms.ANSIFormat
CHAR_CLASS, DEFAULT_FLAGS, DEFAULT_INDEX, DEFAULT_REGEX, mFlags, mFlagsSet, mPattern, mRegex, mRepndx, PLACEHOLDER, UNICODE_ESCAPE
 
Constructor Summary
ColorFormatter()
           
 
Method Summary
 void compilePattern(java.lang.String regex, int repndx, int flags)
          Compiles the regex supplied with the supplied flags.
 java.lang.String stringReplace(java.lang.String str)
          There is a special format for the strings passed to this method: they use single character codes captured in the repndxth capturing group.
 
Methods inherited from class eapms.ANSIFormat
compilePattern, compilePattern, compilePattern, getFlags, getPattern, getRegex
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ColorFormatter

public ColorFormatter()
Method Detail

compilePattern

public void compilePattern(java.lang.String regex,
                           int repndx,
                           int flags)
                    throws java.lang.IllegalArgumentException,
                           java.util.regex.PatternSyntaxException
Description copied from class: ANSIFormat
Compiles the regex supplied with the supplied flags. The string passed to this method as the regex must be in a certain form. As there is a specific character class that must be used in the matching, a placeholder is used in the regex string. You must therefore pass a regex string with this placeholder, such as

\<("+ANSIFormat.PLACEHOLDER+"*?)\>([^<]*)

The placeholder is the string "%%%", so the above would be:

\<(%%%*?)\>([^<]*)"

which will then be replaced with the character class to become

\<([brnglmcw~+-_*;?!]*?)\>([^<]*)"

Also, you'll need to pass a repndx integer as the second argument - this value tells the stringReplace method which capturing group to look in to find where the actual color codes are held (otherwise it won't know which part is color codes and which is text).

Simple, isn't it

Specified by:
compilePattern in class ANSIFormat
Throws:
java.util.regex.PatternSyntaxException - Wrong syntax, retard.
java.lang.IllegalArgumentException - The repndx value must be greater than zero - can also be thrown from something in the regex class, but I don't know why...go look it up, idiot.

stringReplace

public java.lang.String stringReplace(java.lang.String str)
There is a special format for the strings passed to this method: they use single character codes captured in the repndxth capturing group. Here are the codes:

l: Black
r: Red
g: Green
b: Blue
m: Magenta
c: Cyan
w: White

n: Reset to normal
+: Bright colors
-: Dim colors
_: Underline
*: Blink (not usually supported)
#: Reverse
~: Hidden

!: Color(s) that follow are FOREGROUND color(s).
?: Color(s) that follow are BACKGROUND colors

Click here for detailed usage information

Click here for current tag usage info.

Specified by:
stringReplace in class ANSIFormat