--- a/java/sql-dk/src/info/globalcode/sql/dk/ColorfulPrintWriter.java Sat Jan 04 15:11:49 2014 +0100
+++ b/java/sql-dk/src/info/globalcode/sql/dk/ColorfulPrintWriter.java Sat Jan 04 19:38:20 2014 +0100
@@ -77,6 +77,7 @@
return code;
}
}
+ private final boolean COLOR_ENABLED;
private boolean colorful = true;
public void setStyle(TerminalStyle style) {
@@ -264,7 +265,7 @@
}
private void printCodes(int... codes) {
- if (colorful) {
+ if (COLOR_ENABLED && colorful) {
print("\033[");
for (int i = 0; i < codes.length; i++) {
print(codes[i]);
@@ -276,43 +277,78 @@
}
}
+ /**
+ * Colors can be switched on/off during usage of this writer.
+ *
+ * @return whether colors are currently turned on
+ * @see #isColorEnabled()
+ */
public boolean isColorful() {
return colorful;
}
+ /**
+ * Collors might be definitively disabled in constructor. If not, they can be turned on/off
+ * during usage of this writer by {@linkplain #setColorful(boolean)}
+ *
+ * @return whether colors are allowed for this instance of this class
+ * @see #isColorful()
+ */
+ public boolean isColorEnabled() {
+ return COLOR_ENABLED;
+ }
+
+ /**
+ * @see #isColorful()
+ * @see #isColorEnabled()
+ */
public void setColorful(boolean colorful) {
this.colorful = colorful;
}
public ColorfulPrintWriter(File file) throws FileNotFoundException {
super(file);
+ COLOR_ENABLED = true;
}
public ColorfulPrintWriter(OutputStream out) {
super(out);
+ COLOR_ENABLED = true;
}
public ColorfulPrintWriter(String fileName) throws FileNotFoundException {
super(fileName);
+ COLOR_ENABLED = true;
}
public ColorfulPrintWriter(Writer out) {
super(out);
+ COLOR_ENABLED = true;
}
public ColorfulPrintWriter(File file, String csn) throws FileNotFoundException, UnsupportedEncodingException {
super(file, csn);
+ COLOR_ENABLED = true;
}
- public ColorfulPrintWriter(OutputStream out, boolean autoFlush) {
+ /**
+ * @param colorEnabled colors might be definitively disabled by this option – this might be more
+ * optimalizable than dynamic turning off colors by {@linkplain #setColorful(boolean)} which is
+ * not definitive (colors can be turned on during live of this instance). This might be useful
+ * if you need an instance of this class but don't need colors at all.
+ */
+ public ColorfulPrintWriter(OutputStream out, boolean autoFlush, boolean colorEnabled) {
super(out, autoFlush);
+ COLOR_ENABLED = colorEnabled;
}
public ColorfulPrintWriter(String fileName, String csn) throws FileNotFoundException, UnsupportedEncodingException {
super(fileName, csn);
+ COLOR_ENABLED = true;
}
public ColorfulPrintWriter(Writer out, boolean autoFlush) {
super(out, autoFlush);
+ COLOR_ENABLED = true;
}
}