From 9df563f25f7ab8c3534935e62bdcf2e37498c0ab Mon Sep 17 00:00:00 2001 From: Markus Reiter Date: Fri, 4 Oct 2019 09:17:44 +0200 Subject: [PATCH] Add `Tty::color?`. --- Library/Homebrew/utils/tty.rb | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/Library/Homebrew/utils/tty.rb b/Library/Homebrew/utils/tty.rb index 76e2867dd9..3f69e508f5 100644 --- a/Library/Homebrew/utils/tty.rb +++ b/Library/Homebrew/utils/tty.rb @@ -64,10 +64,17 @@ module Tty end def to_s - return "" if !ENV["HOMEBREW_COLOR"] && (ENV["HOMEBREW_NO_COLOR"] || !$stdout.tty?) + return "" unless color? current_escape_sequence ensure reset_escape_sequence! end + + def color? + return false if ENV["HOMEBREW_NO_COLOR"] + return true if ENV["HOMEBREW_COLOR"] + + $stdout.tty? + end end