Skip to content

Commit

Permalink
Update logic for detecting if the output stream is connected to a ter…
Browse files Browse the repository at this point in the history
…minal

remkop#2083
  • Loading branch information
cushon committed Aug 11, 2023
1 parent 71553ae commit 3212b4a
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/main/java/picocli/CommandLine.java
Original file line number Diff line number Diff line change
Expand Up @@ -17840,7 +17840,18 @@ static final boolean forceEnabled() { return System.getenv("CLICOLOR_FORCE") !=
&& !"0".equals(System.getenv("CLICOLOR_FORCE"));}
/** http://stackoverflow.com/questions/1403772/how-can-i-check-if-a-java-programs-input-output-streams-are-connected-to-a-term */
static boolean calcTTY() {
try { return System.class.getDeclaredMethod("console").invoke(null) != null; }
try {
Object console = System.class.getDeclaredMethod("console").invoke(null);
if (console == null) {
return false;
}
try {
Method isTerminal = Console.class.getDeclaredMethod("isTerminal");
return (boolean) isTerminal.invoke(console);
} catch (NoSuchMethodException e) {
return true;
}
}
catch (Throwable reflectionFailed) { return true; }
}
/** Cygwin and MSYS use pseudo-tty and console is always null... */
Expand Down

0 comments on commit 3212b4a

Please sign in to comment.