Skip to content

Commit 0484150

Browse files
committed
diagnose isatty for both stdout and stderr
1 parent e35a57f commit 0484150

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

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

+10-6
Original file line numberDiff line numberDiff line change
@@ -79,12 +79,8 @@ public static void main(String... args) throws IOException {
7979

8080
System.out.println();
8181

82-
int isattyValueReturned = isatty(CLibrary.STDOUT_FILENO);
83-
if( isattyValueReturned == 0 ) {
84-
System.out.println("stdout is *NOT* a TTY, 'isatty' has a value of " + isattyValueReturned);
85-
} else {
86-
System.out.println("stdout *IS* a TTY, 'isatty' has a value of " + isattyValueReturned);
87-
}
82+
diagnoseTty(false); // System.out
83+
diagnoseTty(true); // System.err
8884

8985
AnsiConsole.systemInstall();
9086
try {
@@ -130,6 +126,14 @@ private static String getJansiVersion() {
130126
return ( p == null ) ? null : p.getImplementationVersion();
131127
}
132128

129+
private static void diagnoseTty(boolean stderr) {
130+
int fd = stderr ? CLibrary.STDERR_FILENO : CLibrary.STDOUT_FILENO;
131+
int isatty = isatty(fd);
132+
133+
System.out.println("isatty(STD" + (stderr ? "ERR" : "OUT") + "_FILENO)= " + isatty + ", System."
134+
+ (stderr ? "err" : "out") + " " + ((isatty == 0) ? "is *NOT*" : "is") + " a terminal");
135+
}
136+
133137
private static String getPomPropertiesVersion(String path) throws IOException {
134138
InputStream in = AnsiMain.class.getResourceAsStream("/META-INF/maven/" + path + "/pom.properties");
135139
if (in == null) {

0 commit comments

Comments
 (0)