Package org.fusesource.jansi
Class AnsiConsole
- java.lang.Object
-
- org.fusesource.jansi.AnsiConsole
-
public class AnsiConsole extends java.lang.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
jansi
and is loaded using HawtJNI RuntimeLibrary
- Since:
- 1.0
- See Also:
systemInstall()
,out()
,err()
,for more details on ANSI mode selection
-
-
Field Summary
Fields Modifier and Type Field Description (package private) static int
ENABLE_VIRTUAL_TERMINAL_PROCESSING
static java.io.PrintStream
err
Deprecated.this field will be made private in a future release, useerr()
insteadprivate static boolean
initialized
private static int
installed
(package private) static boolean
IS_CONEMU
(package private) static boolean
IS_CYGWIN
(package private) static boolean
IS_MSYSTEM
(package private) static boolean
IS_WINDOWS
static java.lang.String
JANSI_COLORS
The default color support that Jansi will use, can be either16
,256
ortruecolor
.static java.lang.String
JANSI_COLORS_16
Force the use of 16 colors.static java.lang.String
JANSI_COLORS_256
Force the use of 256 colors.static java.lang.String
JANSI_COLORS_TRUECOLOR
Force the use of 24-bit colors.static java.lang.String
JANSI_EAGER
Deprecated.this property has been added but only for backward compatibility.static java.lang.String
JANSI_ERR_COLORS
Jansi colors specific to the standard error stream.static java.lang.String
JANSI_ERR_MODE
Jansi mode specific to the standard error stream.static java.lang.String
JANSI_FORCE
Deprecated.useJANSI_MODE
insteadstatic java.lang.String
JANSI_MODE
The default mode which Jansi will use, can be eitherforce
,strip
ordefault
(the default).static java.lang.String
JANSI_MODE_DEFAULT
Jansi mode value that output sequences if on a terminal, else strip them.static java.lang.String
JANSI_MODE_FORCE
Jansi mode value to force ansi sequences to the stream even if it's not a terminal.static java.lang.String
JANSI_MODE_STRIP
Jansi mode value to strip all ansi sequences.static java.lang.String
JANSI_NORESET
If thejansi.noreset
system property is set to true, the attributes won't be reset when the streams are uninstalled.static java.lang.String
JANSI_OUT_COLORS
Jansi colors specific to the standard output stream.static java.lang.String
JANSI_OUT_MODE
Jansi mode specific to the standard output stream.static java.lang.String
JANSI_PASSTHROUGH
Deprecated.useJANSI_MODE
insteadstatic java.lang.String
JANSI_STRIP
Deprecated.useJANSI_MODE
insteadstatic java.io.PrintStream
out
Deprecated.this field will be made private in a future release, useout()
insteadstatic java.io.PrintStream
system_err
Deprecated.this field will be made private in a future release, usesysErr()
insteadstatic java.io.PrintStream
system_out
Deprecated.this field will be made private in a future release, usesysOut()
insteadprivate static int
virtualProcessing
-
Constructor Summary
Constructors Modifier Constructor Description private
AnsiConsole()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description private static AnsiPrintStream
ansiStream(boolean stdout)
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.(package private) static boolean
getBoolean(java.lang.String name)
(package private) static void
initStreams()
Initialize the out/err ansi-enabled streamsstatic boolean
isInstalled()
check if the streams have been installed or notprivate static AnsiPrintStream
newPrintStream(AnsiOutputStream out, java.lang.String enc)
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.static java.io.PrintStream
sysErr()
Access to the original System.err stream before ansi streams were installed.static java.io.PrintStream
sysOut()
Access to the original System.out stream before ansi streams were installed.static void
systemInstall()
InstallAnsiConsole.out()
toSystem.out
andAnsiConsole.err()
toSystem.err
.static void
systemUninstall()
undo a previoussystemInstall()
.
-
-
-
Field Detail
-
JANSI_MODE
public static final java.lang.String 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:
- Constant Field Values
-
JANSI_OUT_MODE
public static final java.lang.String JANSI_OUT_MODE
Jansi mode specific to the standard output stream.- See Also:
- Constant Field Values
-
JANSI_ERR_MODE
public static final java.lang.String JANSI_ERR_MODE
Jansi mode specific to the standard error stream.- See Also:
- Constant Field Values
-
JANSI_MODE_STRIP
public static final java.lang.String JANSI_MODE_STRIP
Jansi mode value to strip all ansi sequences.- See Also:
- Constant Field Values
-
JANSI_MODE_FORCE
public static final java.lang.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 java.lang.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 java.lang.String 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:
- Constant Field Values
-
JANSI_OUT_COLORS
public static final java.lang.String JANSI_OUT_COLORS
Jansi colors specific to the standard output stream.- See Also:
- Constant Field Values
-
JANSI_ERR_COLORS
public static final java.lang.String JANSI_ERR_COLORS
Jansi colors specific to the standard error stream.- See Also:
- Constant Field Values
-
JANSI_COLORS_16
public static final java.lang.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 java.lang.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 java.lang.String JANSI_COLORS_TRUECOLOR
Force the use of 24-bit colors.- See Also:
- Constant Field Values
-
JANSI_PASSTHROUGH
@Deprecated public static final java.lang.String 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:
- Constant Field Values
-
JANSI_STRIP
@Deprecated public static final java.lang.String 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:
- Constant Field Values
-
JANSI_FORCE
@Deprecated public static final java.lang.String 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:
- Constant Field Values
-
JANSI_EAGER
@Deprecated public static final java.lang.String 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:
- Constant Field Values
-
JANSI_NORESET
public static final java.lang.String JANSI_NORESET
If thejansi.noreset
system property is set to true, the attributes won't be reset when the streams are uninstalled.- See Also:
- Constant Field Values
-
system_out
@Deprecated public static java.io.PrintStream system_out
Deprecated.this field will be made private in a future release, usesysOut()
instead
-
out
@Deprecated public static java.io.PrintStream out
Deprecated.this field will be made private in a future release, useout()
instead
-
system_err
@Deprecated public static java.io.PrintStream system_err
Deprecated.this field will be made private in a future release, usesysErr()
instead
-
err
@Deprecated public static java.io.PrintStream err
Deprecated.this field will be made private in a future release, useerr()
instead
-
IS_WINDOWS
static final boolean IS_WINDOWS
-
IS_CYGWIN
static final boolean IS_CYGWIN
-
IS_MSYSTEM
static final boolean IS_MSYSTEM
-
IS_CONEMU
static final boolean IS_CONEMU
-
ENABLE_VIRTUAL_TERMINAL_PROCESSING
static final int ENABLE_VIRTUAL_TERMINAL_PROCESSING
- See Also:
- Constant Field Values
-
initialized
private static boolean initialized
-
installed
private static int installed
-
virtualProcessing
private static int virtualProcessing
-
-
Method Detail
-
ansiStream
private static AnsiPrintStream ansiStream(boolean stdout)
-
newPrintStream
private static AnsiPrintStream newPrintStream(AnsiOutputStream out, java.lang.String enc)
-
getBoolean
static boolean getBoolean(java.lang.String name)
-
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 java.io.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 java.io.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.out
andAnsiConsole.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.
-
initStreams
static void initStreams()
Initialize the out/err ansi-enabled streams
-
-