module DEBUGGER__::Color

def color_pp obj, width

def color_pp obj, width
  with_inspection_error_guard do
    if !CONFIG[:no_color]
      IRB::ColorPrinter.pp(obj, "".dup, width)
    else
      obj.pretty_inspect
    end
  end
end

def color_pp obj, width

def color_pp obj, width
  with_inspection_error_guard do
    obj.pretty_inspect
  end
end

def colored_inspect obj, width: SESSION.width, no_color: false

def colored_inspect obj, width: SESSION.width, no_color: false
  with_inspection_error_guard do
    if !no_color
      color_pp obj, width
    else
      obj.pretty_inspect
    end
  end
end

def colorize str, color

def colorize str, color
  if !CONFIG[:no_color]
    irb_colorize str, color
  else
    str
  end
end

def colorize str, color

def colorize str, color
  str
end

def colorize_blue(str)

def colorize_blue(str)
  colorize(str, [:BLUE, :BOLD])
end

def colorize_code code

def colorize_code code
  IRB::Color.colorize_code(code, colorable: true)
end

def colorize_code code

def colorize_code code
  IRB::Color.colorize_code(code)
end

def colorize_code code

def colorize_code code
  code
end

def colorize_cyan(str)

def colorize_cyan(str)
  colorize(str, [:CYAN, :BOLD])
end

def colorize_dim(str)

def colorize_dim(str)
  colorize(str, [:DIM])
end

def colorize_magenta(str)

def colorize_magenta(str)
  colorize(str, [:MAGENTA, :BOLD])
end

def irb_colorize str, color

def irb_colorize str, color
  IRB::Color.colorize str, color, colorable: true
end

def irb_colorize str, color

def irb_colorize str, color
  IRB::Color.colorize str, color
end

def with_inspection_error_guard

def with_inspection_error_guard
  yield
rescue Exception => ex
  err_msg = "#{ex.inspect} rescued during inspection"
  string_result = obj.to_s rescue nil
  # don't colorize the string here because it's not from user's application
  if string_result
    %Q{"#{string_result}" from #to_s because #{err_msg}}
  else
    err_msg
  end
end