Skip to content

Commit

Permalink
improved diagnostic output
Browse files Browse the repository at this point in the history
  • Loading branch information
hboutemy committed Apr 14, 2018
1 parent 68c5810 commit 48b0be5
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 14 deletions.
24 changes: 18 additions & 6 deletions jansi/src/main/java/org/fusesource/jansi/AnsiConsole.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
* @author <a href="http://hiramchirino.com">Hiram Chirino</a>
* @since 1.0
* @see #wrapPrintStream(PrintStream, int)
* @see #systemInstall()
*/
public class AnsiConsole {

Expand Down Expand Up @@ -268,7 +269,8 @@ public static PrintStream err() {
}

/**
* Install Console.out to System.out.
* Install <code>AnsiConsole.out</code> to <code>System.out</code> and
* <code>AnsiConsole.err</code> to <code>System.err</code>.
*/
synchronized static public void systemInstall() {
installed++;
Expand All @@ -295,10 +297,20 @@ synchronized public static void systemUninstall() {
* Type of output installed by AnsiConsole.
*/
enum JansiOutputType {
PASSTHROUGH, // just pass through, ANSI escape codes are supposed to be supported by terminal
STRIP_ANSI, // strip ANSI escape codes (since not a terminal)
WINDOWS, // detect ANSI escape codes and transform Jansi-supported ones into a Windows API to get desired effect
// (since ANSI escape codes are not natively supported by Windows terminals like cmd.exe or PowerShell)
RESET_ANSI_AT_CLOSE // like pass through but reset ANSI attributes when closing
PASSTHROUGH("just pass through, ANSI escape codes are supposed to be supported by terminal"),
RESET_ANSI_AT_CLOSE("like pass through but reset ANSI attributes when closing the stream"),
STRIP_ANSI("strip ANSI escape codes, for example when output is not a terminal"),
WINDOWS("detect ANSI escape codes and transform Jansi-supported ones into a Windows API to get desired effect" +
" (since ANSI escape codes are not natively supported by Windows terminals like cmd.exe or PowerShell)");

private final String description;

private JansiOutputType(String description) {
this.description = description;
}

String getDescription() {
return description;
}
};
}
22 changes: 14 additions & 8 deletions jansi/src/main/java/org/fusesource/jansi/AnsiMain.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ public static void main(String... args) throws IOException {
System.out.println("library.jansi.version= " + System.getProperty("library.jansi.version", ""));
Library lib = new Library("jansi", CLibrary.class);
lib.load();
System.out.println("path: " + lib.getNativeLibraryPath());
System.out.println("Jansi native library loaded from " + lib.getNativeLibraryPath());
if (lib.getNativeLibrarySourceUrl() != null) {
System.out.println("auto-extracted from: " + lib.getNativeLibrarySourceUrl());
System.out.println(" which was auto-extracted from " + lib.getNativeLibrarySourceUrl());
}

System.out.println();
Expand All @@ -71,10 +71,10 @@ public static void main(String... args) throws IOException {

System.out.println();

System.out.println("IS_WINDOWS= " + AnsiConsole.IS_WINDOWS);
System.out.println("IS_WINDOWS: " + AnsiConsole.IS_WINDOWS);
if (AnsiConsole.IS_WINDOWS) {
System.out.println("IS_CYGWIN= " + AnsiConsole.IS_CYGWIN);
System.out.println("IS_MINGW= " + AnsiConsole.IS_MINGW);
System.out.println("IS_CYGWIN: " + AnsiConsole.IS_CYGWIN);
System.out.println("IS_MINGW: " + AnsiConsole.IS_MINGW);
}

System.out.println();
Expand All @@ -86,8 +86,14 @@ public static void main(String... args) throws IOException {

System.out.println();

System.out.println("Jansi System.out mode: " + AnsiConsole.JANSI_STDOUT_TYPE);
System.out.println("Jansi System.err mode: " + AnsiConsole.JANSI_STDERR_TYPE);
System.out.println("Resulting Jansi modes for stout/stderr streams:");
System.out.println(" - System.out: " + AnsiConsole.JANSI_STDOUT_TYPE);
System.out.println(" - System.err: " + AnsiConsole.JANSI_STDERR_TYPE);
System.out.println("modes description:");
int n = 1;
for(AnsiConsole.JansiOutputType type: AnsiConsole.JansiOutputType.values()) {
System.out.println(n++ + ". " + type + ": " + type.getDescription());
}

try {
System.out.println();
Expand Down Expand Up @@ -141,7 +147,7 @@ private static void diagnoseTty(boolean stderr) {
int fd = stderr ? CLibrary.STDERR_FILENO : CLibrary.STDOUT_FILENO;
int isatty = isatty(fd);

System.out.println("isatty(STD" + (stderr ? "ERR" : "OUT") + "_FILENO)= " + isatty + ", System."
System.out.println("isatty(STD" + (stderr ? "ERR" : "OUT") + "_FILENO): " + isatty + ", System."
+ (stderr ? "err" : "out") + " " + ((isatty == 0) ? "is *NOT*" : "is") + " a terminal");
}

Expand Down

0 comments on commit 48b0be5

Please sign in to comment.