picocli.jansi.graalvm.AnsiConsole Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of picocli-jansi-graalvm Show documentation
Show all versions of picocli-jansi-graalvm Show documentation
${rootProject.name} - Create native Windows executable command line applications with colors in Java.
package picocli.jansi.graalvm;
import java.io.OutputStream;
import java.io.PrintStream;
/**
* Enables the use of ANSI escape codes in GraalVM native image applications,
* especially, but not limited to, running on Windows.
*
* Each method in this class calls {@link Workaround#enableLibraryLoad()}
* before delegating to the corresponding method in the
* {@code org.fusesource.jansi.AnsiConsole} class.
* This works around a problem in Jansi's
* org.fusesource.hawtjni.runtime.Library
* that prevents the native libraries embedded in the Jansi JAR in
* /META-INF/native/*
from being loaded
* when running in a GraalVM native image.
*
*
* Usage: use this class as a drop-in replacement for
* org.fusesource.jansi.AnsiConsole
.
*
*/
public class AnsiConsole {
private AnsiConsole() {
}
/**
* Install AnsiConsole.out
to System.out
and
* AnsiConsole.err
to System.err
.
*
* @see #systemUninstall()
*/
synchronized public static void systemInstall() {
Workaround.enableLibraryLoad();
org.fusesource.jansi.AnsiConsole.systemInstall();
}
/**
* undo a previous {@link #systemInstall()}. If {@link #systemInstall()} was called
* multiple times, {@link #systemUninstall()} must be called the same number of times before
* it is actually uninstalled.
*/
synchronized public static void systemUninstall() {
Workaround.enableLibraryLoad();
org.fusesource.jansi.AnsiConsole.systemUninstall();
}
@Deprecated
public static OutputStream wrapOutputStream(final OutputStream stream) {
Workaround.enableLibraryLoad();
return org.fusesource.jansi.AnsiConsole.wrapOutputStream(stream);
}
public static PrintStream wrapSystemOut(final PrintStream ps) {
Workaround.enableLibraryLoad();
return org.fusesource.jansi.AnsiConsole.wrapSystemOut(ps);
}
@Deprecated
public static OutputStream wrapErrorOutputStream(final OutputStream stream) {
Workaround.enableLibraryLoad();
return org.fusesource.jansi.AnsiConsole.wrapErrorOutputStream(stream);
}
public static PrintStream wrapSystemErr(final PrintStream ps) {
Workaround.enableLibraryLoad();
return org.fusesource.jansi.AnsiConsole.wrapSystemErr(ps);
}
@Deprecated
public static OutputStream wrapOutputStream(final OutputStream stream, int fileno) {
Workaround.enableLibraryLoad();
return org.fusesource.jansi.AnsiConsole.wrapOutputStream(stream, fileno);
}
/**
* Wrap PrintStream applying rules in following order:
* - if
jansi.passthrough
is true
, don't wrap but just passthrough (console is
* expected to natively support ANSI escape codes),
* - if
jansi.strip
is true
, just strip ANSI escape codes inconditionally,
* - if OS is Windows and terminal is not Cygwin or Mingw, wrap as WindowsAnsiPrintStream to process ANSI escape codes,
* - if file descriptor is a terminal (see
isatty(int)
) or jansi.force
is true
,
* just passthrough,
* - else strip ANSI escape codes (not a terminal).
*
*
* @param ps original PrintStream to wrap
* @param fileno file descriptor
* @return wrapped PrintStream depending on OS and system properties
*/
public static PrintStream wrapPrintStream(final PrintStream ps, int fileno) {
Workaround.enableLibraryLoad();
return org.fusesource.jansi.AnsiConsole.wrapPrintStream(ps, fileno);
}
/**
* 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.
*
* @return a PrintStream which is ANSI aware.
* @see #wrapPrintStream(PrintStream, int)
*/
public static PrintStream out() {
Workaround.enableLibraryLoad();
return org.fusesource.jansi.AnsiConsole.out();
}
/**
* 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.
*
* @return a PrintStream which is ANSI aware.
* @see #wrapPrintStream(PrintStream, int)
*/
public static PrintStream err() {
Workaround.enableLibraryLoad();
return org.fusesource.jansi.AnsiConsole.err();
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy