123456789_123456789_123456789_123456789_123456789_

Class: RBS::CLI::ColoredIO

Relationships & Source Files
Inherits: Object
Defined in: lib/rbs/cli/colored_io.rb

Class Method Summary

Instance Attribute Summary

Instance Method Summary

Constructor Details

.new(stdout:) ⇒ ColoredIO

[ GitHub ]

  
# File 'lib/rbs/cli/colored_io.rb', line 8

def initialize(stdout:)
  @stdout = stdout
end

Instance Attribute Details

#are_colors_disabled?Boolean (readonly, private)

[ GitHub ]

  
# File '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?Boolean (readonly, private)

[ GitHub ]

  
# File 'lib/rbs/cli/colored_io.rb', line 39

def are_colors_supported?
  stdout.tty? && ENV["TERM"] != "dumb"
end

#can_display_colors?Boolean (readonly, private)

[ GitHub ]

  
# File 'lib/rbs/cli/colored_io.rb', line 35

def can_display_colors?
  are_colors_supported? && !are_colors_disabled?
end

#stdout (readonly)

[ GitHub ]

  
# File 'lib/rbs/cli/colored_io.rb', line 6

attr_reader :stdout

Instance Method Details

#puts

[ GitHub ]

  
# File 'lib/rbs/cli/colored_io.rb', line 28

def puts(...)
  stdout.puts(...)
end

#puts_green(string)

[ GitHub ]

  
# File '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)

[ GitHub ]

  
# File '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