File: breakpoints.rb

package info (click to toggle)
ruby-pry-byebug 3.9.0-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye
  • size: 324 kB
  • sloc: ruby: 1,171; makefile: 4
file content (82 lines) | stat: -rw-r--r-- 1,947 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# frozen_string_literal: true

require "byebug"

module PryByebug
  module Helpers
    #
    # Common helpers for breakpoint related commands
    #
    module Breakpoints
      #
      # Byebug's array of breakpoints.
      #
      def breakpoints
        Pry::Byebug::Breakpoints
      end

      #
      # Prints a message with bold font.
      #
      def bold_puts(msg)
        output.puts(bold(msg))
      end

      #
      # Print out full information about a breakpoint.
      #
      # Includes surrounding code at that point.
      #
      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.
      #
      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

      #
      # Prints a header for the breakpoint list.
      #
      def print_breakpoints_header
        header = "#{' ' * (max_width - 1)}# Enabled At "

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

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

        BREAKPOINTS
      end

      #
      # Max width of breakpoints id column
      #
      def max_width
        breakpoints.last ? breakpoints.last.id.to_s.length : 1
      end
    end
  end
end