Skip to content

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

Merged
merged 7 commits into from
Jun 1, 2016

Conversation

felixmulder
Copy link
Contributor

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.

Review: @smarter

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.
@felixmulder felixmulder force-pushed the topic/fix-stdoutredirect-repl branch from aa62668 to bce6abd Compare May 12, 2016 09:35
@smarter
Copy link
Member

smarter commented May 12, 2016

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", "")
Copy link
Member

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?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@felixmulder felixmulder force-pushed the topic/fix-stdoutredirect-repl branch from fabf357 to fdf2424 Compare May 12, 2016 11:51
@@ -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")
Copy link
Contributor Author

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)

Copy link
Member

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")
Copy link
Contributor Author

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".

@DarkDimius
Copy link
Contributor

"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.
Otherwise LGTM

@felixmulder felixmulder merged commit 64ba4df into scala:master Jun 1, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants