Top Description Fields Constructors Methods
org.fusesource.jansi

public Class AnsiConsole

extends Object
Class Inheritance
Imports
java.io.FileDescriptor, .FileOutputStream, .IOError, .IOException, .OutputStream, .PrintStream, .UnsupportedEncodingException, java.nio.charset.Charset, .UnsupportedCharsetException, java.util.Locale, org.fusesource.jansi.internal.CLibrary, .CLibrary.WinSize, .Kernel32.CONSOLE_SCREEN_BUFFER_INFO, .MingwSupport, org.fusesource.jansi.io.AnsiOutputStream, .AnsiProcessor, .FastBufferedOutputStream, .WindowsAnsiProcessor

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
See Also
systemInstall(), out(), err(), for more details on ANSI mode selection

Field Summary

Modifier and TypeField and Description
pack-priv static final int
public static PrintStream
err

Deprecated this field will be made private in a future release, use err() instead
private static boolean
private static int
pack-priv static final boolean
pack-priv static final boolean
pack-priv static final boolean
pack-priv static final boolean
public static final String
JANSI_COLORS

The default color support that Jansi will use, can be either 16, 256 or truecolor.

public static final String
JANSI_COLORS_16

Force the use of 16 colors.

public static final String
JANSI_COLORS_256

Force the use of 256 colors.

public static final String
JANSI_COLORS_TRUECOLOR

Force the use of 24-bit colors.

public static final String
JANSI_EAGER

If the jansi.eager system property is set to true, the system streams will be eagerly initialized, else the initialization is delayed until out(), err() or systemInstall() is called.

public static final String
JANSI_ERR_COLORS

Jansi colors specific to the standard error stream.

public static final String
JANSI_ERR_MODE

Jansi mode specific to the standard error stream.

public static final String
JANSI_FORCE

If the jansi.force system property is set to true, and neither jansi.passthrough nor jansi.strip are set, then ansi sequences will be printed to the output stream.

public static final String
JANSI_GRACEFUL

If the jansi.graceful system property is set to false, any exception that occurs during the initialization will cause the library to report this exception and fail.

public static final String
JANSI_MODE

The default mode which Jansi will use, can be either force, strip or default (the default).

public static final String
JANSI_MODE_DEFAULT

Jansi mode value that output sequences if on a terminal, else strip them.

public static final String
JANSI_MODE_FORCE

Jansi mode value to force ansi sequences to the stream even if it's not a terminal.

public static final String
JANSI_MODE_STRIP

Jansi mode value to strip all ansi sequences.

public static final String
JANSI_NORESET

If the jansi.noreset system property is set to true, the attributes won't be reset when the streams are uninstalled.

public static final String
JANSI_OUT_COLORS

Jansi colors specific to the standard output stream.

public static final String
JANSI_OUT_MODE

Jansi mode specific to the standard output stream.

public static final String
JANSI_PASSTHROUGH

If the jansi.passthrough system property is set to true, will not perform any transformation and any ansi sequence will be conveyed without any modification.

public static final String
JANSI_STRIP

If the jansi.strip system property is set to true, and jansi.passthrough is not enabled, all ansi sequences will be stripped before characters are written to the output streams.

public static PrintStream
out

Deprecated this field will be made private in a future release, use out() instead
pack-priv static int
pack-priv static int
public static PrintStream
system_err

Deprecated this field will be made private in a future release, use sysErr() instead
public static PrintStream
system_out

Deprecated this field will be made private in a future release, use sysOut() instead
private static int

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
private static AnsiPrintStream
ansiStream(boolean stdout)

public static AnsiPrintStream

Returns:

a PrintStream which is ANSI aware.
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.

pack-priv static boolean
public static int
getTerminalWidth()

Try to find the width of the console for this process.

pack-priv static synchronized void
initStreams()

Initialize the out/err ansi-enabled streams

public static synchronized boolean
isInstalled()

check if the streams have been installed or not

private static AnsiPrintStream
public static AnsiPrintStream

Returns:

a PrintStream which is ANSI aware.
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.

public static PrintStream

Returns:

the originial System.err print stream
sysErr
()

Access to the original System.err stream before ansi streams were installed.

public static PrintStream

Returns:

the originial System.out print stream
sysOut
()

Access to the original System.out stream before ansi streams were installed.

public static synchronized void
systemInstall()

Install AnsiConsole.out() to System.out and AnsiConsole.err() to System.err.

public static synchronized void
systemUninstall()

undo a previous systemInstall().

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

ENABLE_VIRTUAL_TERMINAL_PROCESSINGback to summary
pack-priv static final int ENABLE_VIRTUAL_TERMINAL_PROCESSING
errback to summary
public static PrintStream err

Deprecated

this field will be made private in a future release, use err() instead

Annotations
@Deprecated
initializedback to summary
private static boolean initialized
installedback to summary
private static int installed
IS_CONEMUback to summary
pack-priv static final boolean IS_CONEMU
IS_CYGWINback to summary
pack-priv static final boolean IS_CYGWIN
IS_MSYSTEMback to summary
pack-priv static final boolean IS_MSYSTEM
IS_WINDOWSback to summary
pack-priv static final boolean IS_WINDOWS
JANSI_COLORSback to summary
public static final String JANSI_COLORS

The default color support that Jansi will use, can be either 16, 256 or truecolor. If not set, JANSI will try to autodetect the number of colors supported by the terminal by checking the COLORTERM and TERM variables.

JANSI_COLORS_16back to summary
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.

JANSI_COLORS_256back to summary
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.

JANSI_COLORS_TRUECOLORback to summary
public static final String JANSI_COLORS_TRUECOLOR

Force the use of 24-bit colors.

JANSI_EAGERback to summary
public static final String JANSI_EAGER

Deprecated

this property has been added but only for backward compatibility.

If the jansi.eager system property is set to true, the system streams will be eagerly initialized, else the initialization is delayed until out(), err() or systemInstall() is called.

Annotations
@Deprecated
Since
2.1
JANSI_ERR_COLORSback to summary
public static final String JANSI_ERR_COLORS

Jansi colors specific to the standard error stream.

JANSI_ERR_MODEback to summary
public static final String JANSI_ERR_MODE

Jansi mode specific to the standard error stream.

JANSI_FORCEback to summary
public static final String JANSI_FORCE

Deprecated

use JANSI_MODE instead

If the jansi.force system property is set to true, and neither jansi.passthrough nor jansi.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.

Annotations
@Deprecated
JANSI_GRACEFULback to summary
public static final String JANSI_GRACEFUL

If the jansi.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.

JANSI_MODEback to summary
public static final String JANSI_MODE

The default mode which Jansi will use, can be either force, strip or default (the default). If this property is set, it will override jansi.passthrough, jansi.strip and jansi.force properties.

JANSI_MODE_DEFAULTback to summary
public static final String JANSI_MODE_DEFAULT

Jansi mode value that output sequences if on a terminal, else strip them.

JANSI_MODE_FORCEback to summary
public static final String JANSI_MODE_FORCE

Jansi mode value to force ansi sequences to the stream even if it's not a terminal.

JANSI_MODE_STRIPback to summary
public static final String JANSI_MODE_STRIP

Jansi mode value to strip all ansi sequences.

JANSI_NORESETback to summary
public static final String JANSI_NORESET

If the jansi.noreset system property is set to true, the attributes won't be reset when the streams are uninstalled.

JANSI_OUT_COLORSback to summary
public static final String JANSI_OUT_COLORS

Jansi colors specific to the standard output stream.

JANSI_OUT_MODEback to summary
public static final String JANSI_OUT_MODE

Jansi mode specific to the standard output stream.

JANSI_PASSTHROUGHback to summary
public static final String JANSI_PASSTHROUGH

Deprecated

use JANSI_MODE instead

If the jansi.passthrough system property is set to true, will not perform any transformation and any ansi sequence will be conveyed without any modification.

Annotations
@Deprecated
JANSI_STRIPback to summary
public static final String JANSI_STRIP

Deprecated

use JANSI_MODE instead

If the jansi.strip system property is set to true, and jansi.passthrough is not enabled, all ansi sequences will be stripped before characters are written to the output streams.

Annotations
@Deprecated
outback to summary
public static PrintStream out

Deprecated

this field will be made private in a future release, use out() instead

Annotations
@Deprecated
STDERR_FILENOback to summary
pack-priv static int STDERR_FILENO
STDOUT_FILENOback to summary
pack-priv static int STDOUT_FILENO
system_errback to summary
public static PrintStream system_err

Deprecated

this field will be made private in a future release, use sysErr() instead

Annotations
@Deprecated
system_outback to summary
public static PrintStream system_out

Deprecated

this field will be made private in a future release, use sysOut() instead

Annotations
@Deprecated
virtualProcessingback to summary
private static int virtualProcessing

Constructor Detail

AnsiConsoleback to summary
private AnsiConsole()

Method Detail

ansiStreamback to summary
private static AnsiPrintStream ansiStream(boolean stdout)
errback to summary
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:AnsiPrintStream

a PrintStream which is ANSI aware.

getBooleanback to summary
pack-priv static boolean getBoolean(String name)
getTerminalWidthback to summary
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
initStreamsback to summary
pack-priv static synchronized void initStreams()

Initialize the out/err ansi-enabled streams

isInstalledback to summary
public static synchronized boolean isInstalled()

check if the streams have been installed or not

newPrintStreamback to summary
private static AnsiPrintStream newPrintStream(AnsiOutputStream out, String enc)
outback to summary
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:AnsiPrintStream

a PrintStream which is ANSI aware.

sysErrback to summary
public static PrintStream sysErr()

Access to the original System.err stream before ansi streams were installed.

Returns:PrintStream

the originial System.err print stream

sysOutback to summary
public static PrintStream sysOut()

Access to the original System.out stream before ansi streams were installed.

Returns:PrintStream

the originial System.out print stream

systemInstallback to summary
public static synchronized void systemInstall()

Install AnsiConsole.out() to System.out and AnsiConsole.err() to System.err.

See Also
systemUninstall()
systemUninstallback to summary
public static synchronized void systemUninstall()

undo a previous systemInstall(). If systemInstall() was called multiple times, systemUninstall() must be called the same number of times before it is actually uninstalled.