-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Compiler: use Colorize.on_tty_only! #4499
base: master
Are you sure you want to change the base?
Compiler: use Colorize.on_tty_only! #4499
Conversation
Could you seperate the changes to bin/crystal and the compiler into seperate commits? The core team might even want them in seperate prs. |
ok. Please wait. |
@RX14 I can separate this PR into the wrapper bug fix and others (using |
e9f2a05
to
a08ce00
Compare
@makenowjust i'm not sure I understand what the conflict is. |
@RX14 Bug fix patch: diff --git a/bin/crystal b/bin/crystal
index 54704199d..8b4380f30 100755
--- a/bin/crystal
+++ b/bin/crystal
@@ -115,7 +115,7 @@ __has_colors() {
return 1
fi
}
-SUPPORTS_COLORS=$(__has_colors)
+SUPPORTS_COLORS=$(__has_colors && echo true || echo false)
__error_msg() {
if $SUPPORTS_COLORS; then
# bold red coloring |
I didn't intend to fix a bug. I implemented TTY detection on the wrapper script correctly, then I fixed a bug unexpectedly. Why cause a problem when I make a PR about |
This PR diff is a little large, but it is really simple fix. I will explain:
That's all. |
@makenowjust could you rebase this PR on master? |
a08ce00
to
cfd74df
Compare
To support TTY detection Fixed specs and wrapper script
cfd74df
to
d6c6e18
Compare
@straight-shoota rebased. |
@@ -636,7 +636,9 @@ describe "Semantic: generic class" do | |||
begin | |||
semantic(nodes) | |||
rescue ex : TypeException | |||
old_enabled, Colorize.enabled = Colorize.enabled?, false |
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.
This would be better as two statements.
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.
Thank you but I don't think that.
I'd suggest to add the option to explicitly set color mode to
A lot of command line application do it like this, and I think this would be the best way to handle this. |
@straight-shoota It was implemented in #3925... |
src/compiler/crystal/command.cr
Outdated
case color | ||
when "auto" | ||
Colorize.on_tty_only! | ||
when "always" |
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.
color = "always" if color.empty?
=> when "always", .empty?
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.
when "always", ""
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.
Personally, color = "always" if color.empty?
shows "always"
as default clearly, so I would keep this.
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.
Maybe, but it adds an completely unnecessary comparison and assignment.
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.
It should be all in one case
statement, not a case
plus an if
.
|
For example `crystal run --color a.cr` means `crystal run --color=a.cr`. It is not useful.
Why not use |
@straight-shoota It does not change meaning. |
Yes it does. If |
Yes but it is not implemented unfortunately. |
You mean The commands should provide an arg-less |
Maybe it has already been said, but to me, the
|
It is not useless but adds expressiveness. It makes it easy to inject a configuration value into the command line arguments, like |
more complex things. global state in colorize used by all apps. global state is bad. the design is being ruined. more command line switches. the direction should be to simplify things. |
@larubujo This PR is about the compiler, not "all apps". |
I totally agree with this. But it can be merged this before implementing this feature in |
I personally prefer @bew's suggestion. At least, if this PR is blocked on an |
@straight-shoota I want to revert |
Sorry... 🙇 |
@makenowjust are you still working on this? |
Colorize.on_tty_only!
is introduced in #4271, but it is not used in compiler. I think it is useful that colorize is turned on/off depending on tty detection result.In addition, I fixed
bin/crystal
wrapper script to detect TTY.bin/crystal
script'sSUPPORTS_COLORS
is really buggy, at least it isn't working correct now.