Migrated common build to 1.10 (from 1.3).

This commit is contained in:
Jonathan Bernard
2013-08-27 19:03:27 -05:00
parent c3dfb014a2
commit 49b7524eb7
5 changed files with 76 additions and 15 deletions

View File

@ -0,0 +1,70 @@
/**
* # ConsoleColor
* @author Jonathan Bernard (jdbernard@gmail.com)
* @org jdbernard.com/twitter/ConsoleColor
* @copyright 2010-2012 Jonathan Bernard
*/
package com.jdbernard.twitter;
/**
* The ConsoleColor class is a wrapper around [ANSI escape codes].
*
* [ANSI escape codes]: http://en.wikipedia.org/wiki/ANSI_escape_code
*/
public class ConsoleColor {
// Storage for color information.
public final Colors fg;
public final Colors bg;
public final boolean bright;
public static enum Colors {
BLACK, RED, GREEN, YELLOW, BLUE, MAGENTA, CYAN, WHITE }
public ConsoleColor(String propString) {
String[] vals = propString.split("[,;: ]");
fg = Colors.valueOf(vals[0]);
if (vals.length == 2) {
bg = null;
bright = Boolean.parseBoolean(vals[1]);
} else if (vals.length == 3) {
bg = Colors.valueOf(vals[1]);
bright = Boolean.parseBoolean(vals[2]);
} else { bg = null; bright = false; }
}
public ConsoleColor(Colors fgColor) { this(fgColor, Colors.BLACK, false); }
public ConsoleColor(Colors fgColor, boolean bright) {
this(fgColor, Colors.BLACK, bright);
}
public ConsoleColor(Colors fgColor, Colors bgColor, boolean bright) {
this.fg = fgColor; this.bg = bgColor; this.bright = bright;
}
public String toString() {
String result = "\u001b[";
boolean needSemi = false;
if (bright) {
result += "1";
needSemi = true;
}
if (fg != null) {
if (needSemi) result += ";";
result += "3" + Integer.toString(fg.ordinal());
needSemi = true;
}
if (bg != null) {
if (needSemi) result += ";";
result += "4" + Integer.toString(bg.ordinal());
}
return result + "m";
}
}

File diff suppressed because it is too large Load Diff