Module: PryByebug::Helpers::Breakpoints

Included in:
BreakCommand, ContinueCommand
Defined in:
lib/pry-byebug/helpers/breakpoints.rb

Overview

Common helpers for breakpoint related commands

Instance Method Summary collapse

Instance Method Details

#bold_puts(msg) ⇒ Object

Prints a message with bold font.



21
22
23
# File 'lib/pry-byebug/helpers/breakpoints.rb', line 21

def bold_puts(msg)
  output.puts(bold(msg))
end

#breakpointsObject

Byebug’s array of breakpoints.



14
15
16
# File 'lib/pry-byebug/helpers/breakpoints.rb', line 14

def breakpoints
  Pry::Byebug::Breakpoints
end

#max_widthObject

Max width of breakpoints id column



77
78
79
# File 'lib/pry-byebug/helpers/breakpoints.rb', line 77

def max_width
  breakpoints.last ? breakpoints.last.id.to_s.length : 1
end

Prints a header for the breakpoint list.



63
64
65
66
67
68
69
70
71
72
# File 'lib/pry-byebug/helpers/breakpoints.rb', line 63

def print_breakpoints_header
  header = "#{' ' * (max_width - 1)}# Enabled At "

  output.puts <<-BREAKPOINTS.gsub(/ {8}/, "")

    #{bold(header)}
    #{bold('-' * header.size)}

  BREAKPOINTS
end

Print out full information about a breakpoint.

Includes surrounding code at that point.



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/pry-byebug/helpers/breakpoints.rb', line 30

def print_full_breakpoint(breakpoint)
  header = "Breakpoint #{breakpoint.id}:"
  status = breakpoint.enabled? ? "Enabled" : "Disabled"
  code = breakpoint.source_code.with_line_numbers.to_s
  condition = if breakpoint.expr
                "#{bold('Condition:')} #{breakpoint.expr}\n"
              else
                ""
              end

  output.puts <<-BREAKPOINT.gsub(/ {8}/, "")

    #{bold(header)} #{breakpoint} (#{status}) #{condition}

    #{code}

  BREAKPOINT
end

Print out concise information about a breakpoint.



52
53
54
55
56
57
58
# File 'lib/pry-byebug/helpers/breakpoints.rb', line 52

def print_short_breakpoint(breakpoint)
  id = format("%*d", max_width, breakpoint.id)
  status = breakpoint.enabled? ? "Yes" : "No "
  expr = breakpoint.expr ? " #{breakpoint.expr} " : ""

  output.puts("  #{id} #{status}     #{breakpoint}#{expr}")
end