90 array[i++] = s.getCode(); |
90 array[i++] = s.getCode(); |
91 } |
91 } |
92 return array; |
92 return array; |
93 } |
93 } |
94 |
94 |
|
95 /** |
|
96 * Print (usually audible) bell code (\007, \a, ^G) |
|
97 */ |
|
98 public void bell() { |
|
99 print("\007"); |
|
100 } |
|
101 |
|
102 /** |
|
103 * Eat the last character |
|
104 */ |
|
105 public void backspace() { |
|
106 print("\b"); |
|
107 } |
|
108 |
|
109 /** |
|
110 * Eat n last characters |
|
111 * |
|
112 * @param count n |
|
113 */ |
|
114 public void backspace(int count) { |
|
115 for (int i = 0; i < count; i++) { |
|
116 backspace(); |
|
117 } |
|
118 } |
|
119 |
|
120 /** |
|
121 * With 100 ms delay and all colors. |
|
122 * |
|
123 * @see #printRainbow(java.lang.String, int, |
|
124 * info.globalcode.sql.dk.ColorfulPrintWriter.TerminalColor[]) |
|
125 */ |
|
126 public void printRainbow(String string) { |
|
127 printRainbow(string, 100); |
|
128 } |
|
129 |
|
130 /** |
|
131 * With all colors. |
|
132 * |
|
133 * @see #printRainbow(java.lang.String, int, |
|
134 * info.globalcode.sql.dk.ColorfulPrintWriter.TerminalColor[]) |
|
135 */ |
|
136 public void printRainbow(String string, int delay) { |
|
137 printRainbow(string, delay, TerminalColor.values()); |
|
138 } |
|
139 |
|
140 /** |
|
141 * Prints rainbow text – (re)writes same text subsequently in given colors and then in default |
|
142 * color. |
|
143 * |
|
144 * @param string text to be printed, should not contain \n new line (then rainbow does not work |
|
145 * – use println() after printRainbow() instead) |
|
146 * @param delay delay between rewrites |
|
147 * @param colors list of colors to be used |
|
148 */ |
|
149 public void printRainbow(String string, int delay, TerminalColor... colors) { |
|
150 for (TerminalColor c : colors) { |
|
151 print(c, string); |
|
152 try { |
|
153 Thread.sleep(delay); |
|
154 } catch (InterruptedException e) { |
|
155 // no time to sleep |
|
156 break; |
|
157 } |
|
158 backspace(string.length()); |
|
159 flush(); |
|
160 } |
|
161 print(string); |
|
162 } |
|
163 |
95 public void setForegroundColor(TerminalColor color) { |
164 public void setForegroundColor(TerminalColor color) { |
96 printCodes(color.getForegroundCode()); |
165 printCodes(color.getForegroundCode()); |
97 } |
166 } |
98 |
167 |
99 public void setBackgroundColor(TerminalColor color) { |
168 public void setBackgroundColor(TerminalColor color) { |