@@ -25,6 +25,7 @@ import scala.tools.nsc.Properties.{
25
25
shellBannerString , shellInterruptedString , shellPromptString , shellWelcomeString ,
26
26
userHome , versionString , versionNumberString ,
27
27
}
28
+ import scala .util .Properties .isJavaAtLeast
28
29
29
30
object ShellConfig {
30
31
val EDITOR = envOrNone(" EDITOR" )
@@ -38,7 +39,7 @@ object ShellConfig {
38
39
val batchText : String = if (settings.execute.isSetByUser) settings.execute.value else " "
39
40
val batchMode : Boolean = batchText.nonEmpty
40
41
val doCompletion : Boolean = ! (settings.noCompletion.value || batchMode)
41
- val haveInteractiveConsole : Boolean = ! settings.Xnojline .value
42
+ override val haveInteractiveConsole : Boolean = super .haveInteractiveConsole && ! settings.Xnojline .value
42
43
def xsource : String = if (settings.isScala3: @ nowarn) settings.source.value.versionString else " "
43
44
}
44
45
case _ => new ShellConfig {
@@ -47,7 +48,7 @@ object ShellConfig {
47
48
val batchText : String = " "
48
49
val batchMode : Boolean = false
49
50
val doCompletion : Boolean = ! settings.noCompletion.value
50
- val haveInteractiveConsole : Boolean = ! settings.Xnojline .value
51
+ override val haveInteractiveConsole : Boolean = super .haveInteractiveConsole && ! settings.Xnojline .value
51
52
def xsource : String = if (settings.isScala3: @ nowarn) settings.source.value.versionString else " "
52
53
}
53
54
}
@@ -59,7 +60,15 @@ trait ShellConfig {
59
60
def batchText : String
60
61
def batchMode : Boolean
61
62
def doCompletion : Boolean
62
- def haveInteractiveConsole : Boolean
63
+ def haveInteractiveConsole : Boolean = System .console != null && consoleIsTerminal
64
+
65
+ // false if JDK 22 and the system console says !isTerminal
66
+ def consoleIsTerminal : Boolean = {
67
+ def isTerminal : Boolean =
68
+ try classOf [java.io.Console ].getMethod(" isTerminal" , null ).invoke(System .console).asInstanceOf [Boolean ]
69
+ catch { case _ : NoSuchMethodException => false }
70
+ ! isJavaAtLeast(22 ) || isTerminal
71
+ }
63
72
64
73
// source compatibility, i.e., -Xsource
65
74
def xsource : String
@@ -68,7 +77,7 @@ trait ShellConfig {
68
77
private def int (name : String ) = Prop [Int ](name)
69
78
70
79
// This property is used in TypeDebugging. Let's recycle it.
71
- val colorOk = coloredOutputEnabled
80
+ val colorOk = coloredOutputEnabled && haveInteractiveConsole
72
81
73
82
val historyFile = s " $userHome/.scala_history_jline3 "
74
83
0 commit comments