-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Make Colorize.on_tty_only!
the default behavior
#15881
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
base: master
Are you sure you want to change the base?
Make Colorize.on_tty_only!
the default behavior
#15881
Conversation
src/colorize.cr
Outdated
|
||
# Makes `Colorize.enabled` `true` if and only if both of `STDOUT.tty?` | ||
# and `STDERR.tty?` are `true` and the tty is not considered a dumb terminal. | ||
# This is determined by the environment variable called `TERM`. | ||
# If `TERM=dumb`, color won't be enabled. | ||
# If `NO_COLOR` contains any value color won't be enabled conforming to https://no-color.org | ||
# | ||
# This can be used to revert `Colorize.enabled?` to its default value after | ||
# colorization is explicitly enabled or disabled. | ||
def self.on_tty_only! | ||
self.enabled = STDOUT.tty? && STDERR.tty? && ENV["TERM"]? != "dumb" && !ENV.has_key?("NO_COLOR") |
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.
suggestion: We could reset @@enabled
to avoid duplication. This means the default block of the above class_property
definition would be invoked on the next getter call.
self.enabled = STDOUT.tty? && STDERR.tty? && ENV["TERM"]? != "dumb" && !ENV.has_key?("NO_COLOR") | |
@@enabled = nil |
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 line in Shards implicitly assumes that on_tty_only!
returns the new value of enabled?
, so this is unfortunately a breaking change
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 return enabled
then? This still avoids duplicating the exact same condition.
self.enabled = STDOUT.tty? && STDERR.tty? && ENV["TERM"]? != "dumb" && !ENV.has_key?("NO_COLOR") | |
@enabled = nil | |
enabled |
Co-authored-by: Johannes Müller <[email protected]>
This reverts commit c4e333f.
Originally part of #7690, this seems to be the more sensible behavior compared to ignoring non-terminal streams and
$TERM
. This does not deprecate.on_tty_only!
because it is still useful after the default is overridden.Effectively reverts #14258.