123 lines
4.1 KiB
Diff
123 lines
4.1 KiB
Diff
diff -urEbwB groovy-core-GROOVY_1_8_9/src/main/org/codehaus/groovy/tools/shell/IO.java groovy-core-GROOVY_1_8_9.new/src/main/org/codehaus/groovy/tools/shell/IO.java
|
|
--- groovy-core-GROOVY_1_8_9/src/main/org/codehaus/groovy/tools/shell/IO.java 2013-02-15 09:42:29.000000000 +0100
|
|
+++ groovy-core-GROOVY_1_8_9.new/src/main/org/codehaus/groovy/tools/shell/IO.java 2022-05-12 14:22:46.063512048 +0200
|
|
@@ -23,8 +23,8 @@
|
|
import java.io.PrintWriter;
|
|
import java.io.Reader;
|
|
|
|
+import org.codehaus.groovy.runtime.InvokerHelper;
|
|
import org.codehaus.groovy.tools.shell.util.Preferences;
|
|
-import org.fusesource.jansi.AnsiRenderWriter;
|
|
|
|
/**
|
|
* Container for input/output handles.
|
|
@@ -34,6 +34,8 @@
|
|
*/
|
|
public class IO
|
|
{
|
|
+ private static final String ANSI_RENDER_WRITER = "org.fusesource.jansi.AnsiRenderWriter";
|
|
+
|
|
/** Raw input stream. */
|
|
public final InputStream inputStream;
|
|
|
|
@@ -53,6 +55,11 @@
|
|
public final PrintWriter err;
|
|
|
|
/**
|
|
+ * Whether ansi support is available
|
|
+ */
|
|
+ public final boolean ansiSupported;
|
|
+
|
|
+ /**
|
|
* Construct a new IO container.
|
|
*/
|
|
public IO(final InputStream inputStream, final OutputStream outputStream, final OutputStream errorStream) {
|
|
@@ -65,8 +72,36 @@
|
|
this.errorStream = errorStream;
|
|
|
|
this.in = new InputStreamReader(inputStream);
|
|
- this.out = new AnsiRenderWriter(outputStream, true);
|
|
- this.err = new AnsiRenderWriter(errorStream, true);
|
|
+ boolean ansiSupported = false;
|
|
+ try {
|
|
+ Class.forName(ANSI_RENDER_WRITER, false, IO.class.getClassLoader());
|
|
+ ansiSupported = true;
|
|
+ } catch (ClassNotFoundException ignore) {
|
|
+ }
|
|
+ this.ansiSupported = ansiSupported;
|
|
+ PrintWriter out = null;
|
|
+ PrintWriter err = null;
|
|
+ if (ansiSupported) {
|
|
+ out = tryConstructRenderWriter(outputStream);
|
|
+ err = tryConstructRenderWriter(errorStream);
|
|
+ }
|
|
+ if (out == null) {
|
|
+ out = new PrintWriter(outputStream, true);
|
|
+ }
|
|
+ if (err == null) {
|
|
+ err = new PrintWriter(errorStream, true);
|
|
+ }
|
|
+ this.out = out;
|
|
+ this.err = err;
|
|
+ }
|
|
+
|
|
+ protected PrintWriter tryConstructRenderWriter(OutputStream stream) {
|
|
+ // load via reflection to avoid hard-coded dependency on jansi jar
|
|
+ try {
|
|
+ return (PrintWriter) InvokerHelper.invokeConstructorOf(ANSI_RENDER_WRITER, new Object[]{stream, true});
|
|
+ } catch (ClassNotFoundException ignore) {
|
|
+ return null;
|
|
+ }
|
|
}
|
|
|
|
/**
|
|
@@ -78,8 +113,6 @@
|
|
|
|
/**
|
|
* Set the verbosity level.
|
|
- *
|
|
- * @param verbosity
|
|
*/
|
|
public void setVerbosity(final Verbosity verbosity) {
|
|
assert verbosity != null;
|
|
diff -urEbwB groovy-core-GROOVY_1_8_9/src/main/org/codehaus/groovy/tools/shell/util/Logger.java groovy-core-GROOVY_1_8_9.new/src/main/org/codehaus/groovy/tools/shell/util/Logger.java
|
|
--- groovy-core-GROOVY_1_8_9/src/main/org/codehaus/groovy/tools/shell/util/Logger.java 2013-02-15 09:42:29.000000000 +0100
|
|
+++ groovy-core-GROOVY_1_8_9.new/src/main/org/codehaus/groovy/tools/shell/util/Logger.java 2022-05-12 14:03:06.980193451 +0200
|
|
@@ -56,13 +56,12 @@
|
|
}
|
|
}
|
|
|
|
- Color color = GREEN;
|
|
- if (WARN.equals(level) || ERROR.equals(level)) {
|
|
- color = RED;
|
|
+ if (io.ansiSupported) {
|
|
+ logWithAnsi(level, msg);
|
|
+ } else {
|
|
+ logDefault(level, msg);
|
|
}
|
|
|
|
- io.out.println(ansi().a(INTENSITY_BOLD).a(color).a(level).reset().a(" [").a(name).a("] ").a(msg));
|
|
-
|
|
if (cause != null) {
|
|
cause.printStackTrace(io.out);
|
|
}
|
|
@@ -74,6 +73,18 @@
|
|
}
|
|
}
|
|
|
|
+ private void logDefault(String level, Object msg) {
|
|
+ io.out.println(level + " [" + name + "] " + msg);
|
|
+ }
|
|
+
|
|
+ private void logWithAnsi(String level, Object msg) {
|
|
+ Color color = GREEN;
|
|
+ if (WARN.equals(level) || ERROR.equals(level)) {
|
|
+ color = RED;
|
|
+ }
|
|
+ io.out.println(ansi().a(INTENSITY_BOLD).fg(color).a(level).reset().a(" [").a(name).a("] ").a(msg));
|
|
+ }
|
|
+
|
|
//
|
|
// Level helpers
|
|
//
|