Minor: don't init AnsiConsole when coloring is disabled

This commit is contained in:
Zalim Bashorov
2016-02-04 14:36:00 +03:00
parent bcc3102e05
commit ba6c738cb5
2 changed files with 18 additions and 7 deletions
@@ -1,5 +1,5 @@
/*
* Copyright 2010-2015 JetBrains s.r.o.
* Copyright 2010-2016 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -130,16 +130,23 @@ public abstract class CLICompiler<A extends CommonCompilerArguments> {
MessageCollector collector = new PrintingMessageCollector(errStream, messageRenderer, arguments.verbose);
try {
AnsiConsole.systemInstall();
if (PlainTextMessageRenderer.COLOR_ENABLED) {
AnsiConsole.systemInstall();
}
errStream.print(messageRenderer.renderPreamble());
return exec(collector, services, arguments);
}
finally {
errStream.print(messageRenderer.renderConclusion());
AnsiConsole.systemUninstall();
if (PlainTextMessageRenderer.COLOR_ENABLED) {
AnsiConsole.systemUninstall();
}
}
}
@SuppressWarnings("WeakerAccess") // Used in maven (see KotlinCompileMojoBase.java)
@NotNull
public ExitCode exec(@NotNull MessageCollector messageCollector, @NotNull Services services, @NotNull A arguments) {
printVersionIfNeeded(messageCollector, arguments);
@@ -213,7 +220,7 @@ public abstract class CLICompiler<A extends CommonCompilerArguments> {
@NotNull Disposable rootDisposable
);
protected void printVersionIfNeeded(@NotNull MessageCollector messageCollector, @NotNull A arguments) {
private void printVersionIfNeeded(@NotNull MessageCollector messageCollector, @NotNull A arguments) {
if (!arguments.version) return;
messageCollector.report(CompilerMessageSeverity.INFO,
@@ -234,6 +241,7 @@ public abstract class CLICompiler<A extends CommonCompilerArguments> {
}
}
@SuppressWarnings("UseOfSystemOutOrSystemErr")
@NotNull
public static ExitCode doMainNoExit(@NotNull CLICompiler compiler, @NotNull String[] args) {
try {
@@ -1,5 +1,5 @@
/*
* Copyright 2010-2015 JetBrains s.r.o.
* Copyright 2010-2016 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -30,11 +30,14 @@ import java.util.Set;
import static org.jetbrains.kotlin.cli.common.messages.CompilerMessageSeverity.*;
public abstract class PlainTextMessageRenderer implements MessageRenderer {
private static final String KOTLIN_COLORS_ENABLED_PROPERTY = "kotlin.colors.enabled";
// AnsiConsole doesn't check isatty() for stderr (see https://github.com/fusesource/jansi/pull/35).
// TODO: investigate why ANSI escape codes on Windows only work in REPL for some reason
private static final boolean COLOR_ENABLED =
public static final boolean COLOR_ENABLED =
!SystemInfo.isWindows &&
!"false".equals(System.getProperty("kotlin.colors.enabled")) &&
!"false".equals(System.getProperty(KOTLIN_COLORS_ENABLED_PROPERTY)) &&
CLibrary.isatty(CLibrary.STDERR_FILENO) != 0;
private static final String LINE_SEPARATOR = LineSeparator.getSystemLineSeparator().getSeparatorString();