Minor: don't init AnsiConsole when coloring is disabled
This commit is contained in:
@@ -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");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with 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);
|
MessageCollector collector = new PrintingMessageCollector(errStream, messageRenderer, arguments.verbose);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
AnsiConsole.systemInstall();
|
if (PlainTextMessageRenderer.COLOR_ENABLED) {
|
||||||
|
AnsiConsole.systemInstall();
|
||||||
|
}
|
||||||
|
|
||||||
errStream.print(messageRenderer.renderPreamble());
|
errStream.print(messageRenderer.renderPreamble());
|
||||||
return exec(collector, services, arguments);
|
return exec(collector, services, arguments);
|
||||||
}
|
}
|
||||||
finally {
|
finally {
|
||||||
errStream.print(messageRenderer.renderConclusion());
|
errStream.print(messageRenderer.renderConclusion());
|
||||||
AnsiConsole.systemUninstall();
|
|
||||||
|
if (PlainTextMessageRenderer.COLOR_ENABLED) {
|
||||||
|
AnsiConsole.systemUninstall();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("WeakerAccess") // Used in maven (see KotlinCompileMojoBase.java)
|
||||||
@NotNull
|
@NotNull
|
||||||
public ExitCode exec(@NotNull MessageCollector messageCollector, @NotNull Services services, @NotNull A arguments) {
|
public ExitCode exec(@NotNull MessageCollector messageCollector, @NotNull Services services, @NotNull A arguments) {
|
||||||
printVersionIfNeeded(messageCollector, arguments);
|
printVersionIfNeeded(messageCollector, arguments);
|
||||||
@@ -213,7 +220,7 @@ public abstract class CLICompiler<A extends CommonCompilerArguments> {
|
|||||||
@NotNull Disposable rootDisposable
|
@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;
|
if (!arguments.version) return;
|
||||||
|
|
||||||
messageCollector.report(CompilerMessageSeverity.INFO,
|
messageCollector.report(CompilerMessageSeverity.INFO,
|
||||||
@@ -234,6 +241,7 @@ public abstract class CLICompiler<A extends CommonCompilerArguments> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("UseOfSystemOutOrSystemErr")
|
||||||
@NotNull
|
@NotNull
|
||||||
public static ExitCode doMainNoExit(@NotNull CLICompiler compiler, @NotNull String[] args) {
|
public static ExitCode doMainNoExit(@NotNull CLICompiler compiler, @NotNull String[] args) {
|
||||||
try {
|
try {
|
||||||
|
|||||||
+6
-3
@@ -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");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with 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.*;
|
import static org.jetbrains.kotlin.cli.common.messages.CompilerMessageSeverity.*;
|
||||||
|
|
||||||
public abstract class PlainTextMessageRenderer implements MessageRenderer {
|
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).
|
// 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
|
// 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 &&
|
!SystemInfo.isWindows &&
|
||||||
!"false".equals(System.getProperty("kotlin.colors.enabled")) &&
|
!"false".equals(System.getProperty(KOTLIN_COLORS_ENABLED_PROPERTY)) &&
|
||||||
CLibrary.isatty(CLibrary.STDERR_FILENO) != 0;
|
CLibrary.isatty(CLibrary.STDERR_FILENO) != 0;
|
||||||
|
|
||||||
private static final String LINE_SEPARATOR = LineSeparator.getSystemLineSeparator().getSeparatorString();
|
private static final String LINE_SEPARATOR = LineSeparator.getSystemLineSeparator().getSeparatorString();
|
||||||
|
|||||||
Reference in New Issue
Block a user