-
-
Notifications
You must be signed in to change notification settings - Fork 767
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
Disable colors on Windows OS #1701
Conversation
Signed-off-by: Semyon Levin <levin.semen@gmail.com>
Codecov Report
@@ Coverage Diff @@
## master #1701 +/- ##
============================================
- Coverage 79.14% 75.91% -3.23%
- Complexity 1760 1856 +96
============================================
Files 285 328 +43
Lines 4943 5527 +584
Branches 908 1010 +102
============================================
+ Hits 3912 4196 +284
- Misses 541 791 +250
- Partials 490 540 +50
Continue to review full report at Codecov.
|
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.
Thanks for your time valuable feedback and your two proposals for this issue!!
I favor this approach, because it's simpler and doesn't require a 3rd party library as a dependency.
I have some questions.
What happens if this is executed in the Cygwin shell on Windows? The shell supports ANSI coloring.
What happens if this is executed in the Windows PowerShell?
CC @marschwar
@@ -12,7 +12,12 @@ private data class Color(private val value: Byte) { | |||
get() = "$ESC[${value}m" | |||
} | |||
|
|||
private fun CharSequence.colorized(color: Color) = "${color.escapeSequence}$this${RESET.escapeSequence}" | |||
private val isColoredOutputSupported: Boolean = !System.getProperty("os.name", "").contains("win", true) |
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 happens if the OS is Darwin? Then this variable is true.
The check should be written with startsWith
to be safer.
!System.getProperty("os.name", "").startsWith("Windows")
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.
fixed
@schalkms The Idea behind checking if the property contains Actually I don't see any major drawbacks with adding Jansi dependency to Also, as I understand, all checks you mentioned are supported by Jansi. BTW IDEA correctly displays colorized output by Jansi. |
I fully agree. However,
I tried it out on Windows with the following shells.
True, because IntelliJ only emulates the default cmd on Windows, if not configured otherwise. |
I agree with @schalkms. I don't really see the need for adding an additional library just for this. It's far from being a core feature of detekt. I could live with See: |
"${color.escapeSequence}$this${RESET.escapeSequence}" | ||
} else { | ||
this.toString() | ||
} |
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.
Minor nitpick: In my opinion CharSequence.colorized(color: Color)
should itself return a CharSequence
if possible.
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.
fixed
Thanks @remal @schalkms @marschwar for further investigations. So lets go with this pr then. |
Signed-off-by: Semyon Levin <levin.semen@gmail.com>
Signed-off-by: Semyon Levin <levin.semen@gmail.com>
Guys, please take a look. |
Signed-off-by: Semyon Levin <levin.semen@gmail.com>
fun CharSequence.decolorized() = this.replace(escapeSequenceRegex, "") | ||
fun String.red(): String = colorized(RED).toString() | ||
fun String.yellow(): String = colorized(YELLOW).toString() | ||
fun String.decolorized(): String = this.replace(escapeSequenceRegex, "") |
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.
Why do we have the same extension method String and CharSequence? Did I miss something?
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.
Because @marschwar asked to make CharSequence.colorized(color: Color)
to return CharSequence
. But there are some places where String
is expected, so it would be more convenient to have a method that returns String
. I suggest leaving only one variant that returns String
. WDYT?
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.
Sorry to cause such a confusion. I had not actually made the change myself so I did not realize there were usages where a String is expected to be returned. My point was that the extension function should return the same type if possible.
Please keep fun String.colorized(color: Color): String
only. AFAIK we don't need the extension function to be on CharSequence.
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.
fixed
Signed-off-by: Semyon Levin <levin.semen@gmail.com>
* Disable colors on Windows OS Signed-off-by: Semyon Levin <levin.semen@gmail.com> * CharSequence.colorized returns CharSequence Signed-off-by: Semyon Levin <levin.semen@gmail.com> * Is Windows check is changed Signed-off-by: Semyon Levin <levin.semen@gmail.com> * code formatting Signed-off-by: Semyon Levin <levin.semen@gmail.com> * simplification Signed-off-by: Semyon Levin <levin.semen@gmail.com>
This is simple and a bit dirty fix for #1694 - remove color chars in console output for Windows OS.
IMHO this PR is less preferable than #1702