I am trying to print a logo as I start the scala REPL, and the behaviour seems to have changed between version 2.11.8 and 2.11.11. I am loading a file containing a single println statement using “scala -i file.scala”. In version 2.11.8, I see the message before I get the prompt for further input. In 2.11.11 however, I get the prompt first, and then the message.
Is there a way to force 2.11.11 to give me the message first?
[EDIT]
I just tested the behaviour on 2.12.3 and 2.13.0-M1. They both behave like 2.11.11.
Thank you very much. This is exactly what I was looking for. I tested the -Dscala.repl.welcome flag works on 2.11.8, 2.11.11, 2.12.3 and 2.13.0-M1, and it does what I need in all these versions.
I have a follow-up question. The message that I am trying to show is ASCII art, which I don’t really want to pass in on the command line. I also want to avoid bash-tricks (like using cat), as this almost surely will break on some platforms. Is there a way to pass the welcome message in a file?
[EDIT]
I don’t seem to be able to pass newlines as part of the message in the command line either.
You can use %n from java.util.Formatter for newlines.
There are many perils in shell quoting.
$ scala -Dscala.repl.welcome='Gruezi!%nYou'"'"'re using Java %2$s.%nThis is Scala %1$#s'
Gruezi!
You're using Java 1.8.0_111.
This is Scala 2.12.3
scala> :quit
$ scala -Dscala.repl.welcome='Gruezi!%nYou'"'re using Java %2\$s.%nThis is Scala %1\$#s"
Gruezi!
You're using Java 1.8.0_111.
This is Scala 2.12.3
scala>
You can also set “shell.welcome” in compiler.properties, normally packaged in scala-compiler.jar.
TIL properties strips leading whitespace. And don’t neglect to escape backslashes.
The other trick, not implemented, was to let the “splash” loop that accepts the first line in the REPL take a custom prompt, which would include the logo. Normally, you customize a “splash” image to display at startup; that would decouple the scala notice from the custom banner.