Skip to content

Commit

Permalink
Merge pull request #10758 from som-snytt/fix/repl-color-redux
Browse files Browse the repository at this point in the history
Restrict fix to Properties
  • Loading branch information
lrytz committed Apr 17, 2024
2 parents 6b68db9 + a064a89 commit a527019
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 6 deletions.
3 changes: 2 additions & 1 deletion src/library/scala/util/Properties.scala
Expand Up @@ -148,9 +148,10 @@ private[scala] trait PropertiesTrait {

/** System.console.isTerminal, or just check for null console on JDK < 22 */
private[scala] lazy val consoleIsTerminal: Boolean = {
import language.reflectiveCalls
val console = System.console
def isTerminal: Boolean =
try classOf[java.io.Console].getMethod("isTerminal", null).invoke(console).asInstanceOf[Boolean]
try console.asInstanceOf[{ def isTerminal(): Boolean }].isTerminal()
catch { case _: NoSuchMethodException => false }
console != null && (!isJavaAtLeast("22") || isTerminal)
}
Expand Down
Expand Up @@ -1009,7 +1009,7 @@ object ILoop {
def batchText: String = delegate.batchText
def batchMode: Boolean = delegate.batchMode
def doCompletion: Boolean = delegate.doCompletion
override def haveInteractiveConsole: Boolean = delegate.haveInteractiveConsole
def haveInteractiveConsole: Boolean = delegate.haveInteractiveConsole

def xsource: String = ""

Expand Down
Expand Up @@ -21,7 +21,7 @@ import scala.sys.Prop._

import scala.tools.nsc.{GenericRunnerSettings, Settings}
import scala.tools.nsc.Properties.{
coloredOutputEnabled, consoleIsTerminal, envOrNone, javaVersion, javaVmName,
coloredOutputEnabled, envOrNone, javaVersion, javaVmName,
shellBannerString, shellInterruptedString, shellPromptString, shellWelcomeString,
userHome, versionString, versionNumberString,
}
Expand All @@ -38,7 +38,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)
override val haveInteractiveConsole: Boolean = super.haveInteractiveConsole && !settings.Xnojline.value
val haveInteractiveConsole: Boolean = !settings.Xnojline.value
def xsource: String = if (settings.isScala3: @nowarn) settings.source.value.versionString else ""
}
case _ => new ShellConfig {
Expand All @@ -47,7 +47,7 @@ object ShellConfig {
val batchText: String = ""
val batchMode: Boolean = false
val doCompletion: Boolean = !settings.noCompletion.value
override val haveInteractiveConsole: Boolean = super.haveInteractiveConsole && !settings.Xnojline.value
val haveInteractiveConsole: Boolean = !settings.Xnojline.value
def xsource: String = if (settings.isScala3: @nowarn) settings.source.value.versionString else ""
}
}
Expand All @@ -59,7 +59,7 @@ trait ShellConfig {
def batchText: String
def batchMode: Boolean
def doCompletion: Boolean
def haveInteractiveConsole: Boolean = consoleIsTerminal
def haveInteractiveConsole: Boolean

// source compatibility, i.e., -Xsource
def xsource: String
Expand Down

0 comments on commit a527019

Please sign in to comment.