Skip to content

Use color for showing megaphases #14394

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 5 commits into from
Feb 28, 2022
Merged

Conversation

som-snytt
Copy link
Contributor

Tweak to #14388

@SethTisue
Copy link
Member

in the grand tradition of scala/bug#11548 (comment)

@som-snytt
Copy link
Contributor Author

image

@som-snytt
Copy link
Contributor Author

We could get by with yellow, cyan, magenta.

@nicolasstucki
Copy link
Contributor

Should also check what happens if the background is white. Some of the colors might be hard to see.

@som-snytt
Copy link
Contributor Author

som-snytt commented Feb 1, 2022

skinny window wrapping as for option help:

image

white background in WSL terminal window, where the gray is foreground

image

@@ -134,6 +134,7 @@ private sealed trait VerboseSettings:
self: SettingGroup =>
val Vhelp: Setting[Boolean] = BooleanSetting("-V", "Print a synopsis of verbose options.")
val Xprint: Setting[List[String]] = PhasesSetting("-Vprint", "Print out program after", aliases = List("-Xprint"))
val XshowPhases: Setting[Boolean] = BooleanSetting("-Vphases", "List compiler phases.", aliases = List("-Xshow-phases"))
Copy link
Contributor

Choose a reason for hiding this comment

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

Why was this change made?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That is alignment with scala 2.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Alias means -Xshow-phases is still supported. I've considered it would be nice if help text showed aliases, perhaps under -verbose -help.

@@ -191,3 +144,56 @@ trait CliCommand:

extension [T](setting: Setting[T])
protected def value(using ss: SettingsState): T = setting.valueIn(ss)

extension (s: String)
def padLeft(width: Int): String = StringBuilder().tap(_.append(" " * (width - s.length)).append(s)).toString
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
def padLeft(width: Int): String = StringBuilder().tap(_.append(" " * (width - s.length)).append(s)).toString
def padLeft(width: Int): String = String.format("%1$" + width "s", s)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have been preferring "just emit the string" to "parse a format template then construct a string" because people complain about slow strings. Not sure if I would push back here because format is easier to read.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

format is easier to read.
This. Code is read more often than writ.

We need ability to create strings lazily and efficiently. Also f"%${width}s" could actually detect that the interpolated value is part of the format and translate to padding, etc.

Copy link
Contributor

Choose a reason for hiding this comment

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

Otherwise we could simply have

def padLeft(width: Int): String = StringBuilder().tap(_.append(" " * (width - s.length)).append(s)).toString
def padLeft(width: Int): String = " " * (width - s.length) + s

There is a single String.+, the builder will not help for this use case.

val field1 = maxField.min(texts.flatten.map(_._1.length).filter(_ < maxField).max) // widest field under maxField
val field2 = if field1 + separation + maxField < maxCol then maxCol - field1 - separation else 0 // skinny window -> terminal wrap
val separator = " " * separation
def formatField1(text: String): String = if text.length <= field1 then text.padLeft(field1) else text + EOL + "".padLeft(field1)
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
def formatField1(text: String): String = if text.length <= field1 then text.padLeft(field1) else text + EOL + "".padLeft(field1)
def formatField1(text: String): String = if text.length <= field1 then text.padLeft(field1) else text + "\n" + "".padLeft(field1)

We had some issues with EOL and Windows in the past. The "\n" seems to be what we should use by default.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have followed the issue, but usually if I'm on cygwin I want the correct line separator. I'll try to come up with a use case slash test.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'll try to come up with a use case slash test.
Maybe if I start using cygwin again on a regular basis...

@som-snytt
Copy link
Contributor Author

I guess he didn't add a test because it's too hard?

@som-snytt
Copy link
Contributor Author

som-snytt commented Feb 25, 2022

Addressed comments, re-rebased against main instead of master. I have to say, those colors are pretty.

@nicolasstucki nicolasstucki merged commit 5109909 into scala:main Feb 28, 2022
@som-snytt som-snytt deleted the tweak/color-phases branch February 28, 2022 09:48
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