Skip to content

Commit

Permalink
Merge pull request #10753 from som-snytt/test/fixup
Browse files Browse the repository at this point in the history
Move terminal test to properties
  • Loading branch information
SethTisue committed Apr 15, 2024
2 parents b68ac48 + eea7029 commit fcf69c4
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 15 deletions.
3 changes: 3 additions & 0 deletions project/MimaFilters.scala
Expand Up @@ -39,6 +39,9 @@ object MimaFilters extends AutoPlugin {
ProblemFilters.exclude[DirectMissingMethodProblem]("scala.concurrent.impl.FutureConvertersImpl#P.accept"),
ProblemFilters.exclude[IncompatibleMethTypeProblem]("scala.concurrent.impl.FutureConvertersImpl#P.andThen"),

// private[scala] member used by Properties and by REPL
ProblemFilters.exclude[DirectMissingMethodProblem]("scala.util.Properties.consoleIsTerminal"),

)

override val buildSettings = Seq(
Expand Down
13 changes: 11 additions & 2 deletions src/library/scala/util/Properties.scala
Expand Up @@ -142,8 +142,17 @@ private[scala] trait PropertiesTrait {
private[scala] lazy val isAvian = javaVmName.contains("Avian")

private[scala] def coloredOutputEnabled: Boolean = propOrElse("scala.color", "auto") match {
case "auto" => System.console() != null && !isWin
case s => s == "" || "true".equalsIgnoreCase(s)
case "auto" => !isWin && consoleIsTerminal
case s => "" == s || "true".equalsIgnoreCase(s)
}

/** System.console.isTerminal, or just check for null console on JDK < 22 */
private[scala] lazy val consoleIsTerminal: Boolean = {
val console = System.console
def isTerminal: Boolean =
try classOf[java.io.Console].getMethod("isTerminal", null).invoke(console).asInstanceOf[Boolean]
catch { case _: NoSuchMethodException => false }
console != null && (!isJavaAtLeast("22") || isTerminal)
}

// This is looking for javac, tools.jar, etc.
Expand Down
Expand Up @@ -21,11 +21,10 @@ import scala.sys.Prop._

import scala.tools.nsc.{GenericRunnerSettings, Settings}
import scala.tools.nsc.Properties.{
coloredOutputEnabled, envOrNone, javaVersion, javaVmName,
coloredOutputEnabled, consoleIsTerminal, envOrNone, javaVersion, javaVmName,
shellBannerString, shellInterruptedString, shellPromptString, shellWelcomeString,
userHome, versionString, versionNumberString,
}
import scala.util.Properties.isJavaAtLeast

object ShellConfig {
val EDITOR = envOrNone("EDITOR")
Expand Down Expand Up @@ -60,15 +59,7 @@ trait ShellConfig {
def batchText: String
def batchMode: Boolean
def doCompletion: 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
}
def haveInteractiveConsole: Boolean = consoleIsTerminal

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

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

val historyFile = s"$userHome/.scala_history_jline3"

Expand Down
2 changes: 1 addition & 1 deletion test/files/neg/t6323a.scala
@@ -1,4 +1,4 @@
// scalac: -Vimplicits
//> using options -Vimplicits
//
import scala.reflect.runtime.universe._
import scala.reflect.runtime.{currentMirror => m}
Expand Down

0 comments on commit fcf69c4

Please sign in to comment.