1.1 --- a/java/sql-dk/src/info/globalcode/sql/dk/ColorfulPrintWriter.java Sat Jan 04 15:11:49 2014 +0100
1.2 +++ b/java/sql-dk/src/info/globalcode/sql/dk/ColorfulPrintWriter.java Sat Jan 04 19:38:20 2014 +0100
1.3 @@ -77,6 +77,7 @@
1.4 return code;
1.5 }
1.6 }
1.7 + private final boolean COLOR_ENABLED;
1.8 private boolean colorful = true;
1.9
1.10 public void setStyle(TerminalStyle style) {
1.11 @@ -264,7 +265,7 @@
1.12 }
1.13
1.14 private void printCodes(int... codes) {
1.15 - if (colorful) {
1.16 + if (COLOR_ENABLED && colorful) {
1.17 print("\033[");
1.18 for (int i = 0; i < codes.length; i++) {
1.19 print(codes[i]);
1.20 @@ -276,43 +277,78 @@
1.21 }
1.22 }
1.23
1.24 + /**
1.25 + * Colors can be switched on/off during usage of this writer.
1.26 + *
1.27 + * @return whether colors are currently turned on
1.28 + * @see #isColorEnabled()
1.29 + */
1.30 public boolean isColorful() {
1.31 return colorful;
1.32 }
1.33
1.34 + /**
1.35 + * Collors might be definitively disabled in constructor. If not, they can be turned on/off
1.36 + * during usage of this writer by {@linkplain #setColorful(boolean)}
1.37 + *
1.38 + * @return whether colors are allowed for this instance of this class
1.39 + * @see #isColorful()
1.40 + */
1.41 + public boolean isColorEnabled() {
1.42 + return COLOR_ENABLED;
1.43 + }
1.44 +
1.45 + /**
1.46 + * @see #isColorful()
1.47 + * @see #isColorEnabled()
1.48 + */
1.49 public void setColorful(boolean colorful) {
1.50 this.colorful = colorful;
1.51 }
1.52
1.53 public ColorfulPrintWriter(File file) throws FileNotFoundException {
1.54 super(file);
1.55 + COLOR_ENABLED = true;
1.56 }
1.57
1.58 public ColorfulPrintWriter(OutputStream out) {
1.59 super(out);
1.60 + COLOR_ENABLED = true;
1.61 }
1.62
1.63 public ColorfulPrintWriter(String fileName) throws FileNotFoundException {
1.64 super(fileName);
1.65 + COLOR_ENABLED = true;
1.66 }
1.67
1.68 public ColorfulPrintWriter(Writer out) {
1.69 super(out);
1.70 + COLOR_ENABLED = true;
1.71 }
1.72
1.73 public ColorfulPrintWriter(File file, String csn) throws FileNotFoundException, UnsupportedEncodingException {
1.74 super(file, csn);
1.75 + COLOR_ENABLED = true;
1.76 }
1.77
1.78 - public ColorfulPrintWriter(OutputStream out, boolean autoFlush) {
1.79 + /**
1.80 + * @param colorEnabled colors might be definitively disabled by this option – this might be more
1.81 + * optimalizable than dynamic turning off colors by {@linkplain #setColorful(boolean)} which is
1.82 + * not definitive (colors can be turned on during live of this instance). This might be useful
1.83 + * if you need an instance of this class but don't need colors at all.
1.84 + */
1.85 + public ColorfulPrintWriter(OutputStream out, boolean autoFlush, boolean colorEnabled) {
1.86 super(out, autoFlush);
1.87 + COLOR_ENABLED = colorEnabled;
1.88 }
1.89
1.90 public ColorfulPrintWriter(String fileName, String csn) throws FileNotFoundException, UnsupportedEncodingException {
1.91 super(fileName, csn);
1.92 + COLOR_ENABLED = true;
1.93 }
1.94
1.95 public ColorfulPrintWriter(Writer out, boolean autoFlush) {
1.96 super(out, autoFlush);
1.97 + COLOR_ENABLED = true;
1.98 }
1.99 }