Class: Byebug::RegularState
Overview
Controls state of Byebug’s REPL when in normal mode
Instance Attribute Summary collapse
-
#context ⇒ Object
Returns the value of attribute context.
-
#display ⇒ Object
Returns the value of attribute display.
-
#file ⇒ Object
Returns the value of attribute file.
-
#frame ⇒ Object
Returns the value of attribute frame.
-
#interface ⇒ Object
writeonly
Sets the attribute interface.
-
#line ⇒ Object
Returns the value of attribute line.
-
#prev_line ⇒ Object
Returns the value of attribute prev_line.
Attributes inherited from State
Instance Method Summary collapse
-
#c_frame?(pos) ⇒ Boolean
Checks whether the frame in position
pos
is a c-frame or not. -
#frame_args(pos) ⇒ Object
Builds a string containing all available args in frame number
pos
, in a verbose or non verbose way according to the value of thecallstyle
setting. -
#frame_block_and_method(pos) ⇒ Object
Builds a formatted string containing information about block and method of the frame in position
pos
. -
#frame_call(pos) ⇒ Object
Builds a formatted string containing information about current method call in frame number
pos
. -
#frame_class(pos) ⇒ Object
Builds a string containing the class associated to frame number
pos
or an empty string if the currentcallstyle
setting is ‘short’. -
#frame_file(pos) ⇒ Object
Formatted filename in frame number
pos
. -
#frame_line(pos) ⇒ Object
Line number in frame number
pos
. -
#frame_mark(pos) ⇒ Object
Formatted mark for number of frame in position
pos
. -
#frame_pos(pos) ⇒ Object
Properly formatted frame number of frame in position
pos
. -
#initialize(context, display, file, interface, line) ⇒ RegularState
constructor
A new instance of RegularState.
-
#location ⇒ Object
Current (formatted) location.
-
#proceed ⇒ Object
Signals the REPL that the execution can proceed.
-
#proceed? ⇒ Boolean
Checks whether that execution can proceed.
Methods included from FileFunctions
#get_line, #get_lines, #n_lines, #normalize
Constructor Details
#initialize(context, display, file, interface, line) ⇒ RegularState
Returns a new instance of RegularState.
11 12 13 14 15 16 17 18 19 20 |
# 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 |
Instance Attribute Details
#context ⇒ Object
Returns the value of attribute context.
8 9 10 |
# File 'lib/byebug/states/regular_state.rb', line 8 def context @context end |
#display ⇒ Object
Returns the value of attribute display.
8 9 10 |
# File 'lib/byebug/states/regular_state.rb', line 8 def display @display end |
#file ⇒ Object
Returns the value of attribute file.
8 9 10 |
# File 'lib/byebug/states/regular_state.rb', line 8 def file @file end |
#frame ⇒ Object
Returns the value of attribute frame.
8 9 10 |
# File 'lib/byebug/states/regular_state.rb', line 8 def frame @frame end |
#interface=(value) ⇒ Object (writeonly)
Sets the attribute interface
9 10 11 |
# File 'lib/byebug/states/regular_state.rb', line 9 def interface=(value) @interface = value end |
#line ⇒ Object
Returns the value of attribute line.
8 9 10 |
# File 'lib/byebug/states/regular_state.rb', line 8 def line @line end |
#prev_line ⇒ Object
Returns the value of attribute prev_line.
8 9 10 |
# File 'lib/byebug/states/regular_state.rb', line 8 def prev_line @prev_line end |
Instance Method Details
#c_frame?(pos) ⇒ Boolean
Checks whether the frame in position pos
is a c-frame or not
165 166 167 |
# File 'lib/byebug/states/regular_state.rb', line 165 def c_frame?(pos) context.frame_binding(pos).nil? end |
#frame_args(pos) ⇒ Object
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
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
# 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) ⇒ Object
Builds a formatted string containing information about block and method of the frame in position pos
70 71 72 73 74 75 |
# 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) ⇒ Object
Builds a formatted string containing information about current method call in frame number pos
.
114 115 116 117 118 |
# 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) ⇒ Object
Builds a string containing the class associated to frame number pos
or an empty string if the current callstyle
setting is ‘short’
55 56 57 58 59 60 61 62 |
# 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) ⇒ Object
Formatted filename in frame number pos
125 126 127 128 |
# 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) ⇒ Object
Line number in frame number pos
135 136 137 |
# File 'lib/byebug/states/regular_state.rb', line 135 def frame_line(pos) context.frame_line(pos) end |
#frame_mark(pos) ⇒ Object
Formatted mark for number of frame in position pos
. The mark can contain the current frame symbo (–>), the c_frame symbol (ͱ–) or both
154 155 156 157 158 |
# 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) ⇒ Object
Properly formatted frame number of frame in position pos
144 145 146 |
# File 'lib/byebug/states/regular_state.rb', line 144 def frame_pos(pos) format('%-2d', pos) end |
#location ⇒ Object
Current (formatted) location
43 44 45 46 47 |
# 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 ⇒ Object
Signals the REPL that the execution can proceed
35 36 37 |
# File 'lib/byebug/states/regular_state.rb', line 35 def proceed @proceed = true end |
#proceed? ⇒ Boolean
Checks whether that execution can proceed
28 29 30 |
# File 'lib/byebug/states/regular_state.rb', line 28 def proceed? @proceed end |