From 25ed28fb5f4f03a480017da242e7dacf8afb81fc Mon Sep 17 00:00:00 2001 From: Sebastian Schuberth Date: Mon, 9 May 2016 15:18:00 +0200 Subject: [PATCH 1/2] Rename isCygwin() to isXterm() Strictly speaking this method does not check for Cygwin (as it e.g. does not check to be on Windows) but only for XTerm (which in conjunction with being on Windows is a sign of running under Cygwin). Simplify the code a bit to get rid of the explicit null check long the way. --- .../src/main/java/org/fusesource/jansi/AnsiConsole.java | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/jansi/src/main/java/org/fusesource/jansi/AnsiConsole.java b/jansi/src/main/java/org/fusesource/jansi/AnsiConsole.java index 31b6b50c..3d16cfec 100644 --- a/jansi/src/main/java/org/fusesource/jansi/AnsiConsole.java +++ b/jansi/src/main/java/org/fusesource/jansi/AnsiConsole.java @@ -85,7 +85,7 @@ public static OutputStream wrapOutputStream(final OutputStream stream, int filen } String os = System.getProperty("os.name"); - if (os.startsWith("Windows") && !isCygwin()) { + if (os.startsWith("Windows") && !isXterm()) { // On windows we know the console does not interpret ANSI codes.. try { @@ -107,7 +107,7 @@ public static OutputStream wrapOutputStream(final OutputStream stream, int filen // If we can detect that stdout is not a tty.. then setup // to strip the ANSI sequences.. int rc = isatty(fileno); - if (!isCygwin() && !forceColored && rc == 0) { + if (!isXterm() && !forceColored && rc == 0) { return new AnsiOutputStream(stream); } @@ -129,9 +129,8 @@ public void close() throws IOException { }; } - private static boolean isCygwin() { - String term = System.getenv("TERM"); - return term != null && term.equals("xterm"); + private static boolean isXterm() { + return "xterm".equals(System.getenv("TERM")); } /** From e180ab10d58fbe5cd0624cb6fca443449df1a982 Mon Sep 17 00:00:00 2001 From: Sebastian Schuberth Date: Mon, 9 May 2016 14:47:57 +0200 Subject: [PATCH 2/2] Add the README's example as a separate project This provides a minimal test executable for quickly trying out JAnsi. Run it like $ mvn --projects example exec:java --- example/pom.xml | 43 +++++++++++++++++++ .../main/java/org/fusesource/jansi/Main.java | 12 ++++++ pom.xml | 1 + 3 files changed, 56 insertions(+) create mode 100644 example/pom.xml create mode 100644 example/src/main/java/org/fusesource/jansi/Main.java diff --git a/example/pom.xml b/example/pom.xml new file mode 100644 index 00000000..ed496fd5 --- /dev/null +++ b/example/pom.xml @@ -0,0 +1,43 @@ + + + + jansi-project + org.fusesource.jansi + 1.13-SNAPSHOT + + 4.0.0 + + example + + + + org.fusesource.jansi + jansi + ${project.parent.version} + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + + 1.5 + 1.5 + + + + org.codehaus.mojo + exec-maven-plugin + 1.4.0 + + org.fusesource.jansi.Main + + + + + + diff --git a/example/src/main/java/org/fusesource/jansi/Main.java b/example/src/main/java/org/fusesource/jansi/Main.java new file mode 100644 index 00000000..a90860a5 --- /dev/null +++ b/example/src/main/java/org/fusesource/jansi/Main.java @@ -0,0 +1,12 @@ +package org.fusesource.jansi; + +import static org.fusesource.jansi.Ansi.*; +import static org.fusesource.jansi.Ansi.Color.*; + +public class Main { + public static void main(String[] args) { + AnsiConsole.systemInstall(); + System.out.println( ansi().eraseScreen().fg(RED).a("Hello").fg(GREEN).a(" World").reset() ); + AnsiConsole.systemUninstall(); + } +} diff --git a/pom.xml b/pom.xml index 55efa2f8..0425ae39 100644 --- a/pom.xml +++ b/pom.xml @@ -316,6 +316,7 @@ jansi + example