CLI: disable colors on platforms unsupported by jansi

#KT-10605 Fixed
This commit is contained in:
Alexander Udalov
2016-02-02 09:31:01 +05:30
committed by Alexander Udalov
parent 2e13377d4a
commit 7a6cc71454
@@ -30,15 +30,22 @@ 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 {
public static final boolean COLOR_ENABLED;
private static final String KOTLIN_COLORS_ENABLED_PROPERTY = "kotlin.colors.enabled"; static {
boolean colorEnabled = false;
// 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 if (!SystemInfo.isWindows && !"false".equals(System.getProperty("kotlin.colors.enabled"))) {
public static final boolean COLOR_ENABLED = try {
!SystemInfo.isWindows && // AnsiConsole doesn't check isatty() for stderr (see https://github.com/fusesource/jansi/pull/35).
!"false".equals(System.getProperty(KOTLIN_COLORS_ENABLED_PROPERTY)) && colorEnabled = CLibrary.isatty(CLibrary.STDERR_FILENO) != 0;
CLibrary.isatty(CLibrary.STDERR_FILENO) != 0; }
catch (UnsatisfiedLinkError e) {
colorEnabled = false;
}
}
COLOR_ENABLED = colorEnabled;
}
private static final String LINE_SEPARATOR = LineSeparator.getSystemLineSeparator().getSeparatorString(); private static final String LINE_SEPARATOR = LineSeparator.getSystemLineSeparator().getSeparatorString();