From 15163a4c61e03a696c32105c701267c87c13ad58 Mon Sep 17 00:00:00 2001 From: Richard North Date: Fri, 8 Jan 2016 14:47:36 +0000 Subject: [PATCH] Disable ANSI support when running in IntelliJ regardless of reported TTY support. As a result of this, no run output will be coloured in IntelliJ, but this seems marginally better than having output that is corrupt when viewed in certain modes. This is a workaround for issues described elsewhere: https://github.com/fusesource/jansi/issues/31 https://youtrack.jetbrains.com/issue/IDEA-132822 Refs #1 --- .../java/org/rnorth/visibleassertions/AnsiSupport.java | 10 ++++++++++ .../visibleassertions/VisibleAssertionsTest.java | 1 + 2 files changed, 11 insertions(+) diff --git a/src/main/java/org/rnorth/visibleassertions/AnsiSupport.java b/src/main/java/org/rnorth/visibleassertions/AnsiSupport.java index d0387ec..d5bdea8 100644 --- a/src/main/java/org/rnorth/visibleassertions/AnsiSupport.java +++ b/src/main/java/org/rnorth/visibleassertions/AnsiSupport.java @@ -17,6 +17,7 @@ package org.rnorth.visibleassertions; import jline.TerminalFactory; +import org.fusesource.jansi.Ansi; import org.fusesource.jansi.AnsiConsole; import java.io.PrintStream; @@ -35,6 +36,15 @@ public class AnsiSupport { static PrintStream writer = System.out; protected synchronized static void initialize() { + + try { + Class.forName("com.intellij.rt.execution.application.AppMain"); + // Running in IntelliJ - disable ANSI output + Ansi.setEnabled(false); + } catch (ClassNotFoundException e) { + // Not running in IntelliJ - assume TTY detection works correctly + } + AnsiConsole.systemInstall(); } diff --git a/src/test/java/org/rnorth/visibleassertions/VisibleAssertionsTest.java b/src/test/java/org/rnorth/visibleassertions/VisibleAssertionsTest.java index 30a41ac..10b74a1 100644 --- a/src/test/java/org/rnorth/visibleassertions/VisibleAssertionsTest.java +++ b/src/test/java/org/rnorth/visibleassertions/VisibleAssertionsTest.java @@ -44,6 +44,7 @@ public void setup() { @After public void outputForDebugging() { + System.out.println("CAPTURED STDOUT:"); System.out.println(getCapturedStdOut()); }