|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectjlibs.core.lang.Ansi
public class Ansi
Ansi coloring support is provided by this class.
To print "hello ansi world" in bold with blue foreground and white background:
Ansi ansi = new Ansi(Ansi.Attribute.BRIGHT, Ansi.Color.BLUE, Ansi.Color.WHITE);
ansi.out("hello ansi world")
same can be done as below:
String msg = ansi.colorize("hello ansi world"); // msg is original string wrapped with ansi control sequences
System.out.println(msg);
Ansi Support:
Ansi might not be supported on all systems. Ansi is mostly supported by all unix operating systems.
SUPPORTED is a final boolean, that can be used to check whether your console supports Ansi format;
Ansi class uses simple checks to decide whether ansi is supported or not. Sometimes it may do wrong guess.
In such cases you can override its decision using following system property:
-DAnsi=true or -DAnsi=false
if SUPPORTED is false, any ansi method will not produce ansi control sequences. so you can safely use:
ansi.out("hello ansi world") irrespective of ansi is supported or not.
if ansi is not supported, this will simply do System.out.print("hello ansi world")
AnsiFormatter| Nested Class Summary | |
|---|---|
static class |
Ansi.Attribute
this enum represents the attribute of text |
static class |
Ansi.Color
this enum represents the color of text |
| Field Summary | |
|---|---|
static boolean |
SUPPORTED
specifies whether ansi is supported or not. |
| Constructor Summary | |
|---|---|
Ansi(Ansi.Attribute attr,
Ansi.Color foreground,
Ansi.Color background)
Creates new instanceof Ansi. |
|
Ansi(String format)
Creates new instanceof of ansi with specified format. |
|
| Method Summary | |
|---|---|
String |
colorize(String message)
Wrapps given message with special ansi control sequences and returns it |
void |
err(String message)
Prints colorized message to System.err |
void |
errFormat(String format,
Object... args)
Prints formatted and colorized format to System.err |
void |
errln(String message)
Prints colorized message to System.err followed by newline |
void |
format(PrintStream ps,
String format,
Object... args)
Prints formatted and colorized message to specified ps. |
void |
out(String message)
Prints colorized message to System.out |
void |
outFormat(String format,
Object... args)
Prints formatted and colorized format to System.out |
void |
outln(String message)
Prints colorized message to System.out followed by newline |
void |
print(PrintStream ps,
String message)
Prints colorized message to specified ps. |
void |
println(PrintStream ps,
String message)
Prints colorized message to specified ps followed by newline. |
String |
toString()
The string representation of this object. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Field Detail |
|---|
public static final boolean SUPPORTED
when this is false, it doesn't colorize given strings, rather than
simply returns the given strings
It tries best effort to guess whether ansi is supported or not. But
you can override this value using system property "Ansi" (-DAnsi=true/false)
| Constructor Detail |
|---|
public Ansi(Ansi.Attribute attr,
Ansi.Color foreground,
Ansi.Color background)
attr - attribute of text, null means don't changeforeground - foreground color of text, null means don't changebackground - background color of text, null means don't changepublic Ansi(String format)
The format syntax is
Attribute[;Foreground[;Background]]i.e, semicolon(;) separated values, where tokens are attribute, foreground and background respectively.
DIM;;GREEN # foreground is not specified
format - | Method Detail |
|---|
public String toString()
Ansi(String)
toString in class Objectpublic String colorize(String message)
message with special ansi control sequences and returns it
public void print(PrintStream ps,
String message)
message to specified ps.
if SUPPORTED is false, it prints raw message to ps
ps - stream to printmessage - message to be colorized
public void println(PrintStream ps,
String message)
message to specified ps followed by newline.
if SUPPORTED is false, it prints raw message to ps followed by newline.
ps - stream to printmessage - message to be colorized
public void format(PrintStream ps,
String format,
Object... args)
message to specified ps.
if SUPPORTED is false, it prints formatted message to ps
ps - stream to printformat - A format string whose output to be colorizedargs - Arguments referenced by the format specifiers in the formatpublic void out(String message)
message to System.out
message - message to be colorizedpublic void outln(String message)
message to System.out followed by newline
message - message to be colorized
public void outFormat(String format,
Object... args)
format to System.out
format - A format string whose output to be colorizedargs - Arguments referenced by the format specifiers in the formatpublic void err(String message)
message to System.err
message - message to be colorizedpublic void errln(String message)
message to System.err followed by newline
message - message to be colorized
public void errFormat(String format,
Object... args)
format to System.err
format - A format string whose output to be colorizedargs - Arguments referenced by the format specifiers in the format
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||