Package org.jline.jansi
Class AnsiConsole
- java.lang.Object
-
- org.jline.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 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_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_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.static 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_PROVIDER_FFM
The name of theffm
provider.static java.lang.String
JANSI_PROVIDER_JNI
The name of thejni
provider.static java.lang.String
JANSI_PROVIDER_NATIVE_IMAGE
The name of thenative-image
provider.static java.lang.String
JANSI_PROVIDERS
Thejansi.providers
system property can be set to control which internal provider will be used.
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description 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.static org.jline.terminal.Terminal
getTerminal()
static int
getTerminalWidth()
Try to find the width of the console for this process.static boolean
isInstalled()
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 void
setTerminal(org.jline.terminal.Terminal terminal)
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_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
-
JANSI_GRACEFUL
public static final java.lang.String 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:
- Constant Field Values
-
JANSI_PROVIDERS
public static final java.lang.String JANSI_PROVIDERS
Thejansi.providers
system property can be set to control which internal provider will be used. If this property is not set, theffm
provider will be used if available, else thejni
one will be used. If set, this property is interpreted as a comma separated list of provider names to try in order.- See Also:
- Constant Field Values
-
JANSI_PROVIDER_JNI
public static final java.lang.String JANSI_PROVIDER_JNI
The name of thejni
provider.- See Also:
- Constant Field Values
-
JANSI_PROVIDER_FFM
public static final java.lang.String JANSI_PROVIDER_FFM
The name of theffm
provider.- See Also:
- Constant Field Values
-
JANSI_PROVIDER_NATIVE_IMAGE
public static final java.lang.String JANSI_PROVIDER_NATIVE_IMAGE
The name of thenative-image
provider.This provider uses the Native Image C API to call native functions, so it is only available when building to native image. Additionally, this provider currently does not support Windows.
Note: This is not the only provider available on Native Image, and it is usually recommended to use ffm or jni provider. This provider is mainly used when building static native images linked to musl libc.
- See Also:
- Constant Field Values
-
-
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
-
getTerminal
public static org.jline.terminal.Terminal getTerminal()
-
setTerminal
public static void setTerminal(org.jline.terminal.Terminal terminal)
-
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.
-
-