1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
|
# frozen_string_literal: true
module Cri
# Provides tools to detect platform and environment configuration (e.g. is
# color support available?)
#
# @api private
module Platform
# @return [Boolean] true if the current platform is Windows, false
# otherwise.
def self.windows?
RUBY_PLATFORM =~ /windows|bccwin|cygwin|djgpp|mingw|mswin|wince/i
end
# Checks whether colors can be enabled. For colors to be enabled, the given
# IO should be a TTY, and, when on Windows, ::Win32::Console::ANSI needs to
# be defined.
#
# @return [Boolean] True if colors should be enabled, false otherwise.
def self.color?(io)
if !io.tty?
false
elsif windows?
defined?(::Win32::Console::ANSI)
else
true
end
end
end
end
|