Skip to content

Commit

Permalink
Restore default value of Colorize.enabled. Add Colorize.on_tty_only! (#…
Browse files Browse the repository at this point in the history
…4271)

Amend #4075
Fix docs
  • Loading branch information
bcardiff committed Apr 11, 2017
1 parent c4bbb59 commit e732d1a
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/colorize.cr
Expand Up @@ -80,7 +80,7 @@ module Colorize
# If this value is `true`, `Colorize::Object` is enabled by default.
# But if this value is `false`, `Colorize::Object` is disabled.
#
# This defaule value is `true` only if both of `STDOUT.tty?` and `STDERR.tty?` are `true`.
# The default value is `true`.
#
# ```
# Colorize.enabled = true
Expand All @@ -89,7 +89,12 @@ module Colorize
# Colorize.enabled = false
# "hello".colorize.red.to_s # => "hello"
# ```
class_property? enabled : Bool = STDOUT.tty? && STDERR.tty?
class_property? enabled : Bool = true

# Make `Colorize.enabled` `true` if and only if both of `STDOUT.tty?` and `STDERR.tty?` are `true`.
def self.on_tty_only!
self.enabled = STDOUT.tty? && STDERR.tty?
end
end

def with_color
Expand Down

0 comments on commit e732d1a

Please sign in to comment.