Module: DEBUGGER__::Color

Included in:
Breakpoint, Session, SourceRepository, ThreadClient, Tracer
Defined in:
lib/debug/color.rb

Instance Method Summary collapse

Instance Method Details

#color_pp(obj, width) ⇒ Object



50
51
52
53
54
55
56
57
58
# File 'lib/debug/color.rb', line 50

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

#colored_inspect(obj, width: SESSION.width, no_color: false) ⇒ Object



67
68
69
70
71
72
73
74
75
# File 'lib/debug/color.rb', line 67

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

#colorize(str, color) ⇒ Object



36
37
38
39
40
41
42
# File 'lib/debug/color.rb', line 36

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

#colorize_blue(str) ⇒ Object



97
98
99
# File 'lib/debug/color.rb', line 97

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

#colorize_code(code) ⇒ Object



79
80
81
# File 'lib/debug/color.rb', line 79

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

#colorize_cyan(str) ⇒ Object



93
94
95
# File 'lib/debug/color.rb', line 93

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

#colorize_dim(str) ⇒ Object



105
106
107
# File 'lib/debug/color.rb', line 105

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

#colorize_magenta(str) ⇒ Object



101
102
103
# File 'lib/debug/color.rb', line 101

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

#irb_colorize(str, color) ⇒ Object



27
28
29
# File 'lib/debug/color.rb', line 27

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

#with_inspection_error_guardObject



109
110
111
112
113
114
115
116
117
118
119
120
121
# File 'lib/debug/color.rb', line 109

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