class TTY::Color::Mode

def from_term

Other tags:
    Api: - private

Returns:
  • (NoValue, Integer) -
def from_term
  case @env["TERM"]
  when TERM_24BIT then TRUECOLORS
  when /[-+](\d+)color/ then $1.to_i
  when /[-+](\d+)bit/   then 2**$1.to_i
  when TERM_256 then 256
  when TERM_64  then 64
  when TERM_52  then 52
  when TERM_16  then 16
  when TERM_8   then 8
  when /dummy/  then 0
  else NoValue
  end
end

def from_tput

Other tags:
    Api: - private

Returns:
  • (NoValue, Integer) -
def from_tput
  return NoValue unless TTY::Color.command?("tput colors")
  colors = `tput colors 2>/dev/null`.to_i
  colors >= 8 ? colors : NoValue
rescue Errno::ENOENT
  NoValue
end

def initialize(env)

def initialize(env)
  @env = env
end

def mode

Other tags:
    Api: - public

Returns:
  • (Integer) -
def mode
  return 0 unless TTY::Color.tty?
  value = 8
  METHODS.each do |from_check|
    break if (value = public_send(from_check)) != NoValue
  end
  return 8 if value == NoValue
  value
end