Package org.fusesource.jansi
Class AnsiConsole
java.lang.Object
org.fusesource.jansi.AnsiConsole
Provides consistent access to an ANSI aware console PrintStream or an ANSI codes stripping PrintStream
if not on a terminal (see
Jansi native
CLibrary isatty(int)).
The native library used is named jansi
and is loaded using HawtJNI Runtime
Library
- Since:
- 1.0
- Author:
- Hiram Chirino
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic PrintStream
Deprecated.static final String
The default color support that Jansi will use, can be either16
,256
ortruecolor
.static final String
Force the use of 16 colors.static final String
Force the use of 256 colors.static final String
Force the use of 24-bit colors.static final String
Deprecated.this property has been added but only for backward compatibility.static final String
Jansi colors specific to the standard error stream.static final String
Jansi mode specific to the standard error stream.static final String
Deprecated.useJANSI_MODE
insteadstatic final String
If thejansi.graceful
system property is set to false, any exception that occurs during the initialization will cause the library to report this exception and fail.static final String
The default mode which Jansi will use, can be eitherforce
,strip
ordefault
(the default).static final String
Jansi mode value that output sequences if on a terminal, else strip them.static final String
Jansi mode value to force ansi sequences to the stream even if it's not a terminal.static final String
Jansi mode value to strip all ansi sequences.static final String
If thejansi.noreset
system property is set to true, the attributes won't be reset when the streams are uninstalled.static final String
Jansi colors specific to the standard output stream.static final String
Jansi mode specific to the standard output stream.static final String
Deprecated.useJANSI_MODE
insteadstatic final String
Deprecated.useJANSI_MODE
insteadstatic PrintStream
Deprecated.this field will be made private in a future release, useout()
insteadstatic PrintStream
Deprecated.this field will be made private in a future release, usesysErr()
insteadstatic PrintStream
Deprecated.this field will be made private in a future release, usesysOut()
instead -
Method Summary
Modifier and TypeMethodDescriptionstatic AnsiPrintStream
err()
If the standard out natively supports ANSI escape codes, then this just returns System.err, otherwise it will provide an ANSI aware PrintStream which strips out the ANSI escape sequences or which implement the escape sequences.static int
Try to find the width of the console for this process.static boolean
check if the streams have been installed or notstatic AnsiPrintStream
out()
If the standard out natively supports ANSI escape codes, then this just returns System.out, otherwise it will provide an ANSI aware PrintStream which strips out the ANSI escape sequences or which implement the escape sequences.static PrintStream
sysErr()
Access to the original System.err stream before ansi streams were installed.static PrintStream
sysOut()
Access to the original System.out stream before ansi streams were installed.static void
InstallAnsiConsole.out()
toSystem.out
andAnsiConsole.err()
toSystem.err
.static void
undo a previoussystemInstall()
.
-
Field Details
-
JANSI_MODE
The default mode which Jansi will use, can be eitherforce
,strip
ordefault
(the default). If this property is set, it will overridejansi.passthrough
,jansi.strip
andjansi.force
properties.- See Also:
-
JANSI_OUT_MODE
Jansi mode specific to the standard output stream.- See Also:
-
JANSI_ERR_MODE
Jansi mode specific to the standard error stream.- See Also:
-
JANSI_MODE_STRIP
Jansi mode value to strip all ansi sequences.- See Also:
-
JANSI_MODE_FORCE
Jansi mode value to force ansi sequences to the stream even if it's not a terminal.- See Also:
-
JANSI_MODE_DEFAULT
Jansi mode value that output sequences if on a terminal, else strip them.- See Also:
-
JANSI_COLORS
The default color support that Jansi will use, can be either16
,256
ortruecolor
. If not set, JANSI will try to autodetect the number of colors supported by the terminal by checking theCOLORTERM
andTERM
variables.- See Also:
-
JANSI_OUT_COLORS
Jansi colors specific to the standard output stream.- See Also:
-
JANSI_ERR_COLORS
Jansi colors specific to the standard error stream.- See Also:
-
JANSI_COLORS_16
Force the use of 16 colors. When using a 256-indexed color, or an RGB color, the color will be rounded to the nearest one from the 16 palette.- See Also:
-
JANSI_COLORS_256
Force the use of 256 colors. When using an RGB color, the color will be rounded to the nearest one from the standard 256 palette.- See Also:
-
JANSI_COLORS_TRUECOLOR
Force the use of 24-bit colors.- See Also:
-
JANSI_PASSTHROUGH
Deprecated.useJANSI_MODE
insteadIf thejansi.passthrough
system property is set to true, will not perform any transformation and any ansi sequence will be conveyed without any modification.- See Also:
-
JANSI_STRIP
Deprecated.useJANSI_MODE
insteadIf thejansi.strip
system property is set to true, andjansi.passthrough
is not enabled, all ansi sequences will be stripped before characters are written to the output streams.- See Also:
-
JANSI_FORCE
Deprecated.useJANSI_MODE
insteadIf thejansi.force
system property is set to true, and neitherjansi.passthrough
norjansi.strip
are set, then ansi sequences will be printed to the output stream. This forces the behavior which is by default dependent on the output stream being a real console: if the output stream is redirected to a file or through a system pipe, ansi sequences are disabled by default.- See Also:
-
JANSI_EAGER
Deprecated.this property has been added but only for backward compatibility.If thejansi.eager
system property is set to true, the system streams will be eagerly initialized, else the initialization is delayed untilout()
,err()
orsystemInstall()
is called.- Since:
- 2.1
- See Also:
-
JANSI_NORESET
If thejansi.noreset
system property is set to true, the attributes won't be reset when the streams are uninstalled.- See Also:
-
JANSI_GRACEFUL
If thejansi.graceful
system property is set to false, any exception that occurs during the initialization will cause the library to report this exception and fail. The default behavior is to behave gracefully and fall back to pure emulation on posix systems.- See Also:
-
system_out
Deprecated.this field will be made private in a future release, usesysOut()
instead -
out
Deprecated.this field will be made private in a future release, useout()
instead -
system_err
Deprecated.this field will be made private in a future release, usesysErr()
instead -
err
Deprecated.this field will be made private in a future release, useerr()
instead
-
-
Method Details
-
getTerminalWidth
public static int getTerminalWidth()Try to find the width of the console for this process. Both output and error streams will be checked to determine the width. A value of 0 is returned if the width can not be determined.- Since:
- 2.2
-
out
If the standard out natively supports ANSI escape codes, then this just returns System.out, otherwise it will provide an ANSI aware PrintStream which strips out the ANSI escape sequences or which implement the escape sequences.- Returns:
- a PrintStream which is ANSI aware.
-
sysOut
Access to the original System.out stream before ansi streams were installed.- Returns:
- the originial System.out print stream
-
err
If the standard out natively supports ANSI escape codes, then this just returns System.err, otherwise it will provide an ANSI aware PrintStream which strips out the ANSI escape sequences or which implement the escape sequences.- Returns:
- a PrintStream which is ANSI aware.
-
sysErr
Access to the original System.err stream before ansi streams were installed.- Returns:
- the originial System.err print stream
-
systemInstall
public static void systemInstall()InstallAnsiConsole.out()
toSystem.out
andAnsiConsole.err()
toSystem.err
.- See Also:
-
isInstalled
public static boolean isInstalled()check if the streams have been installed or not -
systemUninstall
public static void systemUninstall()undo a previoussystemInstall()
. IfsystemInstall()
was called multiple times,systemUninstall()
must be called the same number of times before it is actually uninstalled.
-
err()
instead