Sha256: 1b8a7c7bd89c479ccb645027a7d5f9a8ea9865332058c8170de39a0d0b4ad3de

Contents?: true

Size: 1.93 KB

Versions: 3

Compression:

Stored size: 1.93 KB

Contents

# 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(text.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
                      "#{text.bold('Condition:')} #{breakpoint.expr}\n"
                    else
                      ""
                    end

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

          #{text.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}/, "")

          #{text.bold(header)}
          #{text.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

Version data entries

3 entries across 3 versions & 3 rubygems

Version Path
argon-1.3.1 vendor/bundle/ruby/2.7.0/gems/pry-byebug-3.8.0/lib/pry-byebug/helpers/breakpoints.rb
symbolic_enum-1.1.5 vendor/bundle/ruby/2.7.0/gems/pry-byebug-3.8.0/lib/pry-byebug/helpers/breakpoints.rb
pry-byebug-3.8.0 lib/pry-byebug/helpers/breakpoints.rb