Package org.fusesource.jansi
Class AnsiConsole
- java.lang.Object
-
- org.fusesource.jansi.AnsiConsole
-
public class AnsiConsole extends Object
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
jansiand is loaded using HawtJNI RuntimeLibrary- Since:
- 1.0
- Author:
- Hiram Chirino
- See Also:
systemInstall(),out(),err(),for more details on ANSI mode selection
-
-
Field Summary
Fields Modifier and Type Field Description static PrintStreamerrDeprecated.this field will be made private in a future release, useerr()insteadstatic StringJANSI_COLORSThe default color support that Jansi will use, can be either16,256ortruecolor.static StringJANSI_COLORS_16Force the use of 16 colors.static StringJANSI_COLORS_256Force the use of 256 colors.static StringJANSI_COLORS_TRUECOLORForce the use of 24-bit colors.static StringJANSI_EAGERDeprecated.this property has been added but only for backward compatibility.static StringJANSI_ERR_COLORSJansi colors specific to the standard error stream.static StringJANSI_ERR_MODEJansi mode specific to the standard error stream.static StringJANSI_FORCEDeprecated.useJANSI_MODEinsteadstatic StringJANSI_GRACEFULIf thejansi.gracefulsystem property is set to false, any exception that occurs during the initialization will cause the library to report this exception and fail.static StringJANSI_MODEThe default mode which Jansi will use, can be eitherforce,stripordefault(the default).static StringJANSI_MODE_DEFAULTJansi mode value that output sequences if on a terminal, else strip them.static StringJANSI_MODE_FORCEJansi mode value to force ansi sequences to the stream even if it's not a terminal.static StringJANSI_MODE_STRIPJansi mode value to strip all ansi sequences.static StringJANSI_NORESETIf thejansi.noresetsystem property is set to true, the attributes won't be reset when the streams are uninstalled.static StringJANSI_OUT_COLORSJansi colors specific to the standard output stream.static StringJANSI_OUT_MODEJansi mode specific to the standard output stream.static StringJANSI_PASSTHROUGHDeprecated.useJANSI_MODEinsteadstatic StringJANSI_STRIPDeprecated.useJANSI_MODEinsteadstatic PrintStreamoutDeprecated.this field will be made private in a future release, useout()insteadstatic PrintStreamsystem_errDeprecated.this field will be made private in a future release, usesysErr()insteadstatic PrintStreamsystem_outDeprecated.this field will be made private in a future release, usesysOut()instead
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static AnsiPrintStreamerr()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 intgetTerminalWidth()Try to find the width of the console for this process.static booleanisInstalled()check if the streams have been installed or notstatic AnsiPrintStreamout()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 PrintStreamsysErr()Access to the original System.err stream before ansi streams were installed.static PrintStreamsysOut()Access to the original System.out stream before ansi streams were installed.static voidsystemInstall()InstallAnsiConsole.out()toSystem.outandAnsiConsole.err()toSystem.err.static voidsystemUninstall()undo a previoussystemInstall().
-
-
-
Field Detail
-
JANSI_MODE
public static final String JANSI_MODE
The default mode which Jansi will use, can be eitherforce,stripordefault(the default). If this property is set, it will overridejansi.passthrough,jansi.stripandjansi.forceproperties.- See Also:
- Constant Field Values
-
JANSI_OUT_MODE
public static final String JANSI_OUT_MODE
Jansi mode specific to the standard output stream.- See Also:
- Constant Field Values
-
JANSI_ERR_MODE
public static final String JANSI_ERR_MODE
Jansi mode specific to the standard error stream.- See Also:
- Constant Field Values
-
JANSI_MODE_STRIP
public static final String JANSI_MODE_STRIP
Jansi mode value to strip all ansi sequences.- See Also:
- Constant Field Values
-
JANSI_MODE_FORCE
public static final String JANSI_MODE_FORCE
Jansi mode value to force ansi sequences to the stream even if it's not a terminal.- See Also:
- Constant Field Values
-
JANSI_MODE_DEFAULT
public static final String JANSI_MODE_DEFAULT
Jansi mode value that output sequences if on a terminal, else strip them.- See Also:
- Constant Field Values
-
JANSI_COLORS
public static final String JANSI_COLORS
The default color support that Jansi will use, can be either16,256ortruecolor. If not set, JANSI will try to autodetect the number of colors supported by the terminal by checking theCOLORTERMandTERMvariables.- See Also:
- Constant Field Values
-
JANSI_OUT_COLORS
public static final String JANSI_OUT_COLORS
Jansi colors specific to the standard output stream.- See Also:
- Constant Field Values
-
JANSI_ERR_COLORS
public static final String JANSI_ERR_COLORS
Jansi colors specific to the standard error stream.- See Also:
- Constant Field Values
-
JANSI_COLORS_16
public static final String 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:
- Constant Field Values
-
JANSI_COLORS_256
public static final String 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:
- Constant Field Values
-
JANSI_COLORS_TRUECOLOR
public static final String JANSI_COLORS_TRUECOLOR
Force the use of 24-bit colors.- See Also:
- Constant Field Values
-
JANSI_PASSTHROUGH
@Deprecated public static final String JANSI_PASSTHROUGH
Deprecated.useJANSI_MODEinsteadIf thejansi.passthroughsystem property is set to true, will not perform any transformation and any ansi sequence will be conveyed without any modification.- See Also:
- Constant Field Values
-
JANSI_STRIP
@Deprecated public static final String JANSI_STRIP
Deprecated.useJANSI_MODEinsteadIf thejansi.stripsystem property is set to true, andjansi.passthroughis not enabled, all ansi sequences will be stripped before characters are written to the output streams.- See Also:
- Constant Field Values
-
JANSI_FORCE
@Deprecated public static final String JANSI_FORCE
Deprecated.useJANSI_MODEinsteadIf thejansi.forcesystem property is set to true, and neitherjansi.passthroughnorjansi.stripare 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:
- Constant Field Values
-
JANSI_EAGER
@Deprecated public static final String JANSI_EAGER
Deprecated.this property has been added but only for backward compatibility.If thejansi.eagersystem 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:
- Constant Field Values
-
JANSI_NORESET
public static final String JANSI_NORESET
If thejansi.noresetsystem property is set to true, the attributes won't be reset when the streams are uninstalled.- See Also:
- Constant Field Values
-
JANSI_GRACEFUL
public static final String JANSI_GRACEFUL
If thejansi.gracefulsystem 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:
- Constant Field Values
-
system_out
@Deprecated public static PrintStream system_out
Deprecated.this field will be made private in a future release, usesysOut()instead
-
out
@Deprecated public static PrintStream out
Deprecated.this field will be made private in a future release, useout()instead
-
system_err
@Deprecated public static PrintStream system_err
Deprecated.this field will be made private in a future release, usesysErr()instead
-
err
@Deprecated public static PrintStream err
Deprecated.this field will be made private in a future release, useerr()instead
-
-
Method Detail
-
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
public static 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.- Returns:
- a PrintStream which is ANSI aware.
-
sysOut
public static PrintStream sysOut()
Access to the original System.out stream before ansi streams were installed.- Returns:
- the originial System.out print stream
-
err
public static 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.- Returns:
- a PrintStream which is ANSI aware.
-
sysErr
public static PrintStream 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.outandAnsiConsole.err()toSystem.err.- See Also:
systemUninstall()
-
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.
-
-