class RBS::CLI::ColoredIO

Attributes

stdout[R]

Public Class Methods

new(stdout:) click to toggle source
# File rbs-3.4.0/lib/rbs/cli/colored_io.rb, line 8
def initialize(stdout:)
  @stdout = stdout
end

Public Instance Methods

puts(...) click to toggle source
# File rbs-3.4.0/lib/rbs/cli/colored_io.rb, line 28
def puts(...)
  stdout.puts(...)
end
puts_green(string) click to toggle source
# File rbs-3.4.0/lib/rbs/cli/colored_io.rb, line 20
def puts_green(string)
  if can_display_colors?
    puts "\e[32m#{string}\e[m"
  else
    puts string
  end
end
puts_red(string) click to toggle source
# File rbs-3.4.0/lib/rbs/cli/colored_io.rb, line 12
def puts_red(string)
  if can_display_colors?
    puts "\e[31m#{string}\e[m"
  else
    puts string
  end
end

Private Instance Methods

are_colors_disabled?() click to toggle source
# File rbs-3.4.0/lib/rbs/cli/colored_io.rb, line 43
def are_colors_disabled?
  !ENV['NO_COLOR'].nil? && !ENV.fetch('NO_COLOR', '').empty?
end
are_colors_supported?() click to toggle source
# File rbs-3.4.0/lib/rbs/cli/colored_io.rb, line 39
def are_colors_supported?
  stdout.tty? && ENV["TERM"] != "dumb"
end
can_display_colors?() click to toggle source

github.com/rubygems/rubygems/blob/ed65279100234a17d65d71fe26de5083984ac5b8/bundler/lib/bundler/vendor/thor/lib/thor/shell/color.rb#L99-L109

# File rbs-3.4.0/lib/rbs/cli/colored_io.rb, line 35
def can_display_colors?
  are_colors_supported? && !are_colors_disabled?
end