private void initializeColor(boolean useColor) { // sl4j simple logger used by Maven seems to escape ANSI escapes on Windows this.useAnsi = useColor && System.console() != null && !log.isDebugEnabled() && !isWindows(); if (useAnsi) { AnsiConsole.systemInstall(); Ansi.setEnabled(true); } else { Ansi.setEnabled(false); } }
/** * Hook method that allows controlling whether or not output streams should be wrapped by * AnsiConsole.wrapOutputStream. Unfortunately, Eclipse consoles will look to the AnsiWrap * like they do not understand ansi, even if we were to implement support in Eclipse to' * handle it and the wrapped stream will not pass the ansi chars on to Eclipse). * * @param out The output stream * @return The output stream wrapped an as {@link AnsiConsole} */ protected OutputStream ansiWrap(OutputStream out) { return AnsiConsole.wrapOutputStream(out); }
public static void main(String[] args) { // Since https://github.com/remkop/picocli/issues/491 was fixed in picocli 3.6.0, // Ansi.AUTO is automatically enabled if the AnsiConsole is installed. AnsiConsole.systemInstall(); // Jansi magic CommandLine.run(new WindowsJansiDemo(), System.out, Ansi.AUTO, args); AnsiConsole.systemUninstall(); } }
private static void doSystemUninstall() { if ( JANSI ) { AnsiConsole.systemUninstall(); } }
public Context() { this(AnsiConsole.out()); }
/** * Undo a previous {@link #systemInstall()}. If {@link #systemInstall()} was called * multiple times, {@link #systemUninstall()} must be called call the same number of times before * it is actually uninstalled. */ public static void systemUninstall() { if ( JANSI ) { AnsiConsole.systemUninstall(); } }
public ConsoleInteractorImpl(BasicOptions options) { console = System.console(); if (console == null && options.isInteractiveMode()) { throw new RuntimeException("Console not available: please run from a console, or use batch mode."); } out = AnsiConsole.out(); }
AnsiConsole.systemInstall();
@Test public void testAnsiEnabled() { assertTrue(Ansi.ON.enabled()); assertFalse(Ansi.OFF.enabled()); System.setProperty("picocli.ansi", "true"); assertEquals(true, Ansi.AUTO.enabled()); System.setProperty("picocli.ansi", "false"); assertEquals(false, Ansi.AUTO.enabled()); System.clearProperty("picocli.ansi"); boolean isWindows = System.getProperty("os.name").startsWith("Windows"); boolean isXterm = System.getenv("TERM") != null && System.getenv("TERM").startsWith("xterm"); boolean hasOsType = System.getenv("OSTYPE") != null; // null on Windows unless on Cygwin or MSYS boolean isAtty = (isWindows && (isXterm || hasOsType)) // cygwin pseudo-tty || hasConsole(); assertEquals((isAtty && (!isWindows || isXterm || hasOsType)) || isJansiConsoleInstalled(), Ansi.AUTO.enabled()); if (isWindows && !Ansi.AUTO.enabled()) { AnsiConsole.systemInstall(); try { assertTrue(Ansi.AUTO.enabled()); } finally { AnsiConsole.systemUninstall(); } } }
private static boolean detectAnsiSupport() { OutputStream out = AnsiConsole.wrapOutputStream(new ByteArrayOutputStream()); try { out.close(); } catch (Exception e) { // ignore; } return out instanceof WindowsAnsiOutputStream; }
@Override public void shutdown() { AnsiConsole.systemUninstall(); } }
public ConsoleInteractorImpl(BasicOptions options) { console = System.console(); if (console == null && options.isInteractiveMode()) { throw new RuntimeException("Console not available: please run from a console, or use batch mode."); } out = AnsiConsole.out(); }
private void setupColors() { AnsiConsole.systemInstall();
@Test public void testAnsiAutoJansiConsoleInstalledOverridesHintDisabled() { environmentVariables.clear(ANSI_ENVIRONMENT_VARIABLES); environmentVariables.set("CLICOLOR", "0"); // hint disabled System.setProperty("os.name", "Windows"); assertTrue(Ansi.isWindows()); assertFalse(Ansi.isPseudoTTY()); assertFalse(Ansi.forceDisabled()); assertFalse(Ansi.forceEnabled()); assertTrue(Ansi.hintDisabled()); assertFalse(Ansi.hintEnabled()); assertFalse(Ansi.isJansiConsoleInstalled()); AnsiConsole.systemInstall(); try { assertTrue(Ansi.isJansiConsoleInstalled()); assertTrue(Ansi.AUTO.enabled()); } finally { AnsiConsole.systemUninstall(); } }
/** * Hook method that allows controlling whether or not output streams should be wrapped by * AnsiConsole.wrapOutputStream. Unfortunately, Eclipse consoles will look to the AnsiWrap * like they do not understand ansi, even if we were to implement support in Eclipse to' * handle it and the wrapped stream will not pass the ansi chars on to Eclipse). */ protected OutputStream ansiWrap(OutputStream out) { return AnsiConsole.wrapOutputStream(out); }
AnsiConsole.systemInstall(); consoleReader = new ConsoleReader(); consoleReader.setExpandEvents( false );
@Override protected void printClear() { AnsiConsole.systemInstall(); Ansi ansi = Ansi.ansi(); System.out.println( ansi.eraseScreen() ); System.out.println( ansi.cursor(0, 0) ); AnsiConsole.systemUninstall(); }
@Deprecated public static OutputStream wrapErrorOutputStream(final OutputStream stream) { try { return wrapOutputStream(stream, STDERR_FILENO); } catch (Throwable ignore) { return wrapOutputStream(stream, 2); } }
@CliCommand(value = { "cls", "clear" }, help = "Clears the console") public void clear() { AnsiConsole.out().print(ansi().eraseScreen().cursor(0, 0)); }