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 jansi and is loaded using HawtJNI Runtime Library

Since:
1.0
See Also:
  • Field Details

  • Constructor Details

    • AnsiConsole

      private AnsiConsole()
  • Method Details

    • wrapOutputStream

      @Deprecated public static OutputStream wrapOutputStream(OutputStream stream)
      Deprecated.
    • wrapSystemOut

      public static PrintStream wrapSystemOut(PrintStream ps)
    • wrapErrorOutputStream

      @Deprecated public static OutputStream wrapErrorOutputStream(OutputStream stream)
      Deprecated.
    • wrapSystemErr

      public static PrintStream wrapSystemErr(PrintStream ps)
    • wrapOutputStream

      @Deprecated public static OutputStream wrapOutputStream(OutputStream stream, int fileno)
      Deprecated.
    • wrapPrintStream

      public static PrintStream wrapPrintStream(PrintStream ps, int 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).
      Parameters:
      ps - original PrintStream to wrap
      fileno - file descriptor
      Returns:
      wrapped PrintStream depending on OS and system properties
      Since:
      1.17
    • out

      public static PrintStream 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.
      See Also:
    • err

      public static PrintStream 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.
      See Also:
    • systemInstall

      public static void systemInstall()
      Install AnsiConsole.out to System.out and AnsiConsole.err to System.err.
      See Also:
    • systemUninstall

      public static 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.