Skip to content

Commit

Permalink
Merge pull request #10751 from som-snytt/sd/867-jdk22-tests
Browse files Browse the repository at this point in the history
Console color only if JDK 22 says isConsole
  • Loading branch information
SethTisue committed Apr 12, 2024
2 parents 770e6a0 + 2c78ad2 commit b68ac48
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
Expand Up @@ -1009,7 +1009,7 @@ object ILoop {
def batchText: String = delegate.batchText
def batchMode: Boolean = delegate.batchMode
def doCompletion: Boolean = delegate.doCompletion
def haveInteractiveConsole: Boolean = delegate.haveInteractiveConsole
override def haveInteractiveConsole: Boolean = delegate.haveInteractiveConsole

def xsource: String = ""

Expand Down
Expand Up @@ -25,6 +25,7 @@ import scala.tools.nsc.Properties.{
shellBannerString, shellInterruptedString, shellPromptString, shellWelcomeString,
userHome, versionString, versionNumberString,
}
import scala.util.Properties.isJavaAtLeast

object ShellConfig {
val EDITOR = envOrNone("EDITOR")
Expand All @@ -38,7 +39,7 @@ object ShellConfig {
val batchText: String = if (settings.execute.isSetByUser) settings.execute.value else ""
val batchMode: Boolean = batchText.nonEmpty
val doCompletion: Boolean = !(settings.noCompletion.value || batchMode)
val haveInteractiveConsole: Boolean = !settings.Xnojline.value
override val haveInteractiveConsole: Boolean = super.haveInteractiveConsole && !settings.Xnojline.value
def xsource: String = if (settings.isScala3: @nowarn) settings.source.value.versionString else ""
}
case _ => new ShellConfig {
Expand All @@ -47,7 +48,7 @@ object ShellConfig {
val batchText: String = ""
val batchMode: Boolean = false
val doCompletion: Boolean = !settings.noCompletion.value
val haveInteractiveConsole: Boolean = !settings.Xnojline.value
override val haveInteractiveConsole: Boolean = super.haveInteractiveConsole && !settings.Xnojline.value
def xsource: String = if (settings.isScala3: @nowarn) settings.source.value.versionString else ""
}
}
Expand All @@ -59,7 +60,15 @@ trait ShellConfig {
def batchText: String
def batchMode: Boolean
def doCompletion: Boolean
def haveInteractiveConsole: Boolean
def haveInteractiveConsole: Boolean = System.console != null && consoleIsTerminal

// false if JDK 22 and the system console says !isTerminal
def consoleIsTerminal: Boolean = {
def isTerminal: Boolean =
try classOf[java.io.Console].getMethod("isTerminal", null).invoke(System.console).asInstanceOf[Boolean]
catch { case _: NoSuchMethodException => false }
!isJavaAtLeast(22) || isTerminal
}

// source compatibility, i.e., -Xsource
def xsource: String
Expand All @@ -68,7 +77,7 @@ trait ShellConfig {
private def int(name: String) = Prop[Int](name)

// This property is used in TypeDebugging. Let's recycle it.
val colorOk = coloredOutputEnabled
val colorOk = coloredOutputEnabled && haveInteractiveConsole

val historyFile = s"$userHome/.scala_history_jline3"

Expand Down

0 comments on commit b68ac48

Please sign in to comment.