java/sql-dk/src/main/java/info/globalcode/sql/dk/ColorfulPrintWriter.java
author František Kučera <franta-hg@frantovo.cz>
Thu, 24 Oct 2019 21:43:08 +0200
branchv_0
changeset 250 aae5009bd0af
parent 238 4a1864c3e867
permissions -rw-r--r--
fix license version: GNU GPLv3
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
31
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     1
/**
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     2
 * SQL-DK
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     3
 * Copyright © 2013 František Kučera (frantovo.cz)
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     4
 *
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     5
 * This program is free software: you can redistribute it and/or modify
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     6
 * it under the terms of the GNU General Public License as published by
250
aae5009bd0af fix license version: GNU GPLv3
František Kučera <franta-hg@frantovo.cz>
parents: 238
diff changeset
     7
 * the Free Software Foundation, version 3 of the License.
31
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     8
 *
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     9
 * This program is distributed in the hope that it will be useful,
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    12
 * GNU General Public License for more details.
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    13
 *
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    14
 * You should have received a copy of the GNU General Public License
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    15
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    16
 */
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    17
package info.globalcode.sql.dk;
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    18
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    19
import java.io.File;
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    20
import java.io.FileNotFoundException;
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    21
import java.io.OutputStream;
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    22
import java.io.PrintWriter;
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    23
import java.io.UnsupportedEncodingException;
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    24
import java.io.Writer;
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    25
import java.util.EnumSet;
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    26
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    27
/**
155
eb3676c6929b more JavaDoc
František Kučera <franta-hg@frantovo.cz>
parents: 126
diff changeset
    28
 * PrintWriter with convenience methods for printing color and formatted text.
eb3676c6929b more JavaDoc
František Kučera <franta-hg@frantovo.cz>
parents: 126
diff changeset
    29
 *
eb3676c6929b more JavaDoc
František Kučera <franta-hg@frantovo.cz>
parents: 126
diff changeset
    30
 * Uses ANSI Escape Sequences.
eb3676c6929b more JavaDoc
František Kučera <franta-hg@frantovo.cz>
parents: 126
diff changeset
    31
 * See: http://www.tldp.org/HOWTO/Bash-Prompt-HOWTO/x329.html
31
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    32
 *
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    33
 * @author Ing. František Kučera (frantovo.cz)
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    34
 */
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    35
public class ColorfulPrintWriter extends PrintWriter {
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    36
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    37
	public enum TerminalColor {
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    38
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    39
		Black(30, 40),
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    40
		Red(31, 41),
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    41
		Green(32, 42),
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    42
		Yellow(33, 43),
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    43
		Blue(34, 44),
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    44
		Magenta(35, 45),
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    45
		Cyan(36, 46),
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    46
		White(37, 47);
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    47
		private final int foregroundCode;
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    48
		private final int backgroundCode;
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    49
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    50
		private TerminalColor(int foregroundCode, int backgroundCode) {
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    51
			this.foregroundCode = foregroundCode;
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    52
			this.backgroundCode = backgroundCode;
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    53
		}
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    54
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    55
		public int getForegroundCode() {
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    56
			return foregroundCode;
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    57
		}
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    58
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    59
		public int getBackgroundCode() {
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    60
			return backgroundCode;
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    61
		}
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    62
	}
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    63
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    64
	public enum TerminalStyle {
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    65
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    66
		Reset(0),
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    67
		Bright(1),
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    68
		Dim(2),
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    69
		Underscore(4),
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    70
		Blink(5),
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    71
		Reverse(7),
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    72
		Hidden(8);
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    73
		private int code;
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    74
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    75
		private TerminalStyle(int code) {
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    76
			this.code = code;
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    77
		}
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    78
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    79
		public int getCode() {
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    80
			return code;
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    81
		}
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    82
	}
126
2357a9d08660 Colors can be definitively turned off in constructor
František Kučera <franta-hg@frantovo.cz>
parents: 59
diff changeset
    83
	private final boolean COLOR_ENABLED;
31
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    84
	private boolean colorful = true;
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    85
59
5f745ae795a8 logging: print stacktraces if level is less than INFO
František Kučera <franta-hg@frantovo.cz>
parents: 55
diff changeset
    86
	public void setStyle(TerminalStyle style) {
5f745ae795a8 logging: print stacktraces if level is less than INFO
František Kučera <franta-hg@frantovo.cz>
parents: 55
diff changeset
    87
		setStyle(EnumSet.of(style));
5f745ae795a8 logging: print stacktraces if level is less than INFO
František Kučera <franta-hg@frantovo.cz>
parents: 55
diff changeset
    88
	}
5f745ae795a8 logging: print stacktraces if level is less than INFO
František Kučera <franta-hg@frantovo.cz>
parents: 55
diff changeset
    89
31
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    90
	public void setStyle(EnumSet<TerminalStyle> styles) {
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    91
		printCodes(getStyleCodes(styles));
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    92
	}
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    93
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    94
	private static int[] getStyleCodes(EnumSet<TerminalStyle> styles) {
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    95
		int[] array = new int[styles.size()];
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    96
		int i = 0;
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    97
		for (TerminalStyle s : styles) {
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    98
			array[i++] = s.getCode();
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    99
		}
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   100
		return array;
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   101
	}
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   102
40
a9db7fb3ce65 TabularFormatter: print colorful tables\!
František Kučera <franta-hg@frantovo.cz>
parents: 37
diff changeset
   103
	/**
a9db7fb3ce65 TabularFormatter: print colorful tables\!
František Kučera <franta-hg@frantovo.cz>
parents: 37
diff changeset
   104
	 * Print (usually audible) bell code (\007, \a, ^G)
a9db7fb3ce65 TabularFormatter: print colorful tables\!
František Kučera <franta-hg@frantovo.cz>
parents: 37
diff changeset
   105
	 */
a9db7fb3ce65 TabularFormatter: print colorful tables\!
František Kučera <franta-hg@frantovo.cz>
parents: 37
diff changeset
   106
	public void bell() {
a9db7fb3ce65 TabularFormatter: print colorful tables\!
František Kučera <franta-hg@frantovo.cz>
parents: 37
diff changeset
   107
		print("\007");
a9db7fb3ce65 TabularFormatter: print colorful tables\!
František Kučera <franta-hg@frantovo.cz>
parents: 37
diff changeset
   108
	}
a9db7fb3ce65 TabularFormatter: print colorful tables\!
František Kučera <franta-hg@frantovo.cz>
parents: 37
diff changeset
   109
a9db7fb3ce65 TabularFormatter: print colorful tables\!
František Kučera <franta-hg@frantovo.cz>
parents: 37
diff changeset
   110
	/**
a9db7fb3ce65 TabularFormatter: print colorful tables\!
František Kučera <franta-hg@frantovo.cz>
parents: 37
diff changeset
   111
	 * Eat the last character
a9db7fb3ce65 TabularFormatter: print colorful tables\!
František Kučera <franta-hg@frantovo.cz>
parents: 37
diff changeset
   112
	 */
a9db7fb3ce65 TabularFormatter: print colorful tables\!
František Kučera <franta-hg@frantovo.cz>
parents: 37
diff changeset
   113
	public void backspace() {
a9db7fb3ce65 TabularFormatter: print colorful tables\!
František Kučera <franta-hg@frantovo.cz>
parents: 37
diff changeset
   114
		print("\b");
a9db7fb3ce65 TabularFormatter: print colorful tables\!
František Kučera <franta-hg@frantovo.cz>
parents: 37
diff changeset
   115
	}
a9db7fb3ce65 TabularFormatter: print colorful tables\!
František Kučera <franta-hg@frantovo.cz>
parents: 37
diff changeset
   116
a9db7fb3ce65 TabularFormatter: print colorful tables\!
František Kučera <franta-hg@frantovo.cz>
parents: 37
diff changeset
   117
	/**
a9db7fb3ce65 TabularFormatter: print colorful tables\!
František Kučera <franta-hg@frantovo.cz>
parents: 37
diff changeset
   118
	 * Eat n last characters
a9db7fb3ce65 TabularFormatter: print colorful tables\!
František Kučera <franta-hg@frantovo.cz>
parents: 37
diff changeset
   119
	 *
a9db7fb3ce65 TabularFormatter: print colorful tables\!
František Kučera <franta-hg@frantovo.cz>
parents: 37
diff changeset
   120
	 * @param count n
a9db7fb3ce65 TabularFormatter: print colorful tables\!
František Kučera <franta-hg@frantovo.cz>
parents: 37
diff changeset
   121
	 */
a9db7fb3ce65 TabularFormatter: print colorful tables\!
František Kučera <franta-hg@frantovo.cz>
parents: 37
diff changeset
   122
	public void backspace(int count) {
a9db7fb3ce65 TabularFormatter: print colorful tables\!
František Kučera <franta-hg@frantovo.cz>
parents: 37
diff changeset
   123
		for (int i = 0; i < count; i++) {
a9db7fb3ce65 TabularFormatter: print colorful tables\!
František Kučera <franta-hg@frantovo.cz>
parents: 37
diff changeset
   124
			backspace();
a9db7fb3ce65 TabularFormatter: print colorful tables\!
František Kučera <franta-hg@frantovo.cz>
parents: 37
diff changeset
   125
		}
a9db7fb3ce65 TabularFormatter: print colorful tables\!
František Kučera <franta-hg@frantovo.cz>
parents: 37
diff changeset
   126
	}
a9db7fb3ce65 TabularFormatter: print colorful tables\!
František Kučera <franta-hg@frantovo.cz>
parents: 37
diff changeset
   127
a9db7fb3ce65 TabularFormatter: print colorful tables\!
František Kučera <franta-hg@frantovo.cz>
parents: 37
diff changeset
   128
	/**
a9db7fb3ce65 TabularFormatter: print colorful tables\!
František Kučera <franta-hg@frantovo.cz>
parents: 37
diff changeset
   129
	 * With 100 ms delay and all colors.
a9db7fb3ce65 TabularFormatter: print colorful tables\!
František Kučera <franta-hg@frantovo.cz>
parents: 37
diff changeset
   130
	 *
a9db7fb3ce65 TabularFormatter: print colorful tables\!
František Kučera <franta-hg@frantovo.cz>
parents: 37
diff changeset
   131
	 * @see #printRainbow(java.lang.String, int,
a9db7fb3ce65 TabularFormatter: print colorful tables\!
František Kučera <franta-hg@frantovo.cz>
parents: 37
diff changeset
   132
	 * info.globalcode.sql.dk.ColorfulPrintWriter.TerminalColor[])
a9db7fb3ce65 TabularFormatter: print colorful tables\!
František Kučera <franta-hg@frantovo.cz>
parents: 37
diff changeset
   133
	 */
a9db7fb3ce65 TabularFormatter: print colorful tables\!
František Kučera <franta-hg@frantovo.cz>
parents: 37
diff changeset
   134
	public void printRainbow(String string) {
a9db7fb3ce65 TabularFormatter: print colorful tables\!
František Kučera <franta-hg@frantovo.cz>
parents: 37
diff changeset
   135
		printRainbow(string, 100);
a9db7fb3ce65 TabularFormatter: print colorful tables\!
František Kučera <franta-hg@frantovo.cz>
parents: 37
diff changeset
   136
	}
a9db7fb3ce65 TabularFormatter: print colorful tables\!
František Kučera <franta-hg@frantovo.cz>
parents: 37
diff changeset
   137
a9db7fb3ce65 TabularFormatter: print colorful tables\!
František Kučera <franta-hg@frantovo.cz>
parents: 37
diff changeset
   138
	/**
a9db7fb3ce65 TabularFormatter: print colorful tables\!
František Kučera <franta-hg@frantovo.cz>
parents: 37
diff changeset
   139
	 * With all colors.
a9db7fb3ce65 TabularFormatter: print colorful tables\!
František Kučera <franta-hg@frantovo.cz>
parents: 37
diff changeset
   140
	 *
a9db7fb3ce65 TabularFormatter: print colorful tables\!
František Kučera <franta-hg@frantovo.cz>
parents: 37
diff changeset
   141
	 * @see #printRainbow(java.lang.String, int,
a9db7fb3ce65 TabularFormatter: print colorful tables\!
František Kučera <franta-hg@frantovo.cz>
parents: 37
diff changeset
   142
	 * info.globalcode.sql.dk.ColorfulPrintWriter.TerminalColor[])
a9db7fb3ce65 TabularFormatter: print colorful tables\!
František Kučera <franta-hg@frantovo.cz>
parents: 37
diff changeset
   143
	 */
a9db7fb3ce65 TabularFormatter: print colorful tables\!
František Kučera <franta-hg@frantovo.cz>
parents: 37
diff changeset
   144
	public void printRainbow(String string, int delay) {
a9db7fb3ce65 TabularFormatter: print colorful tables\!
František Kučera <franta-hg@frantovo.cz>
parents: 37
diff changeset
   145
		printRainbow(string, delay, TerminalColor.values());
a9db7fb3ce65 TabularFormatter: print colorful tables\!
František Kučera <franta-hg@frantovo.cz>
parents: 37
diff changeset
   146
	}
a9db7fb3ce65 TabularFormatter: print colorful tables\!
František Kučera <franta-hg@frantovo.cz>
parents: 37
diff changeset
   147
a9db7fb3ce65 TabularFormatter: print colorful tables\!
František Kučera <franta-hg@frantovo.cz>
parents: 37
diff changeset
   148
	/**
a9db7fb3ce65 TabularFormatter: print colorful tables\!
František Kučera <franta-hg@frantovo.cz>
parents: 37
diff changeset
   149
	 * Prints rainbow text – (re)writes same text subsequently in given colors and then in default
a9db7fb3ce65 TabularFormatter: print colorful tables\!
František Kučera <franta-hg@frantovo.cz>
parents: 37
diff changeset
   150
	 * color.
a9db7fb3ce65 TabularFormatter: print colorful tables\!
František Kučera <franta-hg@frantovo.cz>
parents: 37
diff changeset
   151
	 *
a9db7fb3ce65 TabularFormatter: print colorful tables\!
František Kučera <franta-hg@frantovo.cz>
parents: 37
diff changeset
   152
	 * @param string text to be printed, should not contain \n new line (then rainbow does not work
a9db7fb3ce65 TabularFormatter: print colorful tables\!
František Kučera <franta-hg@frantovo.cz>
parents: 37
diff changeset
   153
	 * – use println() after printRainbow() instead)
a9db7fb3ce65 TabularFormatter: print colorful tables\!
František Kučera <franta-hg@frantovo.cz>
parents: 37
diff changeset
   154
	 * @param delay delay between rewrites
a9db7fb3ce65 TabularFormatter: print colorful tables\!
František Kučera <franta-hg@frantovo.cz>
parents: 37
diff changeset
   155
	 * @param colors list of colors to be used
a9db7fb3ce65 TabularFormatter: print colorful tables\!
František Kučera <franta-hg@frantovo.cz>
parents: 37
diff changeset
   156
	 */
a9db7fb3ce65 TabularFormatter: print colorful tables\!
František Kučera <franta-hg@frantovo.cz>
parents: 37
diff changeset
   157
	public void printRainbow(String string, int delay, TerminalColor... colors) {
a9db7fb3ce65 TabularFormatter: print colorful tables\!
František Kučera <franta-hg@frantovo.cz>
parents: 37
diff changeset
   158
		for (TerminalColor c : colors) {
a9db7fb3ce65 TabularFormatter: print colorful tables\!
František Kučera <franta-hg@frantovo.cz>
parents: 37
diff changeset
   159
			print(c, string);
a9db7fb3ce65 TabularFormatter: print colorful tables\!
František Kučera <franta-hg@frantovo.cz>
parents: 37
diff changeset
   160
			try {
a9db7fb3ce65 TabularFormatter: print colorful tables\!
František Kučera <franta-hg@frantovo.cz>
parents: 37
diff changeset
   161
				Thread.sleep(delay);
a9db7fb3ce65 TabularFormatter: print colorful tables\!
František Kučera <franta-hg@frantovo.cz>
parents: 37
diff changeset
   162
			} catch (InterruptedException e) {
a9db7fb3ce65 TabularFormatter: print colorful tables\!
František Kučera <franta-hg@frantovo.cz>
parents: 37
diff changeset
   163
				// no time to sleep
a9db7fb3ce65 TabularFormatter: print colorful tables\!
František Kučera <franta-hg@frantovo.cz>
parents: 37
diff changeset
   164
				break;
a9db7fb3ce65 TabularFormatter: print colorful tables\!
František Kučera <franta-hg@frantovo.cz>
parents: 37
diff changeset
   165
			}
a9db7fb3ce65 TabularFormatter: print colorful tables\!
František Kučera <franta-hg@frantovo.cz>
parents: 37
diff changeset
   166
			backspace(string.length());
a9db7fb3ce65 TabularFormatter: print colorful tables\!
František Kučera <franta-hg@frantovo.cz>
parents: 37
diff changeset
   167
			flush();
a9db7fb3ce65 TabularFormatter: print colorful tables\!
František Kučera <franta-hg@frantovo.cz>
parents: 37
diff changeset
   168
		}
a9db7fb3ce65 TabularFormatter: print colorful tables\!
František Kučera <franta-hg@frantovo.cz>
parents: 37
diff changeset
   169
		print(string);
a9db7fb3ce65 TabularFormatter: print colorful tables\!
František Kučera <franta-hg@frantovo.cz>
parents: 37
diff changeset
   170
	}
a9db7fb3ce65 TabularFormatter: print colorful tables\!
František Kučera <franta-hg@frantovo.cz>
parents: 37
diff changeset
   171
31
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   172
	public void setForegroundColor(TerminalColor color) {
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   173
		printCodes(color.getForegroundCode());
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   174
	}
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   175
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   176
	public void setBackgroundColor(TerminalColor color) {
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   177
		printCodes(color.getBackgroundCode());
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   178
	}
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   179
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   180
	public void print(TerminalColor foregroundColor, String string) {
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   181
		setForegroundColor(foregroundColor);
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   182
		print(string);
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   183
		resetAll();
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   184
	}
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   185
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   186
	public void println(TerminalColor foregroundColor, String string) {
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   187
		print(foregroundColor, string);
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   188
		println();
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   189
	}
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   190
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   191
	public void print(TerminalColor foregroundColor, TerminalColor backgroundColor, String string) {
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   192
		setForegroundColor(foregroundColor);
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   193
		setBackgroundColor(backgroundColor);
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   194
		print(string);
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   195
		resetAll();
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   196
	}
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   197
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   198
	public void println(TerminalColor foregroundColor, TerminalColor backgroundColor, String string) {
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   199
		print(foregroundColor, backgroundColor, string);
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   200
		println();
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   201
	}
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   202
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   203
	public void print(TerminalColor foregroundColor, TerminalColor backgroundColor, EnumSet<TerminalStyle> styles, String string) {
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   204
		setForegroundColor(foregroundColor);
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   205
		setBackgroundColor(backgroundColor);
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   206
		setStyle(styles);
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   207
		print(string);
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   208
		resetAll();
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   209
	}
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   210
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   211
	public void println(TerminalColor foregroundColor, TerminalColor backgroundColor, EnumSet<TerminalStyle> styles, String string) {
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   212
		print(foregroundColor, backgroundColor, styles, string);
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   213
		println();
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   214
	}
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   215
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   216
	public void print(TerminalColor foregroundColor, TerminalColor backgroundColor, TerminalStyle style, String string) {
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   217
		print(foregroundColor, backgroundColor, EnumSet.of(style), string);
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   218
	}
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   219
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   220
	public void println(TerminalColor foregroundColor, TerminalColor backgroundColor, TerminalStyle style, String string) {
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   221
		print(foregroundColor, backgroundColor, style, string);
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   222
		println();
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   223
	}
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   224
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   225
	public void print(TerminalColor foregroundColor, EnumSet<TerminalStyle> styles, String string) {
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   226
		setForegroundColor(foregroundColor);
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   227
		setStyle(styles);
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   228
		print(string);
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   229
		resetAll();
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   230
	}
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   231
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   232
	public void println(TerminalColor foregroundColor, EnumSet<TerminalStyle> styles, String string) {
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   233
		print(foregroundColor, styles, string);
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   234
		println();
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   235
	}
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   236
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   237
	public void print(TerminalColor foregroundColor, TerminalStyle style, String string) {
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   238
		print(foregroundColor, EnumSet.of(style), string);
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   239
	}
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   240
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   241
	public void println(TerminalColor foregroundColor, TerminalStyle style, String string) {
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   242
		print(foregroundColor, style, string);
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   243
		println();
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   244
	}
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   245
37
9e6f8e5d5f98 support SQL commands returning more ResultSets + remove COMMAND_TYPE (type is now derived from result returned from SQL – it is not needed to specify the type on CLI)
František Kučera <franta-hg@frantovo.cz>
parents: 31
diff changeset
   246
	public void print(EnumSet<TerminalStyle> styles, String string) {
9e6f8e5d5f98 support SQL commands returning more ResultSets + remove COMMAND_TYPE (type is now derived from result returned from SQL – it is not needed to specify the type on CLI)
František Kučera <franta-hg@frantovo.cz>
parents: 31
diff changeset
   247
		setStyle(styles);
9e6f8e5d5f98 support SQL commands returning more ResultSets + remove COMMAND_TYPE (type is now derived from result returned from SQL – it is not needed to specify the type on CLI)
František Kučera <franta-hg@frantovo.cz>
parents: 31
diff changeset
   248
		print(string);
9e6f8e5d5f98 support SQL commands returning more ResultSets + remove COMMAND_TYPE (type is now derived from result returned from SQL – it is not needed to specify the type on CLI)
František Kučera <franta-hg@frantovo.cz>
parents: 31
diff changeset
   249
		resetAll();
9e6f8e5d5f98 support SQL commands returning more ResultSets + remove COMMAND_TYPE (type is now derived from result returned from SQL – it is not needed to specify the type on CLI)
František Kučera <franta-hg@frantovo.cz>
parents: 31
diff changeset
   250
	}
9e6f8e5d5f98 support SQL commands returning more ResultSets + remove COMMAND_TYPE (type is now derived from result returned from SQL – it is not needed to specify the type on CLI)
František Kučera <franta-hg@frantovo.cz>
parents: 31
diff changeset
   251
9e6f8e5d5f98 support SQL commands returning more ResultSets + remove COMMAND_TYPE (type is now derived from result returned from SQL – it is not needed to specify the type on CLI)
František Kučera <franta-hg@frantovo.cz>
parents: 31
diff changeset
   252
	public void println(EnumSet<TerminalStyle> styles, String string) {
9e6f8e5d5f98 support SQL commands returning more ResultSets + remove COMMAND_TYPE (type is now derived from result returned from SQL – it is not needed to specify the type on CLI)
František Kučera <franta-hg@frantovo.cz>
parents: 31
diff changeset
   253
		print(styles, string);
9e6f8e5d5f98 support SQL commands returning more ResultSets + remove COMMAND_TYPE (type is now derived from result returned from SQL – it is not needed to specify the type on CLI)
František Kučera <franta-hg@frantovo.cz>
parents: 31
diff changeset
   254
		println();
9e6f8e5d5f98 support SQL commands returning more ResultSets + remove COMMAND_TYPE (type is now derived from result returned from SQL – it is not needed to specify the type on CLI)
František Kučera <franta-hg@frantovo.cz>
parents: 31
diff changeset
   255
	}
9e6f8e5d5f98 support SQL commands returning more ResultSets + remove COMMAND_TYPE (type is now derived from result returned from SQL – it is not needed to specify the type on CLI)
František Kučera <franta-hg@frantovo.cz>
parents: 31
diff changeset
   256
9e6f8e5d5f98 support SQL commands returning more ResultSets + remove COMMAND_TYPE (type is now derived from result returned from SQL – it is not needed to specify the type on CLI)
František Kučera <franta-hg@frantovo.cz>
parents: 31
diff changeset
   257
	public void print(TerminalStyle style, String string) {
9e6f8e5d5f98 support SQL commands returning more ResultSets + remove COMMAND_TYPE (type is now derived from result returned from SQL – it is not needed to specify the type on CLI)
František Kučera <franta-hg@frantovo.cz>
parents: 31
diff changeset
   258
		print(EnumSet.of(style), string);
9e6f8e5d5f98 support SQL commands returning more ResultSets + remove COMMAND_TYPE (type is now derived from result returned from SQL – it is not needed to specify the type on CLI)
František Kučera <franta-hg@frantovo.cz>
parents: 31
diff changeset
   259
	}
9e6f8e5d5f98 support SQL commands returning more ResultSets + remove COMMAND_TYPE (type is now derived from result returned from SQL – it is not needed to specify the type on CLI)
František Kučera <franta-hg@frantovo.cz>
parents: 31
diff changeset
   260
9e6f8e5d5f98 support SQL commands returning more ResultSets + remove COMMAND_TYPE (type is now derived from result returned from SQL – it is not needed to specify the type on CLI)
František Kučera <franta-hg@frantovo.cz>
parents: 31
diff changeset
   261
	public void println(TerminalStyle style, String string) {
9e6f8e5d5f98 support SQL commands returning more ResultSets + remove COMMAND_TYPE (type is now derived from result returned from SQL – it is not needed to specify the type on CLI)
František Kučera <franta-hg@frantovo.cz>
parents: 31
diff changeset
   262
		print(style, string);
9e6f8e5d5f98 support SQL commands returning more ResultSets + remove COMMAND_TYPE (type is now derived from result returned from SQL – it is not needed to specify the type on CLI)
František Kučera <franta-hg@frantovo.cz>
parents: 31
diff changeset
   263
		println();
9e6f8e5d5f98 support SQL commands returning more ResultSets + remove COMMAND_TYPE (type is now derived from result returned from SQL – it is not needed to specify the type on CLI)
František Kučera <franta-hg@frantovo.cz>
parents: 31
diff changeset
   264
	}
9e6f8e5d5f98 support SQL commands returning more ResultSets + remove COMMAND_TYPE (type is now derived from result returned from SQL – it is not needed to specify the type on CLI)
František Kučera <franta-hg@frantovo.cz>
parents: 31
diff changeset
   265
31
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   266
	public void resetAll() {
55
f5ed7c4efacc colorful logging
František Kučera <franta-hg@frantovo.cz>
parents: 40
diff changeset
   267
		printCodes(TerminalStyle.Reset.code);
31
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   268
	}
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   269
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   270
	private void printCodes(int... codes) {
126
2357a9d08660 Colors can be definitively turned off in constructor
František Kučera <franta-hg@frantovo.cz>
parents: 59
diff changeset
   271
		if (COLOR_ENABLED && colorful) {
31
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   272
			print("\033[");
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   273
			for (int i = 0; i < codes.length; i++) {
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   274
				print(codes[i]);
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   275
				if (i < codes.length - 1 && codes.length > 1) {
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   276
					print(";");
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   277
				}
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   278
			}
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   279
			print("m");
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   280
		}
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   281
	}
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   282
126
2357a9d08660 Colors can be definitively turned off in constructor
František Kučera <franta-hg@frantovo.cz>
parents: 59
diff changeset
   283
	/**
2357a9d08660 Colors can be definitively turned off in constructor
František Kučera <franta-hg@frantovo.cz>
parents: 59
diff changeset
   284
	 * Colors can be switched on/off during usage of this writer.
2357a9d08660 Colors can be definitively turned off in constructor
František Kučera <franta-hg@frantovo.cz>
parents: 59
diff changeset
   285
	 *
2357a9d08660 Colors can be definitively turned off in constructor
František Kučera <franta-hg@frantovo.cz>
parents: 59
diff changeset
   286
	 * @return whether colors are currently turned on
2357a9d08660 Colors can be definitively turned off in constructor
František Kučera <franta-hg@frantovo.cz>
parents: 59
diff changeset
   287
	 * @see #isColorEnabled()
2357a9d08660 Colors can be definitively turned off in constructor
František Kučera <franta-hg@frantovo.cz>
parents: 59
diff changeset
   288
	 */
31
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   289
	public boolean isColorful() {
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   290
		return colorful;
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   291
	}
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   292
126
2357a9d08660 Colors can be definitively turned off in constructor
František Kučera <franta-hg@frantovo.cz>
parents: 59
diff changeset
   293
	/**
2357a9d08660 Colors can be definitively turned off in constructor
František Kučera <franta-hg@frantovo.cz>
parents: 59
diff changeset
   294
	 * Collors might be definitively disabled in constructor. If not, they can be turned on/off
2357a9d08660 Colors can be definitively turned off in constructor
František Kučera <franta-hg@frantovo.cz>
parents: 59
diff changeset
   295
	 * during usage of this writer by {@linkplain #setColorful(boolean)}
2357a9d08660 Colors can be definitively turned off in constructor
František Kučera <franta-hg@frantovo.cz>
parents: 59
diff changeset
   296
	 *
2357a9d08660 Colors can be definitively turned off in constructor
František Kučera <franta-hg@frantovo.cz>
parents: 59
diff changeset
   297
	 * @return whether colors are allowed for this instance of this class
2357a9d08660 Colors can be definitively turned off in constructor
František Kučera <franta-hg@frantovo.cz>
parents: 59
diff changeset
   298
	 * @see #isColorful()
2357a9d08660 Colors can be definitively turned off in constructor
František Kučera <franta-hg@frantovo.cz>
parents: 59
diff changeset
   299
	 */
2357a9d08660 Colors can be definitively turned off in constructor
František Kučera <franta-hg@frantovo.cz>
parents: 59
diff changeset
   300
	public boolean isColorEnabled() {
2357a9d08660 Colors can be definitively turned off in constructor
František Kučera <franta-hg@frantovo.cz>
parents: 59
diff changeset
   301
		return COLOR_ENABLED;
2357a9d08660 Colors can be definitively turned off in constructor
František Kučera <franta-hg@frantovo.cz>
parents: 59
diff changeset
   302
	}
2357a9d08660 Colors can be definitively turned off in constructor
František Kučera <franta-hg@frantovo.cz>
parents: 59
diff changeset
   303
2357a9d08660 Colors can be definitively turned off in constructor
František Kučera <franta-hg@frantovo.cz>
parents: 59
diff changeset
   304
	/**
2357a9d08660 Colors can be definitively turned off in constructor
František Kučera <franta-hg@frantovo.cz>
parents: 59
diff changeset
   305
	 * @see #isColorful()
2357a9d08660 Colors can be definitively turned off in constructor
František Kučera <franta-hg@frantovo.cz>
parents: 59
diff changeset
   306
	 * @see #isColorEnabled()
2357a9d08660 Colors can be definitively turned off in constructor
František Kučera <franta-hg@frantovo.cz>
parents: 59
diff changeset
   307
	 */
31
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   308
	public void setColorful(boolean colorful) {
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   309
		this.colorful = colorful;
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   310
	}
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   311
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   312
	public ColorfulPrintWriter(File file) throws FileNotFoundException {
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   313
		super(file);
126
2357a9d08660 Colors can be definitively turned off in constructor
František Kučera <franta-hg@frantovo.cz>
parents: 59
diff changeset
   314
		COLOR_ENABLED = true;
31
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   315
	}
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   316
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   317
	public ColorfulPrintWriter(OutputStream out) {
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   318
		super(out);
126
2357a9d08660 Colors can be definitively turned off in constructor
František Kučera <franta-hg@frantovo.cz>
parents: 59
diff changeset
   319
		COLOR_ENABLED = true;
31
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   320
	}
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   321
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   322
	public ColorfulPrintWriter(String fileName) throws FileNotFoundException {
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   323
		super(fileName);
126
2357a9d08660 Colors can be definitively turned off in constructor
František Kučera <franta-hg@frantovo.cz>
parents: 59
diff changeset
   324
		COLOR_ENABLED = true;
31
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   325
	}
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   326
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   327
	public ColorfulPrintWriter(Writer out) {
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   328
		super(out);
126
2357a9d08660 Colors can be definitively turned off in constructor
František Kučera <franta-hg@frantovo.cz>
parents: 59
diff changeset
   329
		COLOR_ENABLED = true;
31
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   330
	}
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   331
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   332
	public ColorfulPrintWriter(File file, String csn) throws FileNotFoundException, UnsupportedEncodingException {
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   333
		super(file, csn);
126
2357a9d08660 Colors can be definitively turned off in constructor
František Kučera <franta-hg@frantovo.cz>
parents: 59
diff changeset
   334
		COLOR_ENABLED = true;
31
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   335
	}
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   336
126
2357a9d08660 Colors can be definitively turned off in constructor
František Kučera <franta-hg@frantovo.cz>
parents: 59
diff changeset
   337
	/**
2357a9d08660 Colors can be definitively turned off in constructor
František Kučera <franta-hg@frantovo.cz>
parents: 59
diff changeset
   338
	 * @param colorEnabled colors might be definitively disabled by this option – this might be more
2357a9d08660 Colors can be definitively turned off in constructor
František Kučera <franta-hg@frantovo.cz>
parents: 59
diff changeset
   339
	 * optimalizable than dynamic turning off colors by {@linkplain #setColorful(boolean)} which is
2357a9d08660 Colors can be definitively turned off in constructor
František Kučera <franta-hg@frantovo.cz>
parents: 59
diff changeset
   340
	 * not definitive (colors can be turned on during live of this instance). This might be useful
2357a9d08660 Colors can be definitively turned off in constructor
František Kučera <franta-hg@frantovo.cz>
parents: 59
diff changeset
   341
	 * if you need an instance of this class but don't need colors at all.
2357a9d08660 Colors can be definitively turned off in constructor
František Kučera <franta-hg@frantovo.cz>
parents: 59
diff changeset
   342
	 */
2357a9d08660 Colors can be definitively turned off in constructor
František Kučera <franta-hg@frantovo.cz>
parents: 59
diff changeset
   343
	public ColorfulPrintWriter(OutputStream out, boolean autoFlush, boolean colorEnabled) {
31
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   344
		super(out, autoFlush);
126
2357a9d08660 Colors can be definitively turned off in constructor
František Kučera <franta-hg@frantovo.cz>
parents: 59
diff changeset
   345
		COLOR_ENABLED = colorEnabled;
31
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   346
	}
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   347
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   348
	public ColorfulPrintWriter(String fileName, String csn) throws FileNotFoundException, UnsupportedEncodingException {
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   349
		super(fileName, csn);
126
2357a9d08660 Colors can be definitively turned off in constructor
František Kučera <franta-hg@frantovo.cz>
parents: 59
diff changeset
   350
		COLOR_ENABLED = true;
31
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   351
	}
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   352
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   353
	public ColorfulPrintWriter(Writer out, boolean autoFlush) {
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   354
		super(out, autoFlush);
126
2357a9d08660 Colors can be definitively turned off in constructor
František Kučera <franta-hg@frantovo.cz>
parents: 59
diff changeset
   355
		COLOR_ENABLED = true;
31
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   356
	}
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   357
}