class Byebug::RegularState - byebug-4.0.5 Documentation

# class Byebug::RegularState

Controls state of Byebug's REPL when in normal mode

### Attributes

context[RW]
display[RW]
file[RW]
frame[RW]
interface[W]
line[RW]
prev_line[RW]

### Public Class Methods

new(context, display, file, interface, line) click to toggle source
Calls superclass method Byebug::State.new

    # File lib/byebug/states/regular_state.rb, line 11
    def initialize(context, display, file, interface, line)
      super(interface)
      @context = context
      @display = display
      @file = file
      @frame = 0
      @line = line
      @prev_line = nil
      @proceed = false
    end

### Public Instance Methods

c_frame?(pos) click to toggle source

Checks whether the frame in position `pos` is a c-frame or not

@param pos [Integer] Frame position.

    # File lib/byebug/states/regular_state.rb, line 165
    def c_frame?(pos)
      context.frame_binding(pos).nil?
    end

frame_args(pos) click to toggle source

Builds a string containing all available args in frame number `pos`, in a verbose or non verbose way according to the value of the `callstyle` setting

@param pos [Integer] Frame position.

    # File lib/byebug/states/regular_state.rb, line 84
    def frame_args(pos)
      args = context.frame_args(pos)
      return '' if args.empty?

      locals = context.frame_locals(pos) unless Setting[:callstyle] == 'short'
      my_args = args.map do |arg|
        case arg[0]
        when :block then prefix, default = '&', 'block'
        when :rest then prefix, default = '*', 'args'
        else prefix, default = '', nil
        end

        kls = if Setting[:callstyle] == 'short' || arg[1].nil? || locals.empty?
                ''
              else
                "##{locals[arg[1]].class}"
              end

        "#{prefix}#{arg[1] || default}#{kls}"
      end

      "(#{my_args.join(', ')})"
    end

frame_block_and_method(pos) click to toggle source

Builds a formatted string containing information about block and method of the frame in position `pos`

@param pos [Integer] Frame position.

    # File lib/byebug/states/regular_state.rb, line 70
    def frame_block_and_method(pos)
      deco_regexp = /((?:block(?: \(\d+ levels\))?|rescue) in )?(.+)/
      deco_method = "#{context.frame_method(pos)}"
      block_and_method = deco_regexp.match(deco_method)[1..2]
      block_and_method.map { |x| x.nil? ? '' : x }
    end

frame_call(pos) click to toggle source

Builds a formatted string containing information about current method call in frame number `pos`.

@param pos [Integer] Frame position.

    # File lib/byebug/states/regular_state.rb, line 114
    def frame_call(pos)
      block, method = frame_block_and_method(pos)

      block + frame_class(pos) + method + frame_args(pos)
    end

frame_class(pos) click to toggle source

Builds a string containing the class associated to frame number `pos` or an empty string if the current `callstyle` setting is 'short'

@param pos [Integer] Frame position.

    # File lib/byebug/states/regular_state.rb, line 55
    def frame_class(pos)
      return '' if Setting[:callstyle] == 'short'

      klass = context.frame_class(pos)
      return '' if klass.to_s.empty?

      "#{klass}."
    end

frame_file(pos) click to toggle source

Formatted filename in frame number `pos`

@param pos [Integer] Frame position.

    # File lib/byebug/states/regular_state.rb, line 125
    def frame_file(pos)
      fullpath = context.frame_file(pos)
      Setting[:fullpath] ? fullpath : shortpath(fullpath)
    end

frame_line(pos) click to toggle source

Line number in frame number `pos`

@param pos [Integer] Frame position.

    # File lib/byebug/states/regular_state.rb, line 135
    def frame_line(pos)
      context.frame_line(pos)
    end

frame_mark(pos) click to toggle source

Formatted mark for number of frame in position `pos`. The mark can contain the current frame symbo (–>), the c_frame symbol (ͱ–) or both

@param pos [Integer] Frame position.

    # File lib/byebug/states/regular_state.rb, line 154
    def frame_mark(pos)
      mark = frame == pos ? '-->' : '   '

      c_frame?(pos) ? mark + ' ͱ--' : mark
    end

frame_pos(pos) click to toggle source

Properly formatted frame number of frame in position `pos`

@param pos [Integer] Frame position.

    # File lib/byebug/states/regular_state.rb, line 144
    def frame_pos(pos)
      format('%-2d', pos)
    end

location() click to toggle source

Current (formatted) location

    # File lib/byebug/states/regular_state.rb, line 43
    def location
      l = "#{normalize(file)} @ #{line}\n"
      l += "#{get_line(file, line)}\n" unless %w((irb) -e').include?(file)
      l
    end

proceed() click to toggle source

Signals the REPL that the execution can proceed

    # File lib/byebug/states/regular_state.rb, line 35
    def proceed
      @proceed = true
    end

proceed?() click to toggle source

Checks whether that execution can proceed

    # File lib/byebug/states/regular_state.rb, line 28
    def proceed?
      @proceed
    end

### Private Instance Methods

shortpath(fullpath) click to toggle source

    # File lib/byebug/states/regular_state.rb, line 171
    def shortpath(fullpath)
      components = Pathname(fullpath).each_filename.to_a
      return fullpath if components.size <= 2

      File.join('...', components[-3..-1])
    end