Skip to content

Commit 48b0be5

Browse files
committed
improved diagnostic output
1 parent 68c5810 commit 48b0be5

File tree

2 files changed

+32
-14
lines changed

2 files changed

+32
-14
lines changed

jansi/src/main/java/org/fusesource/jansi/AnsiConsole.java

+18-6
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
* @author <a href="http://hiramchirino.com">Hiram Chirino</a>
3232
* @since 1.0
3333
* @see #wrapPrintStream(PrintStream, int)
34+
* @see #systemInstall()
3435
*/
3536
public class AnsiConsole {
3637

@@ -268,7 +269,8 @@ public static PrintStream err() {
268269
}
269270

270271
/**
271-
* Install Console.out to System.out.
272+
* Install <code>AnsiConsole.out</code> to <code>System.out</code> and
273+
* <code>AnsiConsole.err</code> to <code>System.err</code>.
272274
*/
273275
synchronized static public void systemInstall() {
274276
installed++;
@@ -295,10 +297,20 @@ synchronized public static void systemUninstall() {
295297
* Type of output installed by AnsiConsole.
296298
*/
297299
enum JansiOutputType {
298-
PASSTHROUGH, // just pass through, ANSI escape codes are supposed to be supported by terminal
299-
STRIP_ANSI, // strip ANSI escape codes (since not a terminal)
300-
WINDOWS, // detect ANSI escape codes and transform Jansi-supported ones into a Windows API to get desired effect
301-
// (since ANSI escape codes are not natively supported by Windows terminals like cmd.exe or PowerShell)
302-
RESET_ANSI_AT_CLOSE // like pass through but reset ANSI attributes when closing
300+
PASSTHROUGH("just pass through, ANSI escape codes are supposed to be supported by terminal"),
301+
RESET_ANSI_AT_CLOSE("like pass through but reset ANSI attributes when closing the stream"),
302+
STRIP_ANSI("strip ANSI escape codes, for example when output is not a terminal"),
303+
WINDOWS("detect ANSI escape codes and transform Jansi-supported ones into a Windows API to get desired effect" +
304+
" (since ANSI escape codes are not natively supported by Windows terminals like cmd.exe or PowerShell)");
305+
306+
private final String description;
307+
308+
private JansiOutputType(String description) {
309+
this.description = description;
310+
}
311+
312+
String getDescription() {
313+
return description;
314+
}
303315
};
304316
}

jansi/src/main/java/org/fusesource/jansi/AnsiMain.java

+14-8
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,9 @@ public static void main(String... args) throws IOException {
4747
System.out.println("library.jansi.version= " + System.getProperty("library.jansi.version", ""));
4848
Library lib = new Library("jansi", CLibrary.class);
4949
lib.load();
50-
System.out.println("path: " + lib.getNativeLibraryPath());
50+
System.out.println("Jansi native library loaded from " + lib.getNativeLibraryPath());
5151
if (lib.getNativeLibrarySourceUrl() != null) {
52-
System.out.println("auto-extracted from: " + lib.getNativeLibrarySourceUrl());
52+
System.out.println(" which was auto-extracted from " + lib.getNativeLibrarySourceUrl());
5353
}
5454

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

7272
System.out.println();
7373

74-
System.out.println("IS_WINDOWS= " + AnsiConsole.IS_WINDOWS);
74+
System.out.println("IS_WINDOWS: " + AnsiConsole.IS_WINDOWS);
7575
if (AnsiConsole.IS_WINDOWS) {
76-
System.out.println("IS_CYGWIN= " + AnsiConsole.IS_CYGWIN);
77-
System.out.println("IS_MINGW= " + AnsiConsole.IS_MINGW);
76+
System.out.println("IS_CYGWIN: " + AnsiConsole.IS_CYGWIN);
77+
System.out.println("IS_MINGW: " + AnsiConsole.IS_MINGW);
7878
}
7979

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

8787
System.out.println();
8888

89-
System.out.println("Jansi System.out mode: " + AnsiConsole.JANSI_STDOUT_TYPE);
90-
System.out.println("Jansi System.err mode: " + AnsiConsole.JANSI_STDERR_TYPE);
89+
System.out.println("Resulting Jansi modes for stout/stderr streams:");
90+
System.out.println(" - System.out: " + AnsiConsole.JANSI_STDOUT_TYPE);
91+
System.out.println(" - System.err: " + AnsiConsole.JANSI_STDERR_TYPE);
92+
System.out.println("modes description:");
93+
int n = 1;
94+
for(AnsiConsole.JansiOutputType type: AnsiConsole.JansiOutputType.values()) {
95+
System.out.println(n++ + ". " + type + ": " + type.getDescription());
96+
}
9197

9298
try {
9399
System.out.println();
@@ -141,7 +147,7 @@ private static void diagnoseTty(boolean stderr) {
141147
int fd = stderr ? CLibrary.STDERR_FILENO : CLibrary.STDOUT_FILENO;
142148
int isatty = isatty(fd);
143149

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

0 commit comments

Comments
 (0)