Description
Compiler version
sbt:scala3> print scalaVersion
scala3-sbt-bridge / scalaVersion
3.0.0-RC3
scala3-library / scalaVersion
3.0.0-RC3
scala3-compiler / scalaVersion
3.0.0-RC3
scala3-interfaces / scalaVersion
3.0.0-RC3
tasty-core / scalaVersion
3.0.0-RC3
scalaVersion
3.0.0-RC3
sbt:scala3>
Minimized code
#!/opt/scala3/bin/scala
import org.jline.utils.OSUtils._
def main(args: Array[String]) =
printf("IS_WINDOWS: %s\n", IS_WINDOWS)
printf("IS_CYGWIN: %s\n", IS_CYGWIN)
printf("IS_MINGW: %s\n", IS_MINGW)
printf("IS_MSYSTEM: %s\n", IS_MSYSTEM)
printf("IS_CONEMU: %s\n", IS_CONEMU)
printf("IS_OSX: %s\n", IS_OSX)
printf("TTY_COMMAND: %s\n", TTY_COMMAND)
printf("STTY_COMMAND: %s\n", STTY_COMMAND)
printf("STTY_F_OPTION: %s\n", STTY_F_OPTION)
printf("INFOCMP_COMMAND: %s\n", INFOCMP_COMMAND)
Output
The output depends on environment variables, but in Windows, the jline3 code for identifying the current console environment is fragile. When launching the scala REPL, if jline3 misidentifies the environment, the result is not good, so it might make sense to take defensive measures to protect the REPL experience from random accidents.
Some examples:
with console CMD.EXE
, and PWD=, jline3 mis-identifies Cygwin.
C:\opt\ue>.\scala3.bat /opt/ue/ssrc/showJline3view.sc
-- Deprecation Warning: C:\opt\ue\ssrc\showJline3view.sc:8:28 ------------------
8 | printf("IS_MINGW: %s\n",IS_MINGW)
| ^^^^^^^^
|value IS_MINGW in object OSUtils is deprecated since : see corresponding Javadoc for more information.
1 warning found
IS_WINDOWS: true
IS_CYGWIN: true
IS_MINGW: false
IS_MSYSTEM: false
IS_CONEMU: false
IS_OSX: false
TTY_COMMAND: tty.exe
STTY_COMMAND: stty.exe
STTY_F_OPTION: null
INFOCMP_COMMAND: infocmp.exe
A REPL
session when PWD
is defined and starts with a slash:
set PWD=/
.\scala3.bat
C:\opt\ue>.\scala3.bat
←[90m~←[0m←[K ←[?2004h←[34mscala> ←[0m
The session looks bad, and the arrow keys are not functional.
A workaround is to unset PWD
immediately prior to starting the jvm.
FYI, here is my scala3.bat
file:
@echo off
set SCALA_HOME="c:/opt/scala3"
set CP="%SCALA_HOME%/lib/scala-library-2.13.5.jar;%SCALA_HOME%/lib/scala3-library_3-3.0.1-RC1-bin-SNAPSHOT.jar;%SCALA_HOME%/lib/scala-asm-9.1.0-scala-1.jar;%SCALA_HOME%/lib/compiler-interface-1.3.5.jar;%SCALA_HOME%/lib/scala3-interfaces-3.0.1-RC1-bin-SNAPSHOT.jar;%SCALA_HOME%/lib/scala3-compiler_3-3.0.1-RC1-bin-SNAPSHOT.jar;%SCALA_HOME%/lib/tasty-core_3-3.0.1-RC1-bin-SNAPSHOT.jar;%SCALA_HOME%/lib/scala3-staging_3-3.0.1-RC1-bin-SNAPSHOT.jar;%SCALA_HOME%/lib/scala3-tasty-inspector_3-3.0.1-RC1-bin-SNAPSHOT.jar;%SCALA_HOME%/lib/jline-reader-3.19.0.jar;%SCALA_HOME%/lib/jline-terminal-3.19.0.jar;%SCALA_HOME%/lib/jline-terminal-jna-3.19.0.jar;%SCALA_HOME%/lib/jna-5.3.1.jar"
if [%1]==[] goto repl
C:/opt/jdk/bin/java.exe -Xmx768m -Xms768m -classpath %CP% -Dscala.usejavacp=true dotty.tools.scripting.Main -color:never -deprecation -script %*
goto :eof
:repl
C:/opt/jdk/bin/java.exe -Xmx768m -Xms768m -classpath %CP% -Dscala.usejavacp=true dotty.tools.repl.Main %*
I stumbled onto this problem accidentally, and PWD would not typically be set in a CMD.EXE
session.
A bigger issue is that I have the same bad REPL
experience in a CYGWIN
bash session with console mintty
. I have to fake a non-cygwin environment to have a good and functional REPL
experience. Perhaps something is unusual about my system, and I do have somewhat similar problems with sbt
as well (I have to fake a non-cygwin environment).
I'm testing other environments, see detailed summary below.
Expectation
Scala REPL
sessions should not be sensitive to fragile console detection. I'll post updates as I learn more about the problem.