Skip to content

Add basic support for colored printers #3526

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 3 commits into from
Nov 27, 2017

Conversation

nicolasstucki
Copy link
Contributor

With this change, both dotc -decompile and dotc -Xprint get colored outputs.

@@ -346,29 +346,31 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) {
case id: Trees.SearchFailureIdent[_] =>
tree.typeOpt match {
case reason: Implicits.SearchFailureType =>
toText(id.name) ~ "implicitly[" ~ toText(reason.expectedType) ~ "]"
Copy link
Contributor

Choose a reason for hiding this comment

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

A [ disappeared, not sure if it's intentional

case CaseDef(pat, guard, body) =>
"case " ~ inPattern(toText(pat)) ~ optText(guard)(" if " ~ _) ~ " => " ~ caseBlockText(body)
keywordStr("case ") ~ inPattern(toText(pat)) ~ optText(guard)(" if " ~ _) ~ " => " ~ caseBlockText(body)
Copy link
Contributor

Choose a reason for hiding this comment

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

this if is not highlighted

@@ -17,6 +17,7 @@ object SyntaxHighlighting {
val KeywordColor = Console.YELLOW
val ValDefColor = Console.CYAN
val LiteralColor = Console.RED
val StringColor = Console.GREEN
Copy link
Contributor

Choose a reason for hiding this comment

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

Missing space ^^'

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Nooooo. Shame on me.

!Character.isAlphabetic(c) && !Character.isDigit(c) &&
!Character.isMirrored(c) && !Character.isWhitespace(c)
val (token, rest) =
if (head == '\u001b') { // ansi color token
Copy link
Contributor

Choose a reason for hiding this comment

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

val ansiColorToken = '\u001b'

(also to be used below)

@@ -69,25 +65,21 @@ object DiffUtil {
}

val expectedDiff =
if (expected eq EOF) ANSI_EOF + expected + ANSI_DEFAULT
if (expected eq EOF) eof()
Copy link
Contributor

Choose a reason for hiding this comment

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

You are printing less here (expected is not shown), is it intentional?

Copy link
Contributor Author

@nicolasstucki nicolasstucki Nov 27, 2017

Choose a reason for hiding this comment

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

The string for expected is in this case "EOF". EOF is a string that has "EOF" but is also meant to be unique.

@nicolasstucki nicolasstucki merged commit 2fba289 into scala:master Nov 27, 2017
@allanrenucci allanrenucci deleted the color-printer branch December 14, 2017 16:58
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.

2 participants