File tree Expand file tree Collapse file tree 1 file changed +11
-3
lines changed Expand file tree Collapse file tree 1 file changed +11
-3
lines changed Original file line number Diff line number Diff line change @@ -158,9 +158,17 @@ private[scala] trait PropertiesTrait {
158
158
private [scala] def isAvian = javaVmName contains " Avian"
159
159
160
160
private [scala] def coloredOutputEnabled : Boolean = propOrElse(" scala.color" , " auto" ) match {
161
- case " auto" => System .console() != null && ! isWin
162
- case a if a.toLowerCase() == " true" => true
163
- case _ => false
161
+ case " auto" => ! isWin && consoleIsTerminal
162
+ case s => " " == s || " true" .equalsIgnoreCase(s)
163
+ }
164
+
165
+ /** System.console.isTerminal, or just check for null console on JDK < 22 */
166
+ private [scala] lazy val consoleIsTerminal : Boolean = {
167
+ val console = System .console
168
+ def isTerminal : Boolean =
169
+ try classOf [java.io.Console ].getMethod(" isTerminal" , null ).invoke(console).asInstanceOf [Boolean ]
170
+ catch { case _ : NoSuchMethodException => false }
171
+ console != null && (! isJavaAtLeast(" 22" ) || isTerminal)
164
172
}
165
173
166
174
// This is looking for javac, tools.jar, etc.
You can’t perform that action at this time.
0 commit comments