-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Fix stdout redirect for REPL's println #1251
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix stdout redirect for REPL's println #1251
Conversation
When printing in the REPL via `println`, the output would end up on the same line, since stdout had not been redirected. This commit remedies that. It also adds syntax highlighting to result types.
aa62668
to
bce6abd
Compare
This doesn't fix the followings which work fine with the scala REPL: > Console.err.println("hi")
> System.out.println("hi")
> System.err.println("hi") |
@@ -38,7 +38,8 @@ class TestREPL(script: String) extends REPL { | |||
out.close() | |||
val printed = out.toString | |||
val transcript = printed.drop(printed.indexOf(config.prompt)) | |||
if (transcript.toString != script) { | |||
val transcriptNoColors = transcript.toString.replaceAll("\u001B\\[[;\\d]*m", "") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about having a config option to disable all colors instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the scala REPL has -Dscala.color
: https://github.com/scala/scala/blob/99a82be91cbb85239f70508f6695c6b21fd3558c/src/repl/scala/tools/nsc/interpreter/ReplProps.scala#L20
fabf357
to
fdf2424
Compare
@@ -94,6 +94,7 @@ class ScalaSettings extends Settings.SettingGroup { | |||
val sourceReader = StringSetting("-Xsource-reader", "classname", "Specify a custom method for reading source files.", "") | |||
val XnoValueClasses = BooleanSetting("-Xno-value-classes", "Do not use value classes. Helps debugging.") | |||
val XreplLineWidth = IntSetting("-Xrepl-line-width", "Maximial number of columns per line for REPL output", 390) | |||
val XreplNoColor = BooleanSetting("-Xrepl-no-color", "Removes syntax highlighting in REPL") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@smarter: It felt like the precedence was to name the option -Xrepl-no-color
as opposed to the -Dscala.color
in scalac
(Other suggested changes in place)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The name doesn't really matter, but I think you should phrase the option positively (-Xrepl-color
, or just -color
since this isn't an "advanced" option) and you really want three possible values for color: never
,auto
and always
, auto
means that we try to guess if we're in a terminal (as opposed to redirected to a file) and only if that's the case do we enable colors, this is how color is specified in many cli tools (gcc -fdiagnostics-color
: https://gcc.gnu.org/onlinedocs/gcc-5.3.0/gcc/Language-Independent-Options.html, git, ...). But this isn't needed for this PR of course.
@@ -28,6 +28,7 @@ class ScalaSettings extends Settings.SettingGroup { | |||
val help = BooleanSetting("-help", "Print a synopsis of standard options") | |||
val nowarn = BooleanSetting("-nowarn", "Generate no warnings.") | |||
val print = BooleanSetting("-print", "Print program with Scala-specific features removed.") | |||
val color = ChoiceSetting("-color", "mode", "Colored output", List("always", "never", "auto"), "auto") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@smarter: done. For now it defaults to "auto" and the repl will be colored if the setting is set to "auto" or "always".
"auto" does not do anything. It is simply lying to user that it's implemented, leading to bad user experience. I propose to comment it out. |
When printing in the REPL via
println
, the output would end up on thesame line, since stdout had not been redirected. This commit remedies
that.
It also adds syntax highlighting to result types.
Review: @smarter