@@ -87,13 +87,22 @@ public class AnsiConsole {
87
87
88
88
static final int ENABLE_VIRTUAL_TERMINAL_PROCESSING = 0x0004 ;
89
89
90
+ public static final String JANSI_PASSTHROUGH = "jansi.passthrough" ;
91
+ public static final String JANSI_STRIP = "jansi.strip" ;
92
+ public static final String JANSI_FORCE = "jansi.force" ;
93
+ public static final String JANSI_NO_OPTIMIZE = "jansi.no-optimize" ;
94
+ public static final String JANSI_DO_WRAP = "jansi.do-wrap" ;
95
+
96
+
90
97
private static JansiOutputType jansiOutputType ;
91
98
static final JansiOutputType JANSI_STDOUT_TYPE ;
92
99
static final JansiOutputType JANSI_STDERR_TYPE ;
100
+
93
101
static {
94
- out = ansiSystem (true );
102
+ boolean doWrap = getBoolean (JANSI_DO_WRAP );
103
+ out = doWrap ? wrapSystemOut (system_out ) : ansiSystem (true );
95
104
JANSI_STDOUT_TYPE = jansiOutputType ;
96
- err = ansiSystem (false );
105
+ err = doWrap ? wrapSystemErr ( system_err ) : ansiSystem (false );
97
106
JANSI_STDERR_TYPE = jansiOutputType ;
98
107
}
99
108
@@ -109,14 +118,14 @@ private static PrintStream ansiSystem(boolean stdout) {
109
118
110
119
// If the jansi.passthrough property is set, then don't interpret
111
120
// any of the ansi sequences.
112
- if (Boolean . getBoolean ("jansi.passthrough" )) {
121
+ if (getBoolean (JANSI_PASSTHROUGH )) {
113
122
jansiOutputType = JansiOutputType .PASSTHROUGH ;
114
123
return newPrintStream (out , enc );
115
124
}
116
125
117
126
// If the jansi.strip property is set, then we just strip the
118
127
// the ansi escapes.
119
- if (Boolean . getBoolean ("jansi.strip" )) {
128
+ if (getBoolean (JANSI_STRIP )) {
120
129
jansiOutputType = JansiOutputType .STRIP_ANSI ;
121
130
return new PrintStream (new AnsiNoSyncOutputStream (out , new AnsiProcessor (out )), true );
122
131
}
@@ -152,7 +161,7 @@ && SetConsoleMode(console, mode[0] | ENABLE_VIRTUAL_TERMINAL_PROCESSING) != 0) {
152
161
try {
153
162
// If the jansi.force property is set, then we force to output
154
163
// the ansi escapes for piping it into ansi color aware commands (e.g. less -r)
155
- boolean forceColored = Boolean . getBoolean ("jansi.force" );
164
+ boolean forceColored = getBoolean (JANSI_FORCE );
156
165
// If we can detect that stdout is not a tty.. then setup
157
166
// to strip the ANSI sequences..
158
167
if (!forceColored && isatty (stdout ? 1 : 2 ) == 0 ) {
@@ -208,6 +217,17 @@ public void close() {
208
217
}
209
218
}
210
219
220
+ static boolean getBoolean (String name ) {
221
+ boolean result = false ;
222
+ try {
223
+ String val = System .getProperty (name );
224
+ result = val .isEmpty () || Boolean .parseBoolean (val );
225
+ } catch (IllegalArgumentException e ) {
226
+ } catch (NullPointerException e ) {
227
+ }
228
+ return result ;
229
+ }
230
+
211
231
@ Deprecated
212
232
public static OutputStream wrapOutputStream (final OutputStream stream ) {
213
233
try {
@@ -247,14 +267,14 @@ public static OutputStream wrapOutputStream(final OutputStream stream, int filen
247
267
248
268
// If the jansi.passthrough property is set, then don't interpret
249
269
// any of the ansi sequences.
250
- if (Boolean . getBoolean ("jansi.passthrough" )) {
270
+ if (getBoolean (JANSI_PASSTHROUGH )) {
251
271
jansiOutputType = JansiOutputType .PASSTHROUGH ;
252
272
return stream ;
253
273
}
254
274
255
275
// If the jansi.strip property is set, then we just strip the
256
276
// the ansi escapes.
257
- if (Boolean . getBoolean ("jansi.strip" )) {
277
+ if (getBoolean (JANSI_STRIP )) {
258
278
jansiOutputType = JansiOutputType .STRIP_ANSI ;
259
279
return new AnsiOutputStream (stream );
260
280
}
@@ -280,7 +300,7 @@ public static OutputStream wrapOutputStream(final OutputStream stream, int filen
280
300
try {
281
301
// If the jansi.force property is set, then we force to output
282
302
// the ansi escapes for piping it into ansi color aware commands (e.g. less -r)
283
- boolean forceColored = Boolean . getBoolean ("jansi.force" );
303
+ boolean forceColored = getBoolean (JANSI_FORCE );
284
304
// If we can detect that stdout is not a tty.. then setup
285
305
// to strip the ANSI sequences..
286
306
if (!forceColored && isatty (fileno ) == 0 ) {
@@ -325,7 +345,7 @@ public void close() throws IOException {
325
345
public static PrintStream wrapPrintStream (final PrintStream ps , int fileno ) {
326
346
PrintStream result = doWrapPrintStream (ps , fileno );
327
347
if (result != ps ) {
328
- if (!Boolean . getBoolean ("jansi.no-optimize" )) {
348
+ if (!getBoolean (JANSI_NO_OPTIMIZE )) {
329
349
result = optimize (ps , result );
330
350
}
331
351
}
@@ -335,14 +355,14 @@ public static PrintStream wrapPrintStream(final PrintStream ps, int fileno) {
335
355
private static PrintStream doWrapPrintStream (final PrintStream ps , int fileno ) {
336
356
// If the jansi.passthrough property is set, then don't interpret
337
357
// any of the ansi sequences.
338
- if (Boolean . getBoolean ("jansi.passthrough" )) {
358
+ if (getBoolean (JANSI_PASSTHROUGH )) {
339
359
jansiOutputType = JansiOutputType .PASSTHROUGH ;
340
360
return ps ;
341
361
}
342
362
343
363
// If the jansi.strip property is set, then we just strip the
344
364
// the ansi escapes.
345
- if (Boolean . getBoolean ("jansi.strip" )) {
365
+ if (getBoolean (JANSI_STRIP )) {
346
366
jansiOutputType = JansiOutputType .STRIP_ANSI ;
347
367
return new AnsiPrintStream (ps );
348
368
}
@@ -368,7 +388,7 @@ private static PrintStream doWrapPrintStream(final PrintStream ps, int fileno) {
368
388
try {
369
389
// If the jansi.force property is set, then we force to output
370
390
// the ansi escapes for piping it into ansi color aware commands (e.g. less -r)
371
- boolean forceColored = Boolean . getBoolean ("jansi.force" );
391
+ boolean forceColored = getBoolean (JANSI_FORCE );
372
392
// If we can detect that stdout is not a tty.. then setup
373
393
// to strip the ANSI sequences..
374
394
if (!forceColored && isatty (fileno ) == 0 ) {
0 commit comments